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

Replaced some old htmlgenerator calls with jinja macros

This commit is contained in:
Krateng 2020-08-31 20:57:56 +02:00
parent 363c431b93
commit f7ca7b0dc9
14 changed files with 75 additions and 21 deletions

View File

@ -2,6 +2,7 @@
{% extends "abstracts/admin.jinja" %}
{% block title %}Maloja - Issues{% endblock %}
{% import 'snippets/links.jinja' as links %}
{% block scripts %}
<script>
@ -50,7 +51,7 @@
{% for issue in issuedata.duplicates %}
<tr>
<td>{{ htmlgenerators.artistLink(issue[0]) }} is a possible duplicate of {{ htmlgenerators.artistLink(issue[1]) }}</td>
<td>{{ links.link(issue[0]) }} is a possible duplicate of {{ links.link(issue[1]) }}</td>
<td class='button' onclick="newrule(this,'replaceartist','{{ issue[0] }}','{{ issue[1] }}')"><div>{{ issue[1] }} is correct</div></td>
<td class='button' onclick="newrule(this,'replaceartist','{{ issue[1] }}','{{ issue[0] }}')"><div>{{ issue[0] }} is correct</div></td>
</tr>
@ -58,7 +59,7 @@
{% for issue in issuedata.combined %}
<tr>
<td>{{ htmlgenerators.artistLink(issue[0]) }} sounds like the combination of {{ issue[1].__len__() }} artists:
<td>{{ links.link(issue[0]) }} sounds like the combination of {{ issue[1].__len__() }} artists:
{{ issue[1]|join(", ") }}
</td>
<td class='button' onclick="newrule(this,'replaceartist','{{ issue[0] }}','{{ issue[1] | join('␟') }}')"><div>Fix it</div></td>
@ -67,7 +68,7 @@
{% for issue in issuedata.newartists %}
<tr>
<td>Is '{{ issue[0] }}' in '{{ htmlgenerators.artistLink(issue[1]) }}' an artist?</td>
<td>Is '{{ issue[0] }}' in '{{ links.link(issue[1]) }}' an artist?</td>
<td class='button' onclick="newrule(this,'replaceartist','{{ issue[1] }}','{{ (issue[2] + [issue[0]]) | join('␟') }}')"><div>Yes</div></td>
</tr>
{% endfor %}

View File

