mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Merged remaining references to two uri modules
This commit is contained in:
parent
ed1c595e20
commit
a6088ec7b7
@ -5,7 +5,7 @@ author = {
|
||||
"email":"maloja@krateng.dev",
|
||||
"github": "krateng"
|
||||
}
|
||||
version = 2,8,4
|
||||
version = 2,8,5
|
||||
versionstr = ".".join(str(n) for n in version)
|
||||
links = {
|
||||
"pypi":"malojaserver",
|
||||
|
@ -5,7 +5,7 @@ from bottle import request, response, FormsDict
|
||||
from .cleanup import CleanerAgent, CollectorAgent
|
||||
from . import utilities
|
||||
from .malojatime import register_scrobbletime, time_stamps, ranges
|
||||
from .urihandler import uri_to_internal, internal_to_uri, compose_querystring
|
||||
from .malojauri import uri_to_internal, internal_to_uri, compose_querystring
|
||||
from . import compliant_api
|
||||
|
||||
from .thirdparty import proxy_scrobble_all
|
||||
|
@ -1,7 +1,7 @@
|
||||
from .. import database_packed
|
||||
from . import filters
|
||||
|
||||
from .. import database, database_packed, malojatime, utilities, urihandler, malojauri
|
||||
from .. import database, database_packed, malojatime, utilities, malojauri
|
||||
from doreah import settings
|
||||
from doreah.regular import repeatdaily
|
||||
|
||||
@ -29,7 +29,6 @@ def update_jinja_environment():
|
||||
"dbp":dbp,
|
||||
"malojatime": malojatime,
|
||||
"utilities": utilities,
|
||||
"urihandler": urihandler,
|
||||
"mlj_uri": malojauri,
|
||||
"settings": settings.get_settings,
|
||||
# external
|
||||
|
@ -63,11 +63,14 @@ def uri_to_internal(keys,forceTrack=False,forceArtist=False):
|
||||
|
||||
|
||||
def create_uri(path,*keydicts):
|
||||
return path + "?" + uriencode(*keydicts)
|
||||
|
||||
def uriencode(*keydicts):
|
||||
keyd = {}
|
||||
for kd in keydicts:
|
||||
keyd.update(kd)
|
||||
|
||||
return path + "?" + compose_querystring(internal_to_uri(keyd))
|
||||
return compose_querystring(internal_to_uri(keyd))
|
||||
|
||||
|
||||
def internal_to_uri(keys):
|
||||
|
@ -15,9 +15,7 @@ from . import malojatime
|
||||
from . import utilities
|
||||
from . import malojauri
|
||||
from .utilities import resolveImage
|
||||
from .urihandler import remove_identical
|
||||
from .malojauri import uri_to_internal
|
||||
from . import urihandler
|
||||
from .malojauri import uri_to_internal, remove_identical
|
||||
from . import globalconf
|
||||
from .jinjaenv.context import jinja_environment
|
||||
# doreah toolkit
|
||||
|
@ -1,167 +0,0 @@
|
||||
import urllib
|
||||
from bottle import FormsDict
|
||||
from .malojatime import time_fix, time_str, get_range_object
|
||||
import math
|
||||
|
||||
# necessary because urllib.parse.urlencode doesnt handle multidicts
|
||||
def compose_querystring(*dicts,exclude=[]):
|
||||
|
||||
st = ""
|
||||
keys = remove_identical(*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
|
||||
|
||||
|
||||
# takes any number of multidicts and normal dicts and creates a formsdict with duplicate values removed
|
||||
def remove_identical(*dicts):
|
||||
#combine multiple dicts
|
||||
keys = FormsDict()
|
||||
for d in dicts:
|
||||
for k in d:
|
||||
try: #multidicts
|
||||
for v in d.getall(k):
|
||||
keys.append(k,v)
|
||||
except: #normaldicts
|
||||
v = d.get(k)
|
||||
keys.append(k,v)
|
||||
|
||||
new = FormsDict()
|
||||
for k in keys:
|
||||
#values = set(keys.getall(k))
|
||||
values = keys.getall(k) # NO IDENTICAL REMOVAL FOR NOW
|
||||
for v in values:
|
||||
new.append(k,v)
|
||||
|
||||
return new
|
||||
|
||||
|
||||
# this also sets defaults!
|
||||
def uri_to_internal(keys,forceTrack=False,forceArtist=False):
|
||||
|
||||
# output:
|
||||
# 1 keys that define the filtered object like artist or track
|
||||
# 2 keys that define time limits of the whole thing
|
||||
# 3 keys that define interal time ranges
|
||||
# 4 keys that define amount limits
|
||||
|
||||
# 1
|
||||
if "title" in keys and not forceArtist:
|
||||
resultkeys1 = {"track":{"artists":keys.getall("artist"),"title":keys.get("title")}}
|
||||
elif "artist" in keys and not forceTrack:
|
||||
resultkeys1 = {"artist":keys.get("artist")}
|
||||
if "associated" in keys: resultkeys1["associated"] = True
|
||||
else:
|
||||
resultkeys1 = {}
|
||||
|
||||
# 2
|
||||
resultkeys2 = {}
|
||||
# if "since" in keys: resultkeys2["since"] = time_fix(keys.get("since"))
|
||||
# elif "from" in keys: resultkeys2["since"] = time_fix(keys.get("from"))
|
||||
# elif "start" in keys: resultkeys2["since"] = time_fix(keys.get("start"))
|
||||
# #
|
||||
# if "to" in keys: resultkeys2["to"] = time_fix(keys.get("to"))
|
||||
# elif "until" in keys: resultkeys2["to"] = time_fix(keys.get("until"))
|
||||
# elif "end" in keys: resultkeys2["to"] = time_fix(keys.get("end"))
|
||||
# #
|
||||
# if "since" in resultkeys2 and "to" in resultkeys2 and resultkeys2["since"] == resultkeys2["to"]:
|
||||
# resultkeys2["within"] = resultkeys2["since"]
|
||||
# del resultkeys2["since"]
|
||||
# del resultkeys2["to"]
|
||||
# #
|
||||
# if "in" in keys: resultkeys2["within"] = time_fix(keys.get("in"))
|
||||
# elif "within" in keys: resultkeys2["within"] = time_fix(keys.get("within"))
|
||||
# elif "during" in keys: resultkeys2["within"] = time_fix(keys.get("during"))
|
||||
# if "within" in resultkeys2:
|
||||
# if "since" in resultkeys2:
|
||||
# del resultkeys2["since"]
|
||||
# if "to" in resultkeys2:
|
||||
# del resultkeys2["to"]
|
||||
since,to,within = None,None,None
|
||||
if "since" in keys: since = keys.get("since")
|
||||
elif "from" in keys: since = keys.get("from")
|
||||
elif "start" in keys: since = keys.get("start")
|
||||
if "to" in keys: to = keys.get("to")
|
||||
elif "until" in keys: to = keys.get("until")
|
||||
elif "end" in keys: to = keys.get("end")
|
||||
if "in" in keys: within = keys.get("in")
|
||||
elif "within" in keys: within = keys.get("within")
|
||||
elif "during" in keys: within = keys.get("during")
|
||||
resultkeys2["timerange"] = get_range_object(since=since,to=to,within=within)
|
||||
|
||||
#3
|
||||
resultkeys3 = {"step":"month","stepn":1,"trail":1}
|
||||
if "step" in keys: [resultkeys3["step"],resultkeys3["stepn"]] = (keys["step"].split("-") + [1])[:2]
|
||||
if "stepn" in keys: resultkeys3["stepn"] = keys["stepn"] #overwrite if explicitly given
|
||||
if "stepn" in resultkeys3: resultkeys3["stepn"] = int(resultkeys3["stepn"]) #in both cases, convert it here
|
||||
if "trail" in keys: resultkeys3["trail"] = int(keys["trail"])
|
||||
if "cumulative" in keys: resultkeys3["trail"] = math.inf
|
||||
|
||||
|
||||
|
||||
#4
|
||||
resultkeys4 = {"page":0,"perpage":100}
|
||||
# if "max" in keys: resultkeys4["max_"] = 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 "perpage" in keys: resultkeys4["perpage"] = int(keys["perpage"])
|
||||
|
||||
|
||||
return resultkeys1, resultkeys2, resultkeys3, resultkeys4
|
||||
|
||||
def compose_from_dicts(*dicts):
|
||||
return compose_querystring(internal_to_uri_p(*dicts))
|
||||
|
||||
def internal_to_uri_p(*dicts):
|
||||
return internal_to_uri({k:d[k] for d in dicts for k in d})
|
||||
|
||||
def internal_to_uri(keys):
|
||||
urikeys = FormsDict()
|
||||
|
||||
#filter
|
||||
if "artist" in keys:
|
||||
urikeys.append("artist",keys["artist"])
|
||||
if keys.get("associated"): urikeys.append("associated","yes")
|
||||
elif "track" in keys:
|
||||
for a in keys["track"]["artists"]:
|
||||
urikeys.append("artist",a)
|
||||
urikeys.append("title",keys["track"]["title"])
|
||||
|
||||
#time
|
||||
if "timerange" in keys:
|
||||
keydict = keys["timerange"].urikeys()
|
||||
for k in keydict:
|
||||
urikeys.append(k,keydict[k])
|
||||
elif "within" in keys:
|
||||
urikeys.append("in",time_str(keys["within"]))
|
||||
else:
|
||||
if "since" in keys and keys["since"] is not None:
|
||||
urikeys.append("since",time_str(keys["since"]))
|
||||
if "to" in keys and keys["to"] is not None:
|
||||
urikeys.append("to",time_str(keys["to"]))
|
||||
|
||||
# delimit
|
||||
if "step" in keys:
|
||||
urikeys.append("step",keys["step"])
|
||||
if "stepn" in keys:
|
||||
urikeys.append("stepn",str(keys["stepn"]))
|
||||
if "trail" in keys:
|
||||
if keys["trail"] == math.inf:
|
||||
urikeys.append("cumulative","yes")
|
||||
else:
|
||||
urikeys.append("trail",str(keys["trail"]))
|
||||
|
||||
# stuff
|
||||
#if "max_" in keys:
|
||||
# urikeys.append("max",str(keys["max_"]))
|
||||
if "page" in keys:
|
||||
urikeys.append("page",str(keys["page"]))
|
||||
if "perpage" in keys:
|
||||
urikeys.append("perpage",str(keys["perpage"]))
|
||||
|
||||
|
||||
return urikeys
|
@ -24,8 +24,7 @@
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% set encodedartist = urihandler.compose_querystring(urihandler.internal_to_uri({'artist':artist})) %}
|
||||
{% set encodedcredited = urihandler.compose_querystring(urihandler.internal_to_uri({'artist':credited})) %}
|
||||
{% set encodedartist = mlj_uri.uriencode({'artist':artist}) %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
@ -57,7 +56,7 @@
|
||||
<span>Competing under {{ links.link(credited) }} (#{{ info.position }})</span>
|
||||
{% endif %}
|
||||
|
||||
<p class="stats"><a href="/scrobbles?{{ encodedartist }}">{{ info['scrobbles'] }} Scrobbles</a></p>
|
||||
<p class="stats"><a href="{{ mlj_uri.create_uri("/scrobbles",filterkeys) }}">{{ info['scrobbles'] }} Scrobbles</a></p>
|
||||
|
||||
|
||||
|
||||
@ -115,7 +114,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<!-- We use the same classes / function calls here because we want it to switch together with pulse -->
|
||||
<h2 class="headerwithextra"><a href='{{ mlj_uri.create_uri("/performance",filterkeys) }}'>Performance</a></h2>
|
||||
<h2 class="headerwithextra"><a href='{{ mlj_uri.create_uri("/performance",{'artist':credited}) }}'>Performance</a></h2>
|
||||
{% if not competes %}<span class="afterheader">of {{ links.link(credited) }}</span>
|
||||
{% endif %}
|
||||
<br/>
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
{% macro topweeks(info) %}
|
||||
|
||||
{% set encodedartist = urihandler.compose_querystring(urihandler.internal_to_uri({'artist':info.artist})) %}
|
||||
{% set encodedartist = mlj_uri.uriencode({'artist':info.artist}) %}
|
||||
|
||||
|
||||
<!-- TOPWEEKS -->
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
{% macro topweeks(info) %}
|
||||
|
||||
{% set encodedtrack = urihandler.compose_querystring(urihandler.internal_to_uri({'track':info.track})) %}
|
||||
{% set encodedtrack = mlj_uri.uriencode({'track':info.track}) %}
|
||||
|
||||
<!-- TOPWEEKS -->
|
||||
<span>
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
{% if pages > 1 %}
|
||||
{% if page > 1 %}
|
||||
<a href='?{{ urihandler.compose_from_dicts(filterkeys,limitkeys,delimitkeys,amountkeys,{'page':0}) }}'>
|
||||
<a href='{{ mlj_uri.create_uri("",filterkeys,limitkeys,delimitkeys,amountkeys,{'page':0}) }}'>
|
||||
<span class='stat_selector'>1</span>
|
||||
</a> |
|
||||
{% endif %}
|
||||
@ -19,7 +19,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if page > 0 %}
|
||||
<a href='?{{ urihandler.compose_from_dicts(filterkeys,limitkeys,delimitkeys,amountkeys,{'page':page-1}) }}'>
|
||||
<a href='{{ mlj_uri.create_uri("",filterkeys,limitkeys,delimitkeys,amountkeys,{'page':page-1}) }}'>
|
||||
<span class='stat_selector'>{{ page }}</span>
|
||||
</a> «
|
||||
{% endif %}
|
||||
@ -29,7 +29,7 @@
|
||||
</span>
|
||||
|
||||
{% if page < pages-1 %}
|
||||
» <a href='?{{ urihandler.compose_from_dicts(filterkeys,limitkeys,delimitkeys,amountkeys,{'page':page+1}) }}'>
|
||||
» <a href='{{ mlj_uri.create_uri("",filterkeys,limitkeys,delimitkeys,amountkeys,{'page':page+1}) }}'>
|
||||
<span class='stat_selector'>{{ page+2 }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
@ -39,7 +39,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if page < pages-2 %}
|
||||
| <a href='?{{ urihandler.compose_from_dicts(filterkeys,limitkeys,delimitkeys,amountkeys,{'page':pages-1}) }}'>
|
||||
| <a href='{{ mlj_uri.create_uri("",filterkeys,limitkeys,delimitkeys,amountkeys,{'page':pages-1}) }}'>
|
||||
<span class='stat_selector'>{{ pages }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
@ -18,7 +18,7 @@
|
||||
{% set initialrange ='month' %}
|
||||
|
||||
|
||||
{% set encodedtrack = urihandler.compose_querystring(urihandler.internal_to_uri({'track':track})) %}
|
||||
{% set encodedtrack = mlj_uri.uriencode({'track':track}) %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
Loading…
Reference in New Issue
Block a user