Add 'artist' view to 'vote' app

main
Luca 2 years ago
parent 378e9b164e
commit 495f90f28f

@ -1,6 +1,22 @@
{% extends "core/base.html" %} {% extends "core/base.html" %}
{% block title %}{% endblock %} {% block title %}{{ artist.name }}{% endblock %}
{% block body %} {% block body %}
<h1>{{ artist.name }}</h1>
<p>{{ artist.genre }} &middot; {{ artist.origin }}<br>{{ artist.comment }}</p>
<div class="pagination">
{% if offset > 0 %}
<a href="{% url 'artist' playlist offset|add:-1 %}">&lt; Zurück</a>
{% else %}
<a></a>
{% endif %}
{{ offset|add:1 }}/{{ count }}
{% if offset < count|add:-1 %}
<a href="{% url 'artist' playlist offset|add:1 %}">Weiter &gt;</a>
{% else %}
<a></a>
{% endif %}
</div>
{% endblock %} {% endblock %}

@ -1,4 +1,4 @@
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, redirect, render
from .forms import JoinSessionForm from .forms import JoinSessionForm
from ..core.models import Session from ..core.models import Session
@ -14,7 +14,16 @@ def join_session(request, session):
if not form.is_valid(): if not form.is_valid():
return render(request, 'vote/join_session.html', {'form': JoinSessionForm()}) return render(request, 'vote/join_session.html', {'form': JoinSessionForm()})
request.session['session'] = session.token
return redirect('artist', session.playlist.pk)
return render(request, 'vote/join_session.html', {'form': form}) return render(request, 'vote/join_session.html', {'form': form})
def artist(request, playlist, offset=None): def artist(request, playlist, offset=None):
return render(request, 'vote/artist.html', {}) session = get_object_or_404(Session, pk=request.session.get('session'))
offset = offset or 0
artists = session.playlist.artist_set
artist = artists.order_by('id')[offset]
return render(request, 'vote/artist.html', {'artist': artist, 'count': artists.count(), 'offset': offset, 'playlist': session.playlist.pk})

Loading…
Cancel
Save