server: moved as_play_link from being a filter to a macro

master
Felix Stupp 3 years ago
parent 0e468d457f
commit 66502e5c08
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -135,19 +135,15 @@ Pony(flask_app)
####
@flask_app.template_filter()
def encode_options(opts: dict[str, Any]):
return urlencode({k: str(v) for k, v in opts.items()}, quote_via=quote_plus)
@flask_app.template_filter()
def as_link(uri: str):
uri = Markup.escape(uri)
return Markup(f'<a href="{uri}">{uri}</a>')
@flask_app.template_filter()
def as_play_link(video_uri: str):
opts = {
"video_uri": video_uri,
}
play_uri = "entertainment-decider:///player/play?" + urlencode(opts, quote_via=quote_plus)
return Markup(f'<a class=button href="{play_uri}">Play</a>')
@flask_app.template_filter()
def tenary(b: bool, true_str: str, false_str: str) -> str:
return true_str if b else false_str

@ -46,10 +46,17 @@
</form>
{% endmacro %}
{% macro as_play_link(element) -%}
{%- set opts = {
"video_uri": element.uri,
} -%}
<a class="button" href="entertainment-decider:///player/play?{{ opts | encode_options }}">Play</a>
{%- endmacro -%}
{% macro media_element_buttons(element) %}
{% set api_uri = "/api/media/" + element.id|string %}
{% set fragment = "media_element_" + element.id|string %}
{{ element.uri | as_play_link }}
{{ as_play_link(element) }}
{% if element.watched %}
{{ post_form(api_uri, "watched", "false", "Unmark as Watched", fragment) }}
{% elif element.ignored %}

Loading…
Cancel
Save