From 2cd54727510693052b52a61376d2193527de49e5 Mon Sep 17 00:00:00 2001 From: Krateng Date: Sun, 17 May 2020 14:11:24 +0200 Subject: [PATCH] Completed artist and track jinja templates --- maloja/__pkginfo__.py | 3 +- maloja/database.py | 2 + maloja/server.py | 4 +- maloja/static/less/maloja.less | 11 ++ maloja/web/jinja/artist.jinja | 18 ++- .../{awards.jinja => awards_artist.jinja} | 13 +- maloja/web/jinja/partials/awards_track.jinja | 63 ++++++++ maloja/web/jinja/partials/charts_tracks.jinja | 5 + maloja/web/jinja/partials/scrobbles.jinja | 8 +- maloja/web/jinja/track.jinja | 135 ++++++++++++++++++ 10 files changed, 242 insertions(+), 20 deletions(-) rename maloja/web/jinja/partials/{awards.jinja => awards_artist.jinja} (83%) create mode 100644 maloja/web/jinja/partials/awards_track.jinja create mode 100644 maloja/web/jinja/track.jinja diff --git a/maloja/__pkginfo__.py b/maloja/__pkginfo__.py index edfe0ba..96e0c01 100644 --- a/maloja/__pkginfo__.py +++ b/maloja/__pkginfo__.py @@ -19,7 +19,8 @@ requires = [ "nimrodel>=0.6.3", "setproctitle>=1.1.10", "wand>=0.5.4", - "lesscpy>=0.13" + "lesscpy>=0.13", + "jinja2">2.11 ] resources = [ "web/*/*", diff --git a/maloja/database.py b/maloja/database.py index 416ebc8..c17fe77 100644 --- a/maloja/database.py +++ b/maloja/database.py @@ -600,6 +600,7 @@ def artistInfo(artist): position = c["rank"] performance = get_performance(artist=artist,step="week") return { + "artist":artist, "scrobbles":scrobbles, "position":position, "associated":others, @@ -645,6 +646,7 @@ def trackInfo(track): return { + "track":track, "scrobbles":scrobbles, "position":position, "medals":{"gold":[],"silver":[],"bronze":[],**MEDALS_TRACKS.get((frozenset(track["artists"]),track["title"]),{})}, diff --git a/maloja/server.py b/maloja/server.py index 13d776a..176a47c 100755 --- a/maloja/server.py +++ b/maloja/server.py @@ -6,6 +6,8 @@ from .globalconf import datadir, DATA_DIR # server stuff from bottle import Bottle, route, get, post, error, run, template, static_file, request, response, FormsDict, redirect, template, HTTPResponse, BaseRequest import waitress +# templating +from jinja2 import Environment, PackageLoader, select_autoescape # monkey patching from . import monkey # rest of the project @@ -206,7 +208,7 @@ JINJA_CONTEXT = { ] } -from jinja2 import Environment, PackageLoader, select_autoescape + jinjaenv = Environment( loader=PackageLoader('maloja', 'web/jinja'), autoescape=select_autoescape(['html', 'xml']) diff --git a/maloja/static/less/maloja.less b/maloja/static/less/maloja.less index 7dc7ffe..3c1b60e 100644 --- a/maloja/static/less/maloja.less +++ b/maloja/static/less/maloja.less @@ -290,6 +290,17 @@ span.stat_selector_pulse,span.stat_selector_topartists,span.stat_selector_toptra } + +h2 { + display:inline-block; + padding-right:5px; + margin-bottom:10px; + margin-top:15px; +} +h2+span.afterheader { + color:@TEXT_COLOR_TERTIARY; +} + /* SHINY*/ .medal { top:5px; diff --git a/maloja/web/jinja/artist.jinja b/maloja/web/jinja/artist.jinja index 585bde5..258e62d 100644 --- a/maloja/web/jinja/artist.jinja +++ b/maloja/web/jinja/artist.jinja @@ -28,6 +28,7 @@ {% block content %} +{% import 'partials/awards_artist.jinja' as awards %} @@ -45,18 +46,18 @@

{{ artist }}

- {% if competes %}{{ positionstring }}{% endif %} + {% if competes %}#{{ info.position }}{% endif %}
{% if competes and included %} associated: {{ htmlgenerators.artistLinks(included) }} {% elif not competes %} - Competing under {{ htmlgenerators.artistLink(credited) }} ({{ positionstring }}) + Competing under {{ htmlgenerators.artistLink(credited) }} (#{{ info.position }}) {% endif %}

{{ info['scrobbles'] }} Scrobbles

- {% import 'partials/awards.jinja' as awards %} + {% if competes %} {{ awards.medals(info) }} @@ -74,7 +75,7 @@ {# htmlmodules.module_trackcharts(**filterkeys,max_=15)[0] #} {% import 'partials/charts_tracks.jinja' as charts_tracks %} -{{ charts_tracks.charts_tracks(filterkeys,limitkeys,amountkeys,compare=false) }} +{{ charts_tracks.charts_tracks(filterkeys,limitkeys,{"perpage":15,"page":0},compare=false) }}
@@ -83,7 +84,7 @@

Pulse

- +
{% for range in xranges %}

Performance

+ {% if not competes %}of {{ htmlgenerators.artistLink(credited) }} + {% endif %} +
{% for range in xranges %} - {{ performance.performance(filterkeys,{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }} + {{ performance.performance({'artist':credited},{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }} @@ -144,7 +148,7 @@
-

Last Scrobbles

+

Last Scrobbles

{% import 'partials/scrobbles.jinja' as scrobbles %} {{ scrobbles.scrobbles(filterkeys,limitkeys,{"perpage":15,"page":0}) }} diff --git a/maloja/web/jinja/partials/awards.jinja b/maloja/web/jinja/partials/awards_artist.jinja similarity index 83% rename from maloja/web/jinja/partials/awards.jinja rename to maloja/web/jinja/partials/awards_artist.jinja index 9f5b92d..4c6189e 100644 --- a/maloja/web/jinja/partials/awards.jinja +++ b/maloja/web/jinja/partials/awards_artist.jinja @@ -28,6 +28,8 @@ {% macro topweeks(info) %} +{% set encodedartist = urihandler.compose_querystring(urihandler.internal_to_uri({'artist':info.artist})) %} + @@ -51,15 +53,14 @@ {% macro certs(artist) %} -{% for track in db.get_tracks(artist=artist) %} +{% for track in db.get_tracks(artist=artist) -%} {% set info = db.trackInfo(track) %} - {% if info.certification is not none %} + {% if info.certification is not none -%} - - {% endif %} -{% endfor %} + title="{{ track.title }} has reached {{ info.certification.capitalize() }} status" /> + {%- endif %} +{%- endfor %} {%- endmacro %} diff --git a/maloja/web/jinja/partials/awards_track.jinja b/maloja/web/jinja/partials/awards_track.jinja new file mode 100644 index 0000000..bf06efc --- /dev/null +++ b/maloja/web/jinja/partials/awards_track.jinja @@ -0,0 +1,63 @@ +{% macro medals(info) %} + + +{% for year in info.medals.gold -%} + + {{ year }} + +{%- endfor %} +{% for year in info.medals.silver -%} + + {{ year }} + +{%- endfor %} +{% for year in info.medals.bronze -%} + + {{ year }} + +{%- endfor %} + +{%- endmacro %} + + + + + + + + +{% macro topweeks(info) %} + +{% set encodedtrack = urihandler.compose_querystring(urihandler.internal_to_uri({'track':info.track})) %} + + + + {% if info.topweeks is not none %} + + {{ info.topweeks }} + + {% endif %} + + +{%- endmacro %} + + + + + + + + + +{% macro certs(track) %} + + + +{% set info = db.trackInfo(track) %} +{% if info.certification is not none %} + +{% endif %} + +{%- endmacro %} diff --git a/maloja/web/jinja/partials/charts_tracks.jinja b/maloja/web/jinja/partials/charts_tracks.jinja index c0cd491..f090ff3 100644 --- a/maloja/web/jinja/partials/charts_tracks.jinja +++ b/maloja/web/jinja/partials/charts_tracks.jinja @@ -20,11 +20,15 @@ {% endfor %} {% endif %} +{% set firstindex = amountkeys.page * amountkeys.perpage %} +{% set lastindex = firstindex + amountkeys.perpage %} + {% set maxbar = tracks[0]['scrobbles'] if tracks != [] else 0 %} {% for e in tracks %} + {% if loop.index0 >= firstindex and loop.index0 < lastindex %} @@ -41,6 +45,7 @@ + {% endif %} {% endfor %}
{%if loop.changed(e.scrobbles) %}#{{ e.rank }}{% endif %}{{ htmlgenerators.scrobblesTrackLink(e['track'],urihandler.internal_to_uri(limitkeys),amount=e['scrobbles']) }} {{ htmlgenerators.scrobblesTrackLink(e['track'],urihandler.internal_to_uri(limitkeys),percent=e['scrobbles']*100/maxbar) }}
diff --git a/maloja/web/jinja/partials/scrobbles.jinja b/maloja/web/jinja/partials/scrobbles.jinja index 0ba0562..26ccdd6 100644 --- a/maloja/web/jinja/partials/scrobbles.jinja +++ b/maloja/web/jinja/partials/scrobbles.jinja @@ -1,4 +1,4 @@ -{% macro scrobbles(filterkeys,limitkeys,amountkeys) %} +{% macro scrobbles(filterkeys,limitkeys,amountkeys,shortTimeDesc=False) %} {% set scrobbles = dbp.get_scrobbles(filterkeys,limitkeys,amountkeys) %} @@ -10,11 +10,9 @@ {% for s in scrobbles %} - {% if loop.index0 > firstindex and loop.index0 < lastindex %} + {% if loop.index0 >= firstindex and loop.index0 < lastindex %} - + {{ entityrow.row(s) }} {% endif %} diff --git a/maloja/web/jinja/track.jinja b/maloja/web/jinja/track.jinja new file mode 100644 index 0000000..461db2a --- /dev/null +++ b/maloja/web/jinja/track.jinja @@ -0,0 +1,135 @@ +{% extends "base.jinja" %} +{% block title %}Maloja - {{ track.title }}{% endblock %} + +{% block scripts %} + + +{% endblock %} + +{% set track = filterkeys.track %} +{% set info = db.trackInfo(track) %} + +{% set initialrange ='month' %} + + +{% set encodedtrack = urihandler.compose_querystring(urihandler.internal_to_uri({'track':track})) %} + + +{% block content %} + + +{% import 'partials/awards_track.jinja' as awards %} + + +
- - {{ malojatime.timestamp_desc(s["time"],short=shortTimeDesc) }}
+ + + + +
+ {% if adminmode %} +
+ {% else %} +
+
+ {% endif %} +
+ {{ htmlgenerators.artistLinks(track.artists) }}
+

{{ track.title }}

+ {{ awards.certs(track) }} + #{{ info.position }} +
+ +

{{ info['scrobbles'] }} Scrobbles

+ + + + + + {{ awards.medals(info) }} + {{ awards.topweeks(info) }} + + +
+ + + + + + + + +
+

Pulse

+
+ {% for range in xranges %} + + {{ range.localisation }} + + {% if not loop.last %}|{% endif %} + {% endfor %} + +

+ + {% import 'partials/pulse.jinja' as pulse %} + {% for range in xranges %} + + + + {{ pulse.pulse(filterkeys,{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }} + + + {% endfor %} +
+ +

Performance

+
+ {% for range in xranges %} + + {{ range.localisation }} + + {% if not loop.last %}|{% endif %} + {% endfor %} + +

+ + {% import 'partials/performance.jinja' as performance %} + {% for range in xranges %} + + + + {{ performance.performance(filterkeys,{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }} + + + + {% endfor %} + +
+ + +

Last Scrobbles

+ +{% import 'partials/scrobbles.jinja' as scrobbles %} +{{ scrobbles.scrobbles(filterkeys,limitkeys,{"perpage":15,"page":0}) }} + + +{% endblock %}