From 4cc00d54b35fcf73c2637cedae5c4f6e7d39fc22 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sat, 20 Oct 2012 15:34:23 -0300 Subject: [PATCH 1/2] First changes to fix the 'delete empty artists function to delete artists with no albums in db --- headphones/webserve.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/headphones/webserve.py b/headphones/webserve.py index 0f1e65c3..0edefa4a 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -188,24 +188,32 @@ class WebInterface(object): myDB.action('DELETE from artists WHERE ArtistID=?', [ArtistID]) myDB.action('DELETE from albums WHERE ArtistID=?', [ArtistID]) myDB.action('DELETE from tracks WHERE ArtistID=?', [ArtistID]) + myDB.action('DELETE from allalbums WHERE ArtistID=?', [ArtistID]) + myDB.action('DELETE from alltracks WHERE ArtistID=?', [ArtistID]) myDB.action('INSERT OR REPLACE into blacklist VALUES (?)', [ArtistID]) raise cherrypy.HTTPRedirect("home") deleteArtist.exposed = True - + def returnEmptyArtists(self): + mydb = db.DBConnection() + emptyArtistNames = [row['ArtistID'] for row in myDB.select("SELECT ArtistName FROM artists WHERE LatestAlbum == None")] + return EmptyArtistNames + returnEmptyArtists.exposed = True + def deleteEmptyArtists(self): logger.info(u"Deleting all empty artists") myDB = db.DBConnection() - emptyArtistIDs = [row['ArtistID'] for row in myDB.select("SELECT ArtistID FROM artists WHERE HaveTracks == 0")] + emptyArtistIDs = [row['ArtistID'] for row in myDB.select("SELECT ArtistID FROM artists WHERE LatestAlbum == None")] for ArtistID in emptyArtistIDs: logger.info(u"Deleting all traces of artist: " + ArtistID) myDB.action('DELETE from artists WHERE ArtistID=?', [ArtistID]) myDB.action('DELETE from albums WHERE ArtistID=?', [ArtistID]) myDB.action('DELETE from tracks WHERE ArtistID=?', [ArtistID]) + myDB.action('DELETE from allalbums WHERE ArtistID=?', [ArtistID]) + myDB.action('DELETE from alltracks WHERE ArtistID=?', [ArtistID]) myDB.action('INSERT OR REPLACE into blacklist VALUES (?)', [ArtistID]) deleteEmptyArtists.exposed = True - - + def refreshArtist(self, ArtistID): threading.Thread(target=importer.addArtisttoDB, args=[ArtistID]).start() raise cherrypy.HTTPRedirect("artistPage?ArtistID=%s" % ArtistID) From 47291c52288eb9eab4dfad5692aedd6507e2fe37 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sat, 20 Oct 2012 16:13:10 -0300 Subject: [PATCH 2/2] Moved empty artist database query to the main manage page, added a dialog to the ui --- data/interfaces/default/manage.html | 20 ++++++++++++++++++-- headphones/webserve.py | 12 ++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/data/interfaces/default/manage.html b/data/interfaces/default/manage.html index db682780..7a7fb14a 100644 --- a/data/interfaces/default/manage.html +++ b/data/interfaces/default/manage.html @@ -34,7 +34,7 @@
@@ -117,7 +117,19 @@ Force Update Active Artists Force Post-Process Albums in Download Folder Check for Headphones Updates - Delete empty Artists + Delete empty Artists +
@@ -131,6 +143,10 @@ $('#dialog').dialog(); return false; }); + $('#delete_empty_artists').click(function() { + $('#emptyartistdialog').dialog(); + return false; + }); jQuery( "#tabs" ).tabs(); initActions(); }; diff --git a/headphones/webserve.py b/headphones/webserve.py index 0edefa4a..01eb83f0 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -194,16 +194,10 @@ class WebInterface(object): raise cherrypy.HTTPRedirect("home") deleteArtist.exposed = True - def returnEmptyArtists(self): - mydb = db.DBConnection() - emptyArtistNames = [row['ArtistID'] for row in myDB.select("SELECT ArtistName FROM artists WHERE LatestAlbum == None")] - return EmptyArtistNames - returnEmptyArtists.exposed = True - def deleteEmptyArtists(self): logger.info(u"Deleting all empty artists") myDB = db.DBConnection() - emptyArtistIDs = [row['ArtistID'] for row in myDB.select("SELECT ArtistID FROM artists WHERE LatestAlbum == None")] + emptyArtistIDs = [row['ArtistID'] for row in myDB.select("SELECT ArtistID FROM artists WHERE LatestAlbum IS NULL")] for ArtistID in emptyArtistIDs: logger.info(u"Deleting all traces of artist: " + ArtistID) myDB.action('DELETE from artists WHERE ArtistID=?', [ArtistID]) @@ -301,7 +295,9 @@ class WebInterface(object): upcoming.exposed = True def manage(self): - return serve_template(templatename="manage.html", title="Manage") + myDB = db.DBConnection() + emptyArtists = myDB.select("SELECT * FROM artists WHERE LatestAlbum IS NULL") + return serve_template(templatename="manage.html", title="Manage", emptyArtists=emptyArtists) manage.exposed = True def manageArtists(self):