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

Completed artist and track jinja templates

This commit is contained in:
Krateng 2020-05-17 14:11:24 +02:00
parent b3f4fc1246
commit 2cd5472751
10 changed files with 242 additions and 20 deletions

View File

@ -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/*/*",

View File

@ -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"]),{})},

View File

@ -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'])

View File

@ -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;

View File

@ -28,6 +28,7 @@
{% block content %}
{% import 'partials/awards_artist.jinja' as awards %}
<table class="top_info">
@ -45,18 +46,18 @@
</td>
<td class="text">
<h1>{{ artist }}</h1>
{% if competes %}<span class="rank"><a href="/charts_artists?max=100">{{ positionstring }}</a></span>{% endif %}
{% if competes %}<span class="rank"><a href="/charts_artists?max=100">#{{ info.position }}</a></span>{% endif %}
<br/>
{% if competes and included %}
<span>associated: {{ htmlgenerators.artistLinks(included) }}</span>
{% elif not competes %}
<span>Competing under {{ htmlgenerators.artistLink(credited) }} ({{ positionstring }})</span>
<span>Competing under {{ htmlgenerators.artistLink(credited) }} (#{{ info.position }})</span>
{% endif %}
<p class="stats"><a href="/scrobbles?{{ encodedartist }}">{{ info['scrobbles'] }} Scrobbles</a></p>
{% 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) }}
<br/>
@ -83,7 +84,7 @@
<tr>
<td>
<h2><a href='/pulse?{{ encodedartist }}&amp;step=year&amp;trail=1'>Pulse</a></h2>
<br/>
{% for range in xranges %}
<span
onclick="showRangeManual('pulse','{{ range.identifier }}')"
@ -112,6 +113,9 @@
<td>
<!-- We use the same classes / function calls here because we want it to switch together with pulse -->
<h2><a href='/performance?{{ encodedcredited }}&amp;step=year&amp;trail=1'>Performance</a></h2>
{% if not competes %}<span class="afterheader">of {{ htmlgenerators.artistLink(credited) }}</span>
{% endif %}
<br/>
{% for range in xranges %}
<span
@ -133,7 +137,7 @@
style="{{ 'display:none;' if initialrange==range.identifier else '' }}"
>
{{ 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) }}
</span>
@ -144,7 +148,7 @@
</table>
<h2><a href='/scrobbles?{encodedartist}'>Last Scrobbles</a></h2>
<h2><a href='/scrobbles?{{ encodedartist }}'>Last Scrobbles</a></h2>
{% import 'partials/scrobbles.jinja' as scrobbles %}
{{ scrobbles.scrobbles(filterkeys,limitkeys,{"perpage":15,"page":0}) }}

View File

@ -28,6 +28,8 @@
{% macro topweeks(info) %}
{% set encodedartist = urihandler.compose_querystring(urihandler.internal_to_uri({'artist':info.artist})) %}
<!-- TOPWEEKS -->
<span>
@ -51,15 +53,14 @@
{% macro certs(artist) %}
<!-- CERTS -->
{% 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 -%}
<a href='{{ htmlgenerators.link_address(track) }}'>
<img class="certrecord_small"
src="/media/record_{{ info.certification }}.png"
title="{{ track.title }} has reached {{ info.certification.capitalize() }} status" />
</a>
{% endif %}
{% endfor %}
title="{{ track.title }} has reached {{ info.certification.capitalize() }} status" /></a>
{%- endif %}
{%- endfor %}
{%- endmacro %}

View File

@ -0,0 +1,63 @@
{% macro medals(info) %}
<!-- MEDALS -->
{% for year in info.medals.gold -%}
<a title="Best Track in {{ year }}" class="hidelink medal shiny gold" href='/charts_tracks?max=50&amp;in={{ year }}'>
<span>{{ year }}</span>
</a>
{%- endfor %}
{% for year in info.medals.silver -%}
<a title="Second best Track in {{ year }}" class="hidelink medal shiny silver" href='/charts_tracks?max=50&amp;in={{ year }}'>
<span>{{ year }}</span>
</a>
{%- endfor %}
{% for year in info.medals.bronze -%}
<a title="Third best Track in {{ year }}" class="hidelink medal shiny bronze" href='/charts_tracks?max=50&amp;in={{ year }}'>
<span>{{ year }}</span>
</a>
{%- endfor %}
{%- endmacro %}
{% macro topweeks(info) %}
{% set encodedtrack = urihandler.compose_querystring(urihandler.internal_to_uri({'track':info.track})) %}
<!-- TOPWEEKS -->
<span>
{% if info.topweeks is not none %}
<a title="{{ info.topweeks }} weeks on #1" href="/performance?{{ encodedtrack }}&step=week">
<img class="star" src="/media/star.png" />{{ info.topweeks }}
</a>
{% endif %}
</span>
{%- endmacro %}
{% macro certs(track) %}
<!-- CERTS -->
{% set info = db.trackInfo(track) %}
{% if info.certification is not none %}
<img class="certrecord"
src="/media/record_{{ info.certification }}.png"
title="This track has reached {{ info.certification.capitalize() }} status" />
{% endif %}
{%- endmacro %}

View File

@ -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 %}
<table class='list'>
{% for e in tracks %}
{% if loop.index0 >= firstindex and loop.index0 < lastindex %}
<tr>
<!-- Rank -->
<td class="rank">{%if loop.changed(e.scrobbles) %}#{{ e.rank }}{% endif %}</td>
@ -41,6 +45,7 @@
<td class="amount">{{ htmlgenerators.scrobblesTrackLink(e['track'],urihandler.internal_to_uri(limitkeys),amount=e['scrobbles']) }}</td>
<td class="bar">{{ htmlgenerators.scrobblesTrackLink(e['track'],urihandler.internal_to_uri(limitkeys),percent=e['scrobbles']*100/maxbar) }}</td>
</tr>
{% endif %}
{% endfor %}
</table>

View File

@ -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 @@
<table class='list'>
{% for s in scrobbles %}
{% if loop.index0 > firstindex and loop.index0 < lastindex %}
{% if loop.index0 >= firstindex and loop.index0 < lastindex %}
<tr>
<td class='time'>
</td>
<td class='time'>{{ malojatime.timestamp_desc(s["time"],short=shortTimeDesc) }}</td>
{{ entityrow.row(s) }}
</tr>
{% endif %}

View File

@ -0,0 +1,135 @@
{% extends "base.jinja" %}
{% block title %}Maloja - {{ track.title }}{% endblock %}
{% block scripts %}
<script src="/rangeselect.js"></script>
<script>
function scrobble(encodedtrack,apikey) {
neo.xhttprequest('/api/newscrobble?' + encodedtrack + "key=" + apikey).then(response=>{window.location.reload()});
}
</script>
{% 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 %}
<table class="top_info">
<tr>
<td class="image">
{% if adminmode %}
<div
class="changeable-image" data-uploader="b64=>upload('{encodedartist}','{apikey}',b64)"
style="background-image:url('{{ utilities.getTrackImage(artists=track.artists,title=track.title,fast=True) }}');"
></div>
{% else %}
<div style="background-image:url('{{ utilities.getTrackImage(artists=track.artists,title=track.title,fast=True) }}');">
</div>
{% endif %}
</td>
<td class="text">
<span>{{ htmlgenerators.artistLinks(track.artists) }}</span><br/>
<h1>{{ track.title }}</h1>
{{ awards.certs(track) }}
<span class="rank"><a href="/charts_tracks?max=100">#{{ info.position }}</a></span>
<br/>
<p class="stats"><a href="/scrobbles?{{ encodedtrack }}">{{ info['scrobbles'] }} Scrobbles</a></p>
{{ awards.medals(info) }}
{{ awards.topweeks(info) }}
</td>
</tr>
</table>
<table class="twopart">
<tr>
<td>
<h2><a href='/pulse?{{ encodedtrack }}&amp;step=year&amp;trail=1'>Pulse</a></h2>
<br/>
{% for range in xranges %}
<span
onclick="showRangeManual('pulse','{{ range.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ range.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==range.identifier else '' }}">
{{ range.localisation }}
</span>
{% if not loop.last %}|{% endif %}
{% endfor %}
<br/><br/>
{% import 'partials/pulse.jinja' as pulse %}
{% for range in xranges %}
<span
class="stat_module_pulse pulse_{{ range.identifier }}"
style="{{ 'display:none;' if initialrange==range.identifier else '' }}"
>
{{ pulse.pulse(filterkeys,{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }}
</span>
{% endfor %}
</td>
<td>
<!-- We use the same classes / function calls here because we want it to switch together with pulse -->
<h2><a href='/performance?{{ encodedtrack }}&amp;step=year&amp;trail=1'>Performance</a></h2>
<br/>
{% for range in xranges %}
<span
onclick="showRangeManual('pulse','{{ range.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ range.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==range.identifier else '' }}">
{{ range.localisation }}
</span>
{% if not loop.last %}|{% endif %}
{% endfor %}
<br/><br/>
{% import 'partials/performance.jinja' as performance %}
{% for range in xranges %}
<span
class="stat_module_pulse pulse_{{ range.identifier }}"
style="{{ 'display:none;' if initialrange==range.identifier else '' }}"
>
{{ performance.performance(filterkeys,{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }}
</span>
{% endfor %}
</td>
</tr>
</table>
<h2><a href='/scrobbles?{{ encodedtrack }}'>Last Scrobbles</a></h2>
{% import 'partials/scrobbles.jinja' as scrobbles %}
{{ scrobbles.scrobbles(filterkeys,limitkeys,{"perpage":15,"page":0}) }}
{% endblock %}