mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Implemented track title editing and refactored edit system
This commit is contained in:
parent
371e73ac99
commit
bccd88acd4
@ -520,8 +520,12 @@ def delete_scrobble(timestamp):
|
||||
|
||||
@api.post("edit_artist")
|
||||
@authenticated_function(api=True)
|
||||
def edit_artist(oldname,newname):
|
||||
# we probably wanna pass the id to the web interface at some point
|
||||
# but for now we just use the old name as identifer as it's always unique
|
||||
def edit_artist(id,name):
|
||||
"""Internal Use Only"""
|
||||
return database.change_artist_name(oldname,newname)
|
||||
return database.edit_artist(id,name)
|
||||
|
||||
@api.post("edit_track")
|
||||
@authenticated_function(api=True)
|
||||
def edit_track(id,title):
|
||||
"""Internal Use Only"""
|
||||
return database.edit_track(id,{'title':title})
|
||||
|
@ -138,13 +138,20 @@ def remove_scrobble(timestamp):
|
||||
dbcache.invalidate_caches(timestamp)
|
||||
|
||||
@waitfordb
|
||||
def change_artist_name(oldname,newname):
|
||||
log(f"Renaming {oldname} to {newname}")
|
||||
id = sqldb.get_artist_id(oldname)
|
||||
sqldb.edit_artist(id,newname)
|
||||
def edit_artist(id,artistinfo):
|
||||
artist = sqldb.get_artist(id)
|
||||
log(f"Renaming {artist} to {artistinfo}")
|
||||
sqldb.edit_artist(id,artistinfo)
|
||||
dbcache.invalidate_entity_cache()
|
||||
dbcache.invalidate_caches()
|
||||
|
||||
@waitfordb
|
||||
def edit_track(id,trackinfo):
|
||||
track = sqldb.get_track(id)
|
||||
log(f"Renaming {track['title']} to {trackinfo['title']}")
|
||||
sqldb.edit_track(id,trackinfo)
|
||||
dbcache.invalidate_entity_cache()
|
||||
dbcache.invalidate_caches()
|
||||
|
||||
|
||||
|
||||
@ -280,7 +287,8 @@ def artist_info(dbconn=None,**keys):
|
||||
|
||||
artist = keys.get('artist')
|
||||
|
||||
artist = sqldb.get_artist(sqldb.get_artist_id(artist,dbconn=dbconn),dbconn=dbconn)
|
||||
artist_id = sqldb.get_artist_id(artist,dbconn=dbconn)
|
||||
artist = sqldb.get_artist(artist_id,dbconn=dbconn)
|
||||
alltimecharts = get_charts_artists(timerange=alltime(),dbconn=dbconn)
|
||||
scrobbles = get_scrobbles_num(artist=artist,timerange=alltime(),dbconn=dbconn)
|
||||
#we cant take the scrobble number from the charts because that includes all countas scrobbles
|
||||
@ -298,7 +306,8 @@ def artist_info(dbconn=None,**keys):
|
||||
"silver": [year for year in cached.medals_artists if artist in cached.medals_artists[year]['silver']],
|
||||
"bronze": [year for year in cached.medals_artists if artist in cached.medals_artists[year]['bronze']],
|
||||
},
|
||||
"topweeks":len([e for e in cached.weekly_topartists if e == artist])
|
||||
"topweeks":len([e for e in cached.weekly_topartists if e == artist]),
|
||||
"id":artist_id
|
||||
}
|
||||
except:
|
||||
# if the artist isnt in the charts, they are not being credited and we
|
||||
@ -316,7 +325,8 @@ def track_info(dbconn=None,**keys):
|
||||
|
||||
track = keys.get('track')
|
||||
|
||||
track = sqldb.get_track(sqldb.get_track_id(track,dbconn=dbconn),dbconn=dbconn)
|
||||
track_id = sqldb.get_track_id(track,dbconn=dbconn)
|
||||
track = sqldb.get_track(track_id,dbconn=dbconn)
|
||||
alltimecharts = get_charts_tracks(timerange=alltime(),dbconn=dbconn)
|
||||
#scrobbles = get_scrobbles_num(track=track,timerange=alltime())
|
||||
|
||||
@ -340,7 +350,8 @@ def track_info(dbconn=None,**keys):
|
||||
"bronze": [year for year in cached.medals_tracks if track in cached.medals_tracks[year]['bronze']],
|
||||
},
|
||||
"certification":cert,
|
||||
"topweeks":len([e for e in cached.weekly_toptracks if e == track])
|
||||
"topweeks":len([e for e in cached.weekly_toptracks if e == track]),
|
||||
"id":track_id
|
||||
}
|
||||
|
||||
|
||||
|
@ -366,6 +366,16 @@ def edit_artist(id,artistdict,dbconn=None):
|
||||
)
|
||||
result = dbconn.execute(op)
|
||||
|
||||
@connection_provider
|
||||
def edit_track(id,trackdict,dbconn=None):
|
||||
dbentry = track_dict_to_db(trackdict)
|
||||
|
||||
op = DB['tracks'].update().where(
|
||||
DB['tracks'].c.id==id
|
||||
).values(
|
||||
**dbentry
|
||||
)
|
||||
result = dbconn.execute(op)
|
||||
|
||||
|
||||
|
||||
|
@ -30,7 +30,8 @@
|
||||
{% block content %}
|
||||
|
||||
<script>
|
||||
const original_entity = "{{ artist }}"
|
||||
const entity_id = {{ info.id }};
|
||||
const entity_type = 'artist';
|
||||
</script>
|
||||
|
||||
|
||||
|
@ -23,6 +23,11 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<script>
|
||||
const entity_id = {{ info.id }};
|
||||
const entity_type = 'track';
|
||||
</script>
|
||||
|
||||
|
||||
{% import 'partials/awards_track.jinja' as awards %}
|
||||
|
||||
@ -43,6 +48,7 @@
|
||||
<td class="text">
|
||||
<span>{{ links.links(track.artists) }}</span><br/>
|
||||
<h1 id="main_entity_name" class="headerwithextra">{{ info.track.title }}</h1>
|
||||
{% if adminmode %}{% include 'icons/edit.jinja' %}{% endif %}
|
||||
{{ awards.certs(track) }}
|
||||
<span class="rank"><a href="/charts_tracks?max=100">#{{ info.position }}</a></span>
|
||||
<br/>
|
||||
|
@ -55,12 +55,24 @@ function doneEditing() {
|
||||
var namefield = document.getElementById('main_entity_name');
|
||||
namefield.contentEditable = "false";
|
||||
newname = document.getElementById('main_entity_name').innerHTML;
|
||||
var searchParams = new URLSearchParams(window.location.search);
|
||||
|
||||
if (entity_type == 'artist') {
|
||||
var endpoint = "/apis/mlj_1/edit_artist";
|
||||
searchParams.set("artist", newname);
|
||||
var payload = {'id':entity_id,'name':newname};
|
||||
}
|
||||
else if (entity_type == 'track') {
|
||||
var endpoint = "/apis/mlj_1/edit_track";
|
||||
searchParams.set("title", newname);
|
||||
var payload = {'id':entity_id,'title':newname}
|
||||
}
|
||||
|
||||
neo.xhttpreq(
|
||||
"/apis/mlj_1/edit_artist",
|
||||
data={'oldname':original_entity,'newname':newname},
|
||||
endpoint,
|
||||
data=payload,
|
||||
method="POST",
|
||||
callback=(()=>window.location = "?artist=" + newname),
|
||||
callback=(()=>window.location = "?" + searchParams.toString()),
|
||||
json=true
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user