Add YouTube playlist support in game detail views and create custom template tag

This commit is contained in:
Edgar P. Burkhart 2025-06-14 12:53:46 +02:00
parent 08e4d6e75b
commit 3042382ae4
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
5 changed files with 20 additions and 2 deletions

View file

@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load form %}
{% load form youtube %}
{% block content %}
<h1>
{% if group.owner == user %}
@ -39,6 +39,9 @@
<thead>
{% if group.owner == user %}<th></th>{% endif %}
<th>Date</th>
<th>
<i class="ri-youtube-fill"></i> Playlists
</th>
<th>Joueurs</th>
</thead>
<tbody>
@ -52,6 +55,11 @@
<td>
<a href="{% url "game_detail" pk=game.pk %}">{{ game.date }}</a>
</td>
<td>
{% if game.playlist %}
<a href="{% yt_playlist game %}"><i class="ri-youtube-fill"></i> Playlist</a>
{% endif %}
</td>
<td>{{ game.players.all|join:", " }}</td>
</tr>
{% endfor %}

View file

@ -1,4 +1,5 @@
{% extends "base.html" %}
{% load youtube %}
{% block content %}
<h1>
<i class="ri-play-circle-fill"></i> {{ musikgame.date }}
@ -6,7 +7,7 @@
{% if musikgame.playlist or musikgame.playlist_loading %}
<p>
<a target="_blank"
href="https://youtube.com/watch?v={{ musikgame.musicgameorder_set.first.music_video.yt_id }}&list={{ musikgame.playlist }}"
href="{% yt_playlist musikgame %}"
role="button"
{% if musikgame.playlist_loading %}aria-busy="true"{% endif %}><i class="ri-youtube-fill"></i> Playlist</a>
</p>

View file

@ -0,0 +1 @@
<a href="{{ url }}">{{ text }}</a>

View file

View file

@ -0,0 +1,8 @@
from django import template
register = template.Library()
@register.simple_tag
def yt_playlist(game):
return f"https://youtube.com/watch?v={game.musicgameorder_set.first().music_video.yt_id}&list={game.playlist}"