From 4cc00d54b35fcf73c2637cedae5c4f6e7d39fc22 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sat, 20 Oct 2012 15:34:23 -0300 Subject: [PATCH] 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)