From af2b0515eeccaac313d1cc2a4601ff551c47dace Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sun, 19 Aug 2012 15:37:09 +0530 Subject: [PATCH] Added selective extras fetching to the artist page - had to make some backend changes to get this working: changed DB.select to DB.action in mb.py, added newstyle variable to getExtras --- data/interfaces/default/album.html | 2 +- data/interfaces/default/artist.html | 23 ++++++++++++++- data/interfaces/default/css/style.css | 7 +++++ headphones/mb.py | 2 +- headphones/webserve.py | 41 +++++++++++++++++++++++++-- 5 files changed, 69 insertions(+), 6 deletions(-) diff --git a/data/interfaces/default/album.html b/data/interfaces/default/album.html index 6af0459d..c3609d07 100644 --- a/data/interfaces/default/album.html +++ b/data/interfaces/default/album.html @@ -170,7 +170,7 @@ function initThisPage() { $('#album_chooser').click(function() { - $('#dialog').dialog(); + $('#dialog').dialog({ width: "500px" }); return false; }); $('#refresh_artist').click(function() { diff --git a/data/interfaces/default/artist.html b/data/interfaces/default/artist.html index b0d8af05..49acbef7 100644 --- a/data/interfaces/default/artist.html +++ b/data/interfaces/default/artist.html @@ -2,6 +2,7 @@ <%! from headphones import db import headphones + import string %> <%def name="headerIncludes()"> @@ -16,9 +17,21 @@ %endif %if artist['IncludeExtras']: Remove Extras + Modify Extras %else: - Get Extras + Get Extras %endif + « Back to overview @@ -178,6 +191,14 @@ function initThisPage() { + $('#menu_link_getextra').click(function() { + $('#dialog').dialog(); + return false; + }); + $('#menu_link_modifyextra').click(function() { + $('#dialog').dialog(); + }); + %if artist['Status'] == 'Loading': showMsg("Getting artist information",true); %endif diff --git a/data/interfaces/default/css/style.css b/data/interfaces/default/css/style.css index 54a2bc7c..771d4db3 100644 --- a/data/interfaces/default/css/style.css +++ b/data/interfaces/default/css/style.css @@ -674,6 +674,13 @@ footer { position: relative; margin-right: 3px; } +#dialog { + padding: 40px; +} +#dialog input#submit { + margin-left: 50px; + margin-right: auto; +} #subhead .back { float: left; margin-top: -25px; diff --git a/headphones/mb.py b/headphones/mb.py index f81b7057..29b5bb8a 100644 --- a/headphones/mb.py +++ b/headphones/mb.py @@ -234,7 +234,7 @@ def getArtist(artistid, extrasonly=False): myDB = db.DBConnection() try: - db_artist = myDB.select('SELECT IncludeExtras, Extras from artists WHERE ArtistID=?', [artistid]).fetchone() + db_artist = myDB.action('SELECT IncludeExtras, Extras from artists WHERE ArtistID=?', [artistid]).fetchone() includeExtras = db_artist['IncludeExtras'] except IndexError: includeExtras = False diff --git a/headphones/webserve.py b/headphones/webserve.py index e69ab664..ca4a70a9 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -61,9 +61,27 @@ class WebInterface(object): myDB = db.DBConnection() artist = myDB.action('SELECT * FROM artists WHERE ArtistID=?', [ArtistID]).fetchone() albums = myDB.select('SELECT * from albums WHERE ArtistID=? order by ReleaseDate DESC', [ArtistID]) + + # Serve the extras up as a dict to make things easier for new templates + extras_list = ["single", "ep", "compilation", "soundtrack", "live", "remix", "spokenword", "audiobook"] + extras_dict = {} + + if not artist['Extras']: + artist_extras = "" + else: + artist_extras = artist['Extras'] + + i = 1 + for extra in extras_list: + if str(i) in artist_extras: + extras_dict[extra] = "checked" + else: + extras_dict[extra] = "" + i+=1 + if artist is None: raise cherrypy.HTTPRedirect("home") - return serve_template(templatename="artist.html", title=artist['ArtistName'], artist=artist, albums=albums) + return serve_template(templatename="artist.html", title=artist['ArtistName'], artist=artist, albums=albums, extras=extras_dict) artistPage.exposed = True @@ -93,10 +111,27 @@ class WebInterface(object): raise cherrypy.HTTPRedirect("artistPage?ArtistID=%s" % artistid) addArtist.exposed = True - def getExtras(self, ArtistID): + def getExtras(self, ArtistID, newstyle=False, **kwargs): + # if calling this function without the newstyle, they're using the old format + # which doesn't separate extras, so we'll grab all of them + # + # If they are, we need to convert kwargs to string format + if not newstyle: + extras = "1,2,3,4,5,6,7,8" + else: + temp_extras_list = [] + # TODO: Put these extras as a global variable + i = 1 + for extra in ["single", "ep", "compilation", "soundtrack", "live", "remix", "spokenword", "audiobook"]: + if extra in kwargs: + temp_extras_list.append(i) + i += 1 + extras = ','.join(str(n) for n in temp_extras_list) + myDB = db.DBConnection() controlValueDict = {'ArtistID': ArtistID} - newValueDict = {'IncludeExtras': 1} + newValueDict = {'IncludeExtras': 1, + 'Extras': extras} myDB.upsert("artists", newValueDict, controlValueDict) threading.Thread(target=importer.addArtisttoDB, args=[ArtistID, True]).start() raise cherrypy.HTTPRedirect("artistPage?ArtistID=%s" % ArtistID)