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

This commit is contained in:
rembo10
2012-08-19 15:37:09 +05:30
parent ecb5395c22
commit af2b0515ee
5 changed files with 69 additions and 6 deletions

View File

@@ -170,7 +170,7 @@
function initThisPage() {
$('#album_chooser').click(function() {
$('#dialog').dialog();
$('#dialog').dialog({ width: "500px" });
return false;
});
$('#refresh_artist').click(function() {

View File

@@ -2,6 +2,7 @@
<%!
from headphones import db
import headphones
import string
%>
<%def name="headerIncludes()">
@@ -16,9 +17,21 @@
%endif
%if artist['IncludeExtras']:
<a id="menu_link_removeextra" href="#" onclick="doAjaxCall('removeExtras?ArtistID=${artist['ArtistID']}',$(this),true)" data-success="Extras removed for ${artist['ArtistName']}">Remove Extras</a>
<a class="menu_link_edit" id="menu_link_modifyextra" href="#">Modify Extras</a>
%else:
<a id="menu_link_getextra" href="#" onclick="doAjaxCall('getExtras?ArtistID=${artist['ArtistID']}',$(this),true)" data-success="Getting Extras for ${artist['ArtistName']}">Get Extras</a>
<a id="menu_link_getextra" href="#">Get Extras</a>
%endif
<div id="dialog" title="Choose Which Extras to Fetch" style="display:none" class="configtable">
<form action="getExtras" method="get" class="form">
<input type="hidden" name="ArtistID" value="${artist['ArtistID']}">
<input type="hidden" name="newstyle" value="true">
%for extra in extras:
<input type="checkbox" id="${extra}" name="${extra}" value="1" ${extras[extra]} />${string.capwords(extra)}<br>
%endfor
<br>
<input id="submit" type="submit" value="Fetch Extras">
</form>
</div>
</div>
</div>
<a href="home" class="back">&laquo; Back to overview</a>
@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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)