From e3145974f6eee87018d49b53656c903a870548b1 Mon Sep 17 00:00:00 2001 From: Patrick Speiser Date: Fri, 28 Sep 2012 20:05:24 +0200 Subject: [PATCH 1/8] Added GetArtists.json as the backend for the ajax enabled main page --- headphones/webserve.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/headphones/webserve.py b/headphones/webserve.py index 87a59336..803bbe5f 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -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': From 203e7ca3a127270873931b623b0ba2bac955d1f0 Mon Sep 17 00:00:00 2001 From: Patrick Speiser Date: Fri, 28 Sep 2012 21:28:35 +0200 Subject: [PATCH 2/8] More groundwork for home page ajax --- .gitignore | 32 + data/interfaces/default/index.html | 96 ++- data/js/libs/jquery.dataTables.min.js | 801 +++++--------------------- data/js/libs/jquery.js | 2 + headphones/webserve.py | 11 +- 5 files changed, 233 insertions(+), 709 deletions(-) create mode 100644 data/js/libs/jquery.js diff --git a/.gitignore b/.gitignore index 74e29c78..b557314a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ + # Compiled source # ################### *.pyc *.py~ +*.pyproj +*.sln # Logs and databases # ###################### @@ -19,3 +22,32 @@ cache/* ehthumbs.db Icon? Thumbs.db + +#ignore thumbnails created by windows +Thumbs.db +#Ignore files build by Visual Studio +*.obj +*.exe +*.pdb +*.user +*.aps +*.pch +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +[Bb]in +[Dd]ebug*/ +*.lib +*.sbr +obj/ +[Rr]elease*/ +_ReSharper*/ +[Tt]est[Rr]esult* \ No newline at end of file diff --git a/data/interfaces/default/index.html b/data/interfaces/default/index.html index bcd8cf2b..f33920e0 100644 --- a/data/interfaces/default/index.html +++ b/data/interfaces/default/index.html @@ -8,58 +8,13 @@ - Artist Name - Status - Latest Album - Have + Artist Name + Status + Latest Album + Have - %for artist in artists: - <% - totaltracks = artist['TotalTracks'] - havetracks = artist['HaveTracks'] - if not havetracks: - havetracks = 0 - try: - percent = (havetracks*100.0)/totaltracks - if percent > 100: - percent = 100 - except (ZeroDivisionError, TypeError): - percent = 0 - totaltracks = '?' - - if artist['ReleaseDate'] and artist['LatestAlbum']: - releasedate = artist['ReleaseDate'] - albumdisplay = '%s (%s)' % (artist['LatestAlbum'], artist['ReleaseDate']) - if releasedate > helpers.today(): - grade = 'A' - else: - grade = 'Z' - elif artist['LatestAlbum']: - releasedate = '' - grade = 'Z' - albumdisplay = '%s' % artist['LatestAlbum'] - else: - releasedate = '' - grade = 'Z' - albumdisplay = 'None' - - if artist['Status'] == 'Paused': - grade = 'X' - - if artist['Status'] == 'Loading': - grade = 'L' - - %> - -
- ${artist['ArtistName']} - ${artist['Status']} - ${albumdisplay} -
${havetracks}/${totaltracks}
- - %endfor @@ -72,7 +27,9 @@