diff --git a/htmlmodules.py b/htmlmodules.py index 2617513..b5cbc03 100644 --- a/htmlmodules.py +++ b/htmlmodules.py @@ -18,12 +18,14 @@ import math # result.append(element.get("image")) -# artist=None,track=None,since=None,to=None,within=None,associated=False,max_=None,pictures=False -def module_scrobblelist(page=0,perpage=100,pictures=False,shortTimeDesc=False,earlystop=False,**kwargs): +#max_ indicates that no pagination should occur (because this is not the primary module) +def module_scrobblelist(page=0,perpage=100,max_=None,pictures=False,shortTimeDesc=False,earlystop=False,**kwargs): kwargs_filter = pickKeys(kwargs,"artist","track","associated") kwargs_time = pickKeys(kwargs,"timerange","since","to","within") + if max_ is not None: perpage,page=max_,0 + firstindex = page * perpage lastindex = firstindex + perpage @@ -37,6 +39,8 @@ def module_scrobblelist(page=0,perpage=100,pictures=False,shortTimeDesc=False,ea #scrobbleimages = ["/image?title=" + urllib.parse.quote(t["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in t["artists"]]) for t in scrobbleswithpictures] scrobbleimages = [getTrackImage(t["artists"],t["title"],fast=True) for t in scrobbleswithpictures] + pages = math.ceil(len(scrobbles) / perpage) + representative = scrobbles[0] if len(scrobbles) is not 0 else None # build list @@ -62,22 +66,27 @@ def module_scrobblelist(page=0,perpage=100,pictures=False,shortTimeDesc=False,ea html += "" + if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs) + return (html,len(scrobbles),representative) -def module_pulse(page=0,perpage=100,**kwargs): +def module_pulse(page=0,perpage=100,max_=None,**kwargs): from doreah.timing import clock, clockp kwargs_filter = pickKeys(kwargs,"artist","track","associated") kwargs_time = pickKeys(kwargs,"since","to","within","timerange","step","stepn","trail") + if max_ is not None: perpage,page=max_,0 + firstindex = page * perpage lastindex = firstindex + perpage ranges = database.get_pulse(**kwargs_time,**kwargs_filter) + pages = math.ceil(len(ranges) / perpage) ranges = ranges[firstindex:lastindex] @@ -100,21 +109,26 @@ def module_pulse(page=0,perpage=100,**kwargs): html += "" html += "" + if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs) return html -def module_performance(page=0,perpage=100,**kwargs): +def module_performance(page=0,perpage=100,max_=None,**kwargs): kwargs_filter = pickKeys(kwargs,"artist","track") kwargs_time = pickKeys(kwargs,"since","to","within","timerange","step","stepn","trail") + if max_ is not None: perpage,page=max_,0 + firstindex = page * perpage lastindex = firstindex + perpage ranges = database.get_performance(**kwargs_time,**kwargs_filter) + pages = math.ceil(len(ranges) / perpage) + ranges = ranges[firstindex:lastindex] # if time range not explicitly specified, only show from first appearance @@ -139,21 +153,26 @@ def module_performance(page=0,perpage=100,**kwargs): html += "" html += "" + if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs) return html -def module_trackcharts(page=0,perpage=100,**kwargs): +def module_trackcharts(page=0,perpage=100,max_=None,**kwargs): kwargs_filter = pickKeys(kwargs,"artist","associated") kwargs_time = pickKeys(kwargs,"timerange","since","to","within") + if max_ is not None: perpage,page=max_,0 + firstindex = page * perpage lastindex = firstindex + perpage tracks = database.get_charts_tracks(**kwargs_filter,**kwargs_time) + pages = math.ceil(len(tracks) / perpage) + # last time range (to compare) try: trackslast = database.get_charts_tracks(**kwargs_filter,timerange=kwargs_time["timerange"].next(step=-1)) @@ -211,19 +230,25 @@ def module_trackcharts(page=0,perpage=100,**kwargs): prev = e html += "" + if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs) + return (html,representative) -def module_artistcharts(page=0,perpage=100,**kwargs): +def module_artistcharts(page=0,perpage=100,max_=None,**kwargs): kwargs_filter = pickKeys(kwargs,"associated") #not used right now kwargs_time = pickKeys(kwargs,"timerange","since","to","within") + if max_ is not None: perpage,page=max_,0 + firstindex = page * perpage lastindex = firstindex + perpage artists = database.get_charts_artists(**kwargs_filter,**kwargs_time) + pages = math.ceil(len(artists) / perpage) + # last time range (to compare) try: #from malojatime import _get_next @@ -283,6 +308,8 @@ def module_artistcharts(page=0,perpage=100,**kwargs): html += "" + if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs) + return (html, representative) @@ -499,6 +526,44 @@ def module_trackcharts_tiles(**kwargs): return html + +def module_paginate(page,pages,**keys): + + unchangedkeys = internal_to_uri({**keys}) + + html = "