Added GetArtists.json as the backend for the ajax enabled main page

This commit is contained in:
Patrick Speiser
2012-09-28 20:05:24 +02:00
parent 4373a94e07
commit e3145974f6

View File

@@ -29,6 +29,7 @@ from headphones import logger, searcher, db, importer, mb, lastfm, librarysync
from headphones.helpers import checked, radio
import lib.simplejson as simplejson
import json
@@ -438,6 +439,51 @@ class WebInterface(object):
return s
getLog.exposed = True
def getArtists_json(self,iDisplayStart=0,iDisplayLength=100,sSearch="",iSortCol_0='0',sSortDir_0='asc'):
iDisplayStart = int(iDisplayStart)
iDisplayLength = int(iDisplayLength)
filtered = []
totalcount = 0
myDB = db.DBConnection()
if sSearch == "":
filtered = myDB.select('SELECT * from artists order by ArtistSortName COLLATE NOCASE')
totalcount = len(filtered)
else:
filtered = myDB.select('SELECT * from artists order by ArtistSortName WHERE ArtistSortName LIKE %s OR LatestAlbum LIKE %s COLLATE NOCASE' % (sSearch,sSearch))
totalcount = myDB.select('SELECT COUNT(*) from artists')
sortcolumn = 0
if iSortCol_0 == '1':
sortcolumn = 2
elif iSortCol_0 == '2':
sortcolumn = 1
filtered.sort(key=lambda x:x[sortcolumn],reverse=sSortDir_0 == "desc")
artists = filtered[iDisplayStart:(iDisplayStart+iDisplayLength)]
rows = []
for artist in artists:
row = {"ArtistID":artist['ArtistID'],
"ArtistSortName":artist["ArtistSortName"],
"Status":artist["Status"],
"TotalTracks":artist["TotalTracks"],
"HaveTracks":artist["HaveTracks"] if 'HaveTracks' in artist else 0,
"LatestAlbum":"",
"ReleaseDate":"",
}
rows.append(row)
dict = {'iTotalDisplayRecords':len(filtered),
'iTotalRecords':totalcount,
'aaData':rows,
}
s = json.dumps(dict)
cherrypy.response.headers['Content-type'] = 'application/json'
return s
getArtists_json.exposed=True
def clearhistory(self, type=None):
myDB = db.DBConnection()
if type == 'all':