1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added time selector to scrobbles and fixed bug with multiartist tracks

This commit is contained in:
Krateng 2019-04-02 12:59:42 +02:00
parent aa56e11d85
commit c96103ad28
4 changed files with 49 additions and 40 deletions

View File

@ -32,15 +32,17 @@ def scrobblesLink(timekeys,amount=None,percent=None,artist=None,track=None,assoc
return "<a href='/scrobbles?" + keysToUrl(timekeys) + "'>" + inner + "</a>"
# necessary because urllib.parse.urlencode doesnt handle multidicts
def keysToUrl(*dicts):
def keysToUrl(*dicts,exclude=[]):
st = ""
keys = removeIdentical(*dicts)
for k in keys:
if k in exclude: continue
values = keys.getall(k)
st += "&".join([urllib.parse.urlencode({k:v},safe="/") for v in values])
st += "&"
return st
def removeIdentical(*dicts):
#combine multiple dicts
keys = FormsDict()

View File

@ -283,10 +283,10 @@ def module_filterselection(keys,time=True,delimit=False):
html = ""
if time:
retainkeys = {k:keys[k] for k in keys if k not in ["since","to","in"]}
keystr = "?" + urllib.parse.urlencode(retainkeys)
keystr = "?" + keysToUrl(keys,exclude=["since","to","in"])
# wonky selector for precise date range
@ -343,8 +343,7 @@ def module_filterselection(keys,time=True,delimit=False):
if delimit:
retainkeys = {k:keys[k] for k in keys if k not in ["step","stepn"]}
keystr = "?" + urllib.parse.urlencode(retainkeys)
keystr = "?" + keysToUrl(keys,exclude=["step","stepn"])
html += "<div>"
if keys.get("step") == "day":
@ -367,8 +366,8 @@ def module_filterselection(keys,time=True,delimit=False):
html += "</div>"
retainkeys = {k:keys[k] for k in keys if k not in ["trail"]}
keystr = "?" + urllib.parse.urlencode(retainkeys)
keystr = "?" + keysToUrl(keys,exclude=["trail"])
html += "<div>"
if keys.get("trail") == "1" or keys.get("trail") is None:

View File

@ -16,6 +16,8 @@
<h1>Scrobbles</h1><br/>
<span>KEY_LIMITS</span>
<p class="stats">KEY_SCROBBLES Scrobbles</p>
<br/>
KEY_FILTERSELECTOR
</td>
</tr>

View File

@ -5,7 +5,7 @@ import database
def instructions(keys):
from utilities import getArtistImage, getTrackImage
from htmlgenerators import artistLink, artistLinks, trackLink, KeySplit
from htmlmodules import module_scrobblelist
from htmlmodules import module_scrobblelist, module_filterselection
from malojatime import range_desc
@ -27,6 +27,8 @@ def instructions(keys):
limitstring += " " + range_desc(**timekeys)
html_filterselector = module_filterselection(keys)
html, amount, rep = module_scrobblelist(**filterkeys,**timekeys,**amountkeys)
@ -44,6 +46,10 @@ def instructions(keys):
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
replace = {"KEY_SCROBBLELIST":html,"KEY_SCROBBLES":str(amount),"KEY_IMAGEURL":imgurl,"KEY_LIMITS":limitstring}
replace = {"KEY_SCROBBLELIST":html,
"KEY_SCROBBLES":str(amount),
"KEY_IMAGEURL":imgurl,
"KEY_LIMITS":limitstring,
"KEY_FILTERSELECTOR":html_filterselector}
return (replace,pushresources)