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

Added pyhp partials

This commit is contained in:
Krateng 2019-12-19 20:05:50 +01:00
parent 582c4c8814
commit 94a20a8818
2 changed files with 135 additions and 0 deletions

View File

@ -0,0 +1,76 @@
<pyhp>
if amountkeys.get("max_") is not None: amountkeys["perpage"],amountkeys["page"] = amountkeys["max_"],0
firstindex = amountkeys["page"] * amountkeys["perpage"]
lastindex = firstindex + amountkeys["perpage"]
</pyhp>
<pyhp import="math" />
<pyhp save="db.get_charts_artists(**filterkeys,**limitkeys)" as="artists" />
<pyhp save="math.ceil(len(artists) / amountkeys['perpage'])" as="pages" />
<pyhp>
try:
artistslast = db.get_charts_artists(**filterkeys,timerange=limitkeys["timerange"].next(step=-1))
# create rank association
lastrank = {}
for al in artistslast:
lastrank[al["artist"]] = al["rank"]
for a in artists:
try:
a["delta"] = lastrank[a["artist"]] - a["rank"]
except:
a["delta"] = math.inf
except:
pass
</pyhp>
<!--
if artists != []:
maxbar = artists[0]["scrobbles"]
representative = artists[0]["artist"]
else:
representative = None
-->
<pyhp save="artists[0]['scrobbles'] if artists != [] else 0" as="maxbar" />
<table class='list'>
<pyhp save="True" as="first" />
<pyhp for="e" in="artists[firstindex:lastindex]">
<tr>
<!-- Rank -->
<td class="rank"><pyhp if="first or e['scrobbles'] < prev['scrobbles']">#<pyhp echo="e['rank']"/></pyhp></td>
<pyhp save="False" as="first" />
<!-- Rank change -->
<pyhp if="e.get('delta') is not None">
<pyhp if="e.get('delta') is math.inf">
<td class='rankup' title='New'>🆕</td>
</pyhp>
<pyhp if="e.get('delta') > 0 and e.get('delta') is not math.inf">
<td class='rankup' title="up from #{e['rank']+e['delta']}">↗</td>
</pyhp>
<pyhp if="e.get('delta') < 0">
<td class='rankdown' title="down from #{e['rank']+e['delta']}">↘</td>
</pyhp>
<pyhp if="e.get('delta') == 0">
<td class='ranksame' title="Unchanged">➡</td>
</pyhp>
</pyhp>
<!-- artist -->
<pyhp echo="htmlgenerators.entity_column(e['artist'],counting=e['counting'])" />
<!-- scrobbles -->
<td class="amount"><pyhp echo="htmlgenerators.scrobblesArtistLink(e['artist'],limitkeys,amount=e['scrobbles'],**filterkeys,associated=True)" /></td>
<td class="bar"><pyhp echo="htmlgenerators.scrobblesArtistLink(e['artist'],limitkeys,percent=e['scrobbles']*100/maxbar,**filterkeys,associated=True)" /></td>
</tr>
<pyhp save="e" as="prev" />
</pyhp>
</table>
<pyhp if="amountkeys.get('max_') is None">
<pyhp include="pagination.pyhp" />
</pyhp>

View File

@ -0,0 +1,59 @@
<pyhp save="{k:amountkeys[k] for k in amountkeys if k in ['perpage','pages']}" as="unchangedamountkeys" />
<pyhp save="{**unchangedamountkeys,**filterkeys,**limitkeys,**delimitkeys}" as="unchanged" />
<pyhp save="amountkeys['page']" as="page" />
<pyhp save="urihandler.compose_querystring" as="compose" />
<pyhp save="urihandler.internal_to_uri" as="touri" />
<div class='paginate'>
<pyhp if="page > 1">
<a href='?{compose(touri(dict(**unchanged,page=0)))}'>
<span class='stat_selector'>
1
</span>
</a>
|
</pyhp>
<pyhp if="page > 2">
... |
</pyhp>
<pyhp if="page > 0">
<a href='?{compose(touri(dict(**unchanged,page=page-1)))}'>
<span class='stat_selector'>
<pyhp echo="page" />
</span>
</a>
«
</pyhp>
<span style='opacity:0.5;' class='stat_selector'>
<pyhp echo="page+1" />
</span>
<pyhp if="page < pages - 1">
»
<a href='?{compose(touri(dict(**unchanged,page=page+1)))}'>
<span class='stat_selector'>
<pyhp echo="page+2" />
</span>
</a>
</pyhp>
<pyhp if="page < pages - 3">
| ...
</pyhp>
<pyhp if="page < pages - 2">
|
<a href='?{compose(touri(dict(**unchanged,page=pages-1)))}'>
<span class='stat_selector'>
<pyhp echo="pages" />
</span>
</a>
</pyhp>
</div>