1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Implemented artist name editing

This commit is contained in:
krateng 2022-04-15 18:48:03 +02:00
parent c33fcf1dc1
commit 371e73ac99
6 changed files with 51 additions and 4 deletions

View File

@ -515,4 +515,13 @@ def get_export(**keys):
@authenticated_function(api=True)
def delete_scrobble(timestamp):
"""Internal Use Only"""
database.remove_scrobble(timestamp)
return database.remove_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
"""Internal Use Only"""
return database.change_artist_name(oldname,newname)

View File

@ -137,6 +137,13 @@ def remove_scrobble(timestamp):
result = sqldb.delete_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)
dbcache.invalidate_entity_cache()
dbcache.invalidate_caches()

View File

@ -94,12 +94,12 @@ def cached_wrapper_individual(inner_func):
return outer_func
def invalidate_caches(scrobbletime):
def invalidate_caches(scrobbletime=None):
if malojaconfig['USE_GLOBAL_CACHE']:
cleared, kept = 0, 0
for k in cache.keys():
# VERY BIG TODO: differentiate between None as in 'unlimited timerange' and None as in 'time doesnt matter here'!
if (k[3] is None or scrobbletime >= k[3]) and (k[4] is None or scrobbletime <= k[4]):
if scrobbletime is None or (k[3] is None or scrobbletime >= k[3]) and (k[4] is None or scrobbletime <= k[4]):
cleared += 1
del cache[k]
else:

View File

@ -353,6 +353,19 @@ def get_artist_id(artistname,create_new=True,dbconn=None):
return result.inserted_primary_key[0]
### Edit existing
@connection_provider
def edit_artist(id,artistdict,dbconn=None):
dbentry = artist_dict_to_db(artistdict)
op = DB['artists'].update().where(
DB['artists'].c.id==id
).values(
**dbentry
)
result = dbconn.execute(op)

View File

@ -29,7 +29,9 @@
{% block content %}
<script>
const original_entity = "{{ artist }}"
</script>
@ -73,6 +75,7 @@
</tr>
</table>
<h2><a href='{{ mlj_uri.create_uri("/charts_tracks",filterkeys) }}'>Top Tracks</a></h2>

View File

@ -41,6 +41,12 @@ function editEntity() {
})
// manually clicking away
namefield.addEventListener('blur',function(e){
doneEditing();
})
namefield.focus();
selectAll(namefield);
}
@ -48,4 +54,13 @@ function editEntity() {
function doneEditing() {
var namefield = document.getElementById('main_entity_name');
namefield.contentEditable = "false";
newname = document.getElementById('main_entity_name').innerHTML;
neo.xhttpreq(
"/apis/mlj_1/edit_artist",
data={'oldname':original_entity,'newname':newname},
method="POST",
callback=(()=>window.location = "?artist=" + newname),
json=true
);
}