mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04:00
Implemented artist name editing
This commit is contained in:
parent
c33fcf1dc1
commit
371e73ac99
@ -515,4 +515,13 @@ def get_export(**keys):
|
|||||||
@authenticated_function(api=True)
|
@authenticated_function(api=True)
|
||||||
def delete_scrobble(timestamp):
|
def delete_scrobble(timestamp):
|
||||||
"""Internal Use Only"""
|
"""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)
|
||||||
|
@ -137,6 +137,13 @@ def remove_scrobble(timestamp):
|
|||||||
result = sqldb.delete_scrobble(timestamp)
|
result = sqldb.delete_scrobble(timestamp)
|
||||||
dbcache.invalidate_caches(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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,12 +94,12 @@ def cached_wrapper_individual(inner_func):
|
|||||||
|
|
||||||
return outer_func
|
return outer_func
|
||||||
|
|
||||||
def invalidate_caches(scrobbletime):
|
def invalidate_caches(scrobbletime=None):
|
||||||
if malojaconfig['USE_GLOBAL_CACHE']:
|
if malojaconfig['USE_GLOBAL_CACHE']:
|
||||||
cleared, kept = 0, 0
|
cleared, kept = 0, 0
|
||||||
for k in cache.keys():
|
for k in cache.keys():
|
||||||
# VERY BIG TODO: differentiate between None as in 'unlimited timerange' and None as in 'time doesnt matter here'!
|
# 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
|
cleared += 1
|
||||||
del cache[k]
|
del cache[k]
|
||||||
else:
|
else:
|
||||||
|
@ -353,6 +353,19 @@ def get_artist_id(artistname,create_new=True,dbconn=None):
|
|||||||
return result.inserted_primary_key[0]
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const original_entity = "{{ artist }}"
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -73,6 +75,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
<h2><a href='{{ mlj_uri.create_uri("/charts_tracks",filterkeys) }}'>Top Tracks</a></h2>
|
<h2><a href='{{ mlj_uri.create_uri("/charts_tracks",filterkeys) }}'>Top Tracks</a></h2>
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,6 +41,12 @@ function editEntity() {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// manually clicking away
|
||||||
|
namefield.addEventListener('blur',function(e){
|
||||||
|
doneEditing();
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
namefield.focus();
|
namefield.focus();
|
||||||
selectAll(namefield);
|
selectAll(namefield);
|
||||||
}
|
}
|
||||||
@ -48,4 +54,13 @@ function editEntity() {
|
|||||||
function doneEditing() {
|
function doneEditing() {
|
||||||
var namefield = document.getElementById('main_entity_name');
|
var namefield = document.getElementById('main_entity_name');
|
||||||
namefield.contentEditable = "false";
|
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user