mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added graphical pagination
This commit is contained in:
parent
a5d73f8fe9
commit
5fedde5e9f
@ -18,12 +18,14 @@ import math
|
|||||||
# result.append(element.get("image"))
|
# result.append(element.get("image"))
|
||||||
|
|
||||||
|
|
||||||
# artist=None,track=None,since=None,to=None,within=None,associated=False,max_=None,pictures=False
|
#max_ indicates that no pagination should occur (because this is not the primary module)
|
||||||
def module_scrobblelist(page=0,perpage=100,pictures=False,shortTimeDesc=False,earlystop=False,**kwargs):
|
def module_scrobblelist(page=0,perpage=100,max_=None,pictures=False,shortTimeDesc=False,earlystop=False,**kwargs):
|
||||||
|
|
||||||
kwargs_filter = pickKeys(kwargs,"artist","track","associated")
|
kwargs_filter = pickKeys(kwargs,"artist","track","associated")
|
||||||
kwargs_time = pickKeys(kwargs,"timerange","since","to","within")
|
kwargs_time = pickKeys(kwargs,"timerange","since","to","within")
|
||||||
|
|
||||||
|
if max_ is not None: perpage,page=max_,0
|
||||||
|
|
||||||
firstindex = page * perpage
|
firstindex = page * perpage
|
||||||
lastindex = firstindex + 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 = ["/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]
|
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
|
representative = scrobbles[0] if len(scrobbles) is not 0 else None
|
||||||
|
|
||||||
# build list
|
# build list
|
||||||
@ -62,22 +66,27 @@ def module_scrobblelist(page=0,perpage=100,pictures=False,shortTimeDesc=False,ea
|
|||||||
|
|
||||||
html += "</table>"
|
html += "</table>"
|
||||||
|
|
||||||
|
if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs)
|
||||||
|
|
||||||
return (html,len(scrobbles),representative)
|
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
|
from doreah.timing import clock, clockp
|
||||||
|
|
||||||
kwargs_filter = pickKeys(kwargs,"artist","track","associated")
|
kwargs_filter = pickKeys(kwargs,"artist","track","associated")
|
||||||
kwargs_time = pickKeys(kwargs,"since","to","within","timerange","step","stepn","trail")
|
kwargs_time = pickKeys(kwargs,"since","to","within","timerange","step","stepn","trail")
|
||||||
|
|
||||||
|
if max_ is not None: perpage,page=max_,0
|
||||||
|
|
||||||
firstindex = page * perpage
|
firstindex = page * perpage
|
||||||
lastindex = firstindex + perpage
|
lastindex = firstindex + perpage
|
||||||
|
|
||||||
|
|
||||||
ranges = database.get_pulse(**kwargs_time,**kwargs_filter)
|
ranges = database.get_pulse(**kwargs_time,**kwargs_filter)
|
||||||
|
|
||||||
|
pages = math.ceil(len(ranges) / perpage)
|
||||||
|
|
||||||
ranges = ranges[firstindex:lastindex]
|
ranges = ranges[firstindex:lastindex]
|
||||||
|
|
||||||
@ -100,21 +109,26 @@ def module_pulse(page=0,perpage=100,**kwargs):
|
|||||||
html += "</tr>"
|
html += "</tr>"
|
||||||
html += "</table>"
|
html += "</table>"
|
||||||
|
|
||||||
|
if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs)
|
||||||
|
|
||||||
return html
|
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_filter = pickKeys(kwargs,"artist","track")
|
||||||
kwargs_time = pickKeys(kwargs,"since","to","within","timerange","step","stepn","trail")
|
kwargs_time = pickKeys(kwargs,"since","to","within","timerange","step","stepn","trail")
|
||||||
|
|
||||||
|
if max_ is not None: perpage,page=max_,0
|
||||||
|
|
||||||
firstindex = page * perpage
|
firstindex = page * perpage
|
||||||
lastindex = firstindex + perpage
|
lastindex = firstindex + perpage
|
||||||
|
|
||||||
ranges = database.get_performance(**kwargs_time,**kwargs_filter)
|
ranges = database.get_performance(**kwargs_time,**kwargs_filter)
|
||||||
|
|
||||||
|
pages = math.ceil(len(ranges) / perpage)
|
||||||
|
|
||||||
ranges = ranges[firstindex:lastindex]
|
ranges = ranges[firstindex:lastindex]
|
||||||
|
|
||||||
# if time range not explicitly specified, only show from first appearance
|
# if time range not explicitly specified, only show from first appearance
|
||||||
@ -139,21 +153,26 @@ def module_performance(page=0,perpage=100,**kwargs):
|
|||||||
html += "</tr>"
|
html += "</tr>"
|
||||||
html += "</table>"
|
html += "</table>"
|
||||||
|
|
||||||
|
if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs)
|
||||||
|
|
||||||
return html
|
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_filter = pickKeys(kwargs,"artist","associated")
|
||||||
kwargs_time = pickKeys(kwargs,"timerange","since","to","within")
|
kwargs_time = pickKeys(kwargs,"timerange","since","to","within")
|
||||||
|
|
||||||
|
if max_ is not None: perpage,page=max_,0
|
||||||
|
|
||||||
firstindex = page * perpage
|
firstindex = page * perpage
|
||||||
lastindex = firstindex + perpage
|
lastindex = firstindex + perpage
|
||||||
|
|
||||||
tracks = database.get_charts_tracks(**kwargs_filter,**kwargs_time)
|
tracks = database.get_charts_tracks(**kwargs_filter,**kwargs_time)
|
||||||
|
|
||||||
|
pages = math.ceil(len(tracks) / perpage)
|
||||||
|
|
||||||
# last time range (to compare)
|
# last time range (to compare)
|
||||||
try:
|
try:
|
||||||
trackslast = database.get_charts_tracks(**kwargs_filter,timerange=kwargs_time["timerange"].next(step=-1))
|
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
|
prev = e
|
||||||
html += "</table>"
|
html += "</table>"
|
||||||
|
|
||||||
|
if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs)
|
||||||
|
|
||||||
return (html,representative)
|
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_filter = pickKeys(kwargs,"associated") #not used right now
|
||||||
kwargs_time = pickKeys(kwargs,"timerange","since","to","within")
|
kwargs_time = pickKeys(kwargs,"timerange","since","to","within")
|
||||||
|
|
||||||
|
if max_ is not None: perpage,page=max_,0
|
||||||
|
|
||||||
firstindex = page * perpage
|
firstindex = page * perpage
|
||||||
lastindex = firstindex + perpage
|
lastindex = firstindex + perpage
|
||||||
|
|
||||||
artists = database.get_charts_artists(**kwargs_filter,**kwargs_time)
|
artists = database.get_charts_artists(**kwargs_filter,**kwargs_time)
|
||||||
|
|
||||||
|
pages = math.ceil(len(artists) / perpage)
|
||||||
|
|
||||||
# last time range (to compare)
|
# last time range (to compare)
|
||||||
try:
|
try:
|
||||||
#from malojatime import _get_next
|
#from malojatime import _get_next
|
||||||
@ -283,6 +308,8 @@ def module_artistcharts(page=0,perpage=100,**kwargs):
|
|||||||
|
|
||||||
html += "</table>"
|
html += "</table>"
|
||||||
|
|
||||||
|
if max_ is None: html += module_paginate(page=page,pages=pages,**kwargs)
|
||||||
|
|
||||||
return (html, representative)
|
return (html, representative)
|
||||||
|
|
||||||
|
|
||||||
@ -499,6 +526,44 @@ def module_trackcharts_tiles(**kwargs):
|
|||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def module_paginate(page,pages,**keys):
|
||||||
|
|
||||||
|
unchangedkeys = internal_to_uri({**keys})
|
||||||
|
|
||||||
|
html = "<div class='paginate'>"
|
||||||
|
|
||||||
|
if page > 1:
|
||||||
|
html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"page":0})) + "'><span class='stat_selector'>" + "1" + "</span></a>"
|
||||||
|
html += " | "
|
||||||
|
|
||||||
|
if page > 2:
|
||||||
|
html += " ... | "
|
||||||
|
|
||||||
|
if page > 0:
|
||||||
|
html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"page":page-1})) + "'><span class='stat_selector'>" + str(page) + "</span></a>"
|
||||||
|
html += " « "
|
||||||
|
|
||||||
|
html += "<span style='opacity:0.5;' class='stat_selector'>" + str(page+1) + "</span>"
|
||||||
|
|
||||||
|
if page < pages-1:
|
||||||
|
html += " » "
|
||||||
|
html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"page":page+1})) + "'><span class='stat_selector'>" + str(page+2) + "</span></a>"
|
||||||
|
|
||||||
|
if page < pages-3:
|
||||||
|
html += " | ... "
|
||||||
|
|
||||||
|
if page < pages-2:
|
||||||
|
html += " | "
|
||||||
|
html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"page":pages-1})) + "'><span class='stat_selector'>" + str(pages) + "</span></a>"
|
||||||
|
|
||||||
|
|
||||||
|
html += "</div>"
|
||||||
|
|
||||||
|
return html
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# THIS FUNCTION USES THE ORIGINAL URI KEYS!!!
|
# THIS FUNCTION USES THE ORIGINAL URI KEYS!!!
|
||||||
def module_filterselection(keys,time=True,delimit=False):
|
def module_filterselection(keys,time=True,delimit=False):
|
||||||
|
|
||||||
@ -510,6 +575,7 @@ def module_filterselection(keys,time=True,delimit=False):
|
|||||||
|
|
||||||
html = ""
|
html = ""
|
||||||
|
|
||||||
|
|
||||||
if time:
|
if time:
|
||||||
# all other keys that will not be changed by clicking another filter
|
# all other keys that will not be changed by clicking another filter
|
||||||
#keystr = "?" + compose_querystring(keys,exclude=["since","to","in"])
|
#keystr = "?" + compose_querystring(keys,exclude=["since","to","in"])
|
||||||
|
@ -106,6 +106,7 @@ def uri_to_internal(keys,forceTrack=False,forceArtist=False):
|
|||||||
resultkeys4 = {"page":0,"perpage":100}
|
resultkeys4 = {"page":0,"perpage":100}
|
||||||
# if "max" in keys: resultkeys4["max_"] = int(keys["max"])
|
# if "max" in keys: resultkeys4["max_"] = int(keys["max"])
|
||||||
if "max" in keys: resultkeys4["page"],resultkeys4["perpage"] = 0, int(keys["max"])
|
if "max" in keys: resultkeys4["page"],resultkeys4["perpage"] = 0, int(keys["max"])
|
||||||
|
#different max than the internal one! the user doesn't get to disable pagination
|
||||||
if "page" in keys: resultkeys4["page"] = int(keys["page"])
|
if "page" in keys: resultkeys4["page"] = int(keys["page"])
|
||||||
if "perpage" in keys: resultkeys4["perpage"] = int(keys["perpage"])
|
if "perpage" in keys: resultkeys4["perpage"] = int(keys["perpage"])
|
||||||
|
|
||||||
@ -149,8 +150,8 @@ def internal_to_uri(keys):
|
|||||||
urikeys.append("trail",str(keys["trail"]))
|
urikeys.append("trail",str(keys["trail"]))
|
||||||
|
|
||||||
# stuff
|
# stuff
|
||||||
if "max_" in keys:
|
#if "max_" in keys:
|
||||||
urikeys.append("max",str(keys["max_"]))
|
# urikeys.append("max",str(keys["max_"]))
|
||||||
if "page" in keys:
|
if "page" in keys:
|
||||||
urikeys.append("page",str(keys["page"]))
|
urikeys.append("page",str(keys["page"]))
|
||||||
if "perpage" in keys:
|
if "perpage" in keys:
|
||||||
|
@ -268,6 +268,11 @@ p.desc a {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
.paginate {
|
||||||
|
text-align: center;
|
||||||
|
padding:30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.stats {
|
.stats {
|
||||||
|
@ -42,7 +42,7 @@ def instructions(keys):
|
|||||||
|
|
||||||
|
|
||||||
# scrobbles
|
# scrobbles
|
||||||
html_scrobbles, _, _ = module_scrobblelist(perpage=15,shortTimeDesc=True,pictures=True,earlystop=True)
|
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True,earlystop=True)
|
||||||
|
|
||||||
clockp("Scrobbles")
|
clockp("Scrobbles")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user