c3dfa234125133e2ee473f14dcb200eba341bddf
[audio.git] / src / archive / templatetags / tags.py
1 from django import template
2
3 register = template.Library()
4
5
6 @register.inclusion_tag('archive/tags/multiple_tags_table.html')
7 def multiple_tags_table(tags, table=True):
8     new_tags = {}
9     if tags:
10         for k, v in tags.items():
11             if isinstance(v, list):
12                 new_tags[k] = v
13             else:
14                 new_tags[k] = [v]
15     return {"tags": new_tags, "table": table}
16
17
18 @register.inclusion_tag('archive/tags/tags_table.html')
19 def tags_table(tags, table=True):
20     if tags is None:
21         tags = {}
22     return locals()
23
24
25 @register.inclusion_tag("archive/status.html")
26 def status(audiobook, format):
27     if format == "youtube" and audiobook.youtube_id:
28         link = f"https://youtu.be/{audiobook.youtube_id}"
29     else:
30         link = None
31     return {
32         "published": getattr(audiobook, f"{format}_published"),
33         "status": getattr(audiobook, f"get_{format}_status_display")(),
34         "format": format,
35         "link": link,
36     }