@ -1,6 +1,9 @@
{% extends "abstracts/base.jinja" %}
{% block title %}Maloja - {{ artist }}{% endblock %}
{% import 'snippets/links.jinja' as links %}
{% import 'partials/awards_artist.jinja' as awards %}
{% block scripts %}
<script src="/rangeselect.js"></script>
{% endblock %}
@ -28,7 +31,7 @@
{% block content %}
{% import 'partials/awards_artist.jinja' as awards %}
<table class="top_info">
@ -49,9 +52,9 @@
{% 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>
<span>associated: {{ links.links(included) }}</span>
{% elif not competes %}
<span>Competing under {{ htmlgenerators.artistLink(credited) }} (#{{ info.position }})</span>
<span>Competing under {{ links.link(credited) }} (#{{ info.position }})</span>
{% endif %}
<p class="stats"><a href="/scrobbles?{{ encodedartist }}">{{ info['scrobbles'] }} Scrobbles</a></p>
@ -113,7 +116,7 @@
<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>
{% if not competes %}<span class="afterheader">of {{ htmlgenerators.artistLink(credited) }}</span>
{% if not competes %}<span class="afterheader">of {{ links.link(credited) }}</span>
{% endif %}
<br/>

View File

@ -1,6 +1,8 @@
{% extends "abstracts/base.jinja" %}
{% block title %}Maloja - Track Charts{% endblock %}
{% import 'snippets/links.jinja' as links %}
{% block scripts %}
<script src="/datechange.js" async></script>
{% endblock %}
@ -24,7 +26,7 @@
</td>
<td class="text">
<h1>Track Charts</h1><a href="/top_tracks"><span>View #1 Tracks</span></a><br/>
{% if filterkeys.get('artist') is not none %}by {{ htmlgenerators.artistLink(filterkeys.get('artist')) }}{% endif %}
{% if filterkeys.get('artist') is not none %}by {{ links.link(filterkeys.get('artist')) }}{% endif %}
<span>{{ limitkeys.timerange.desc(prefix=True) }}</span>
<br/><br/>
{% import 'snippets/timeselection.jinja' as timeselection %}

View File

@ -1,6 +1,8 @@
{% extends "abstracts/base.jinja" %}
{% block title %}Maloja - Compare{% endblock %}
{% import 'snippets/links.jinja' as links %}
{% block scripts %}
<style>
.comparecircle {
@ -99,7 +101,7 @@
<td></td>
<td>
<span>Common Favorite</span>
<h2 style="margin:7px;">{{ htmlgenerators.artistLink(bestartist) }}</h2>
<h2 style="margin:7px;">{{ links.link(bestartist) }}</h2>
<img src="{{ utilities.getArtistImage(bestartist) }}" style="width:80px;" />
</td>
<td></td>

View File

@ -1,3 +1,6 @@
{% import 'snippets/links.jinja' as links %}
{% macro medals(info) %}
<!-- MEDALS -->
@ -56,7 +59,7 @@
{% for track in db.get_tracks(artist=artist) -%}
{% set info = db.trackInfo(track) %}
{% if info.certification is not none -%}
<a href='{{ htmlgenerators.link_address(track) }}'>
<a href='{{ links.url(track) }}'>
<img class="certrecord_small"
src="/media/record_{{ info.certification }}.png"
title="{{ track.title }} has reached {{ info.certification.capitalize() }} status" /></a>

View File

@ -1,3 +1,6 @@
{% import 'snippets/links.jinja' as links %}
{% import 'snippets/entityrow.jinja' as entityrow %}
{% macro charts_artists(limitkeys,amountkeys,charts=None,compare=False) %}
{% if charts is none %}
@ -47,7 +50,7 @@
{% endif %}
<!-- artist -->
{{ htmlgenerators.entity_column(e['artist']) }}
{{ entityrow.row(e['artist']) }}
<!-- scrobbles -->
<td class="amount">{{ htmlgenerators.scrobblesArtistLink(e['artist'],urihandler.internal_to_uri(limitkeys),amount=e['scrobbles']) }}</td>

View File

@ -1,3 +1,5 @@
{% import 'snippets/links.jinja' as links %}
{% macro charts_artists_tiles(limitkeys,amountkeys,charts=None,compare=False) %}
{% if charts is none %}
@ -21,7 +23,7 @@
{% set artist = entry.artist %}
{% set rank = entry.rank %}
<td>
<a href="{{ htmlgenerators.link_address(artist) }}">
<a href="{{ links.url(artist) }}">
<div style='cursor:pointer;background-image:url("{{ utilities.getArtistImage(artist,fast=True) }}")'>
<span class='stats'>#{{ rank }}</span> <span>{{ artist }}</span>
</div>

View File

@ -1,3 +1,6 @@
{% import 'snippets/links.jinja' as links %}
{% import 'snippets/entityrow.jinja' as entityrow %}
{% macro charts_tracks(filterkeys,limitkeys,amountkeys,charts=None,compare=False) %}
{% if charts is none %}
@ -44,7 +47,7 @@
{% endif %}
<!-- artist -->
{{ htmlgenerators.entity_column(e['track']) }}
{{ entityrow.row(e['track']) }}
<!-- scrobbles -->
<td class="amount">{{ htmlgenerators.scrobblesTrackLink(e['track'],urihandler.internal_to_uri(limitkeys),amount=e['scrobbles']) }}</td>

View File

@ -1,3 +1,5 @@
{% import 'snippets/links.jinja' as links %}
{% macro charts_tracks_tiles(filterkeys,limitkeys,amountkeys,charts=None,compare=False) %}
{% if charts is none %}
@ -21,7 +23,7 @@
{% set track = entry.track %}
{% set rank = entry.rank %}
<td>
<a href="{{ htmlgenerators.link_address(track) }}">
<a href="{{ links.url(track) }}">
<div style='cursor:pointer;background-image:url("{{ utilities.getTrackImage(track.artists,track.title,fast=True) }}")'>
<span class='stats'>#{{ rank }}</span> <span>{{ track.title }}</span>
</div>

View File

@ -1,3 +1,5 @@
{% import 'snippets/links.jinja' as links %}
{% set ranges = dbp.get_performance(filterkeys,limitkeys,delimitkeys) %}
{% set minrank = ranges|map(attribute="rank")|reject("none")|max|default(60) %}

View File

@ -1,5 +1,7 @@
{% macro row(entity,counting=[]) %}
{% import 'snippets/links.jinja' as links %}
{% if 'artists' in entity %}
{% set img = utilities.getTrackImage(artists=entity.artists,title=entity.title,fast=True) %}
{% else %}
@ -9,12 +11,12 @@
<td class='icon'><div style="background-image:url('{{ img }}')"></div></td>
{% if "artists" in entity %}
<td class='track'>
<span class='artist_in_trackcolumn'>{{ htmlgenerators.html_links(entity.artists) }}</span> {{ htmlgenerators.html_link(entity) }}
<span class='artist_in_trackcolumn'>{{ links.links(entity.artists) }}</span> {{ links.link(entity) }}
</td>
{% else %}
<td class='artist'>{{ htmlgenerators.html_link(entity) }}
<td class='artist'>{{ links.link(entity) }}
{% if counting != [] %}
<span class='extra'>incl. {{ htmlgenerators.html_links(counting) }}</span>
<span class='extra'>incl. {{ links.links(counting) }}</span>
{% endif %}
</td>

View File

@ -1,10 +1,12 @@
{% import 'snippets/links.jinja' as links %}
{% macro desc(filterkeys,limitkeys,prefix="by") %}
{% if filterkeys.get('artist') is not none %}
{{ prefix }} {{ htmlgenerators.artistLink(filterkeys.get('artist')) }}
{{ prefix }} {{ links.link(filterkeys.get('artist')) }}
{% elif filterkeys.get('track') is not none %}
of {{ htmlgenerators.trackLink(filterkeys.get('track')) }}
by {{ htmlgenerators.artistLinks(filterkeys["track"]["artists"]) }}
of {{ links.link(filterkeys.get('track')) }}
by {{ links.links(filterkeys["track"]["artists"]) }}
{% endif %}
{{ limitkeys.timerange.desc(prefix=True) }}

View File

@ -0,0 +1,25 @@
{% macro link(entity) -%}
{% if 'artists' in entity %}
{% set name = entity.title %}
{% else %}
{% set name = entity %}
{% endif %}
<a href="{{ url(entity) }}">{{ name }}</a>
{%- endmacro %}
{% macro links(entities) -%}
{% for entity in entities -%}
{{ link(entity) }}{{ ", " if not loop.last }}
{%- endfor %}
{%- endmacro %}
{% macro url(entity) -%}
{% if 'artists' in entity %}
{{ mlj_uri.create_uri("/track",{'track':entity}) }}
{% else %}
{{ mlj_uri.create_uri("/artist",{'artist':entity}) }}
{% endif %}
{%- endmacro %}

View File

@ -1,6 +1,8 @@
{% extends "abstracts/base.jinja" %}
{% block title %}Maloja - {{ track.title }}{% endblock %}
{% import 'snippets/links.jinja' as links %}
{% block scripts %}
<script src="/rangeselect.js"></script>
<script>
@ -39,7 +41,7 @@
{% endif %}
</td>
<td class="text">
<span>{{ htmlgenerators.artistLinks(track.artists) }}</span><br/>
<span>{{ links.links(track.artists) }}</span><br/>
<h1 class="headerwithextra">{{ track.title }}</h1>
{{ awards.certs(track) }}
<span class="rank"><a href="/charts_tracks?max=100">#{{ info.position }}</a></span>