Commit 028b1ab2 authored by Evert Prants's avatar Evert Prants

Add next and previous buttons to episode page

parent adb14fe4
......@@ -174,3 +174,9 @@ AUTH_REDIRECT_URL = oauth_options.get('redirect_url')
DISCUSSIONS_PER_PAGE = 26
DISCUSSIONS_REPLIES_PER_PAGE = 10
# Domain of this app
DOMAIN='localhost'
# Use subdomains for each show
DOMAIN_SUBDOMAIN_SHOWS=False
......@@ -33,6 +33,12 @@ from .models import DiscussionBoard
# Get a show's URL by its abbreviation
def get_show_url(abbr):
use_sdms = getattr(settings, "DOMAIN_SUBDOMAIN_SHOWS", False)
domain = getattr(settings, "DOMAIN", 'localhost')
if use_sdms:
return '%s.%s' % (abbr, domain)
return '/show/%s' % (abbr)
# Redirect url should point to this view
......
......@@ -55,6 +55,11 @@
<div class="submission-list">
{% for sbm in submissions %}
<div class="submission{% if sbm.positives < sbm.negatives %} buried{% endif %}{% if sbm.pinned %} pinned{% endif %}{% if highlight and highlight == sbm.id %} highlighted{% endif %} mb-2">
{% if forloop.counter0 == 0 and sbm.embed and not sbm.positives < sbm.negatives %}
<div class="onsite-player d-flex justify-content-center mb-2">
<iframe src="{{sbm.embed}}" width="1024" height="640"></iframe>
</div>
{% endif %}
<div class="row">
<div class="col">
<a href="{{sbm.url}}" class="link d-block mb-2">
......@@ -114,5 +119,26 @@
<span class="fillertext"><a href="/login">Log in</a> to submit a link</span>
{% endif %}
</div>
<p>Discuss <q>{{episode.name}}</q> on the <a href="{{showurl}}/discuss">discussion boards</a>!</p>
<ul class="nav fixed-bottom d-flex justify-content-center border-top bg-light">
{% if has_previous %}
<li class="nav-item">
<a class="nav-link" href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode|add:'-1'}}">Previous Episode</a>
</li>
{% else %}
<li class="nav-item">
<a href="#" class="nav-link disabled">Previous Episode</a>
</li>
{% endif %}
{% if has_next %}
<li class="nav-item">
<a class="nav-link" href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode|add:'1'}}">Next Episode</a>
</li>
{% else %}
<li class="nav-item">
<a href="#" class="nav-link disabled">Next Episode</a>
</li>
{% endif %}
</ul>
</section>
{% endblock %}
......@@ -21,6 +21,7 @@
<li class="breadcrumb-item active" aria-current="page">{{show.name}}</li>
</ol>
</nav>
<p>Discuss {{show.name}} on the <a href="discuss">discussion boards</a>!</p>
{% for season in seasons %}
<div class="row mb-3">
<div class="col-md-2 mb-2">
......
......@@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from django.template import RequestContext
from django.shortcuts import render, get_list_or_404, get_object_or_404
from django.shortcuts import render, get_list_or_404, get_object_or_404, redirect
from django.views import View
from django.views.generic.base import TemplateView
from django.contrib.auth.decorators import login_required
......@@ -69,6 +69,34 @@ class EpisodeView(TemplateView):
# Get show by abbr
show = get_object_or_404(Show, abbr=abbr)
# Check next or previous
season_number = int(season)
episode_number = int(episode)
lastep = Episode.objects.filter(season__number=season_number,show=show).order_by('episode').last()
season_count = Season.objects.filter(show=show).count()
if season_count == 0:
raise Http404('This show has no episodes.')
if episode_number == 0 and season_number > 1:
season_number -= 1
epobj = Episode.objects.filter(season__number=season_number,show=show).order_by('episode').last()
if not epobj:
raise Http404('No Episode matches the given query.')
episode_number = int(epobj.episode)
ctx['url'] = '%s/episode/%d/%d'%(ctx['showurl'], season_number, episode_number)
elif episode_number > int(lastep.episode):
season_number += 1
episode_number = 1
ctx['url'] = '%s/episode/%d/%d'%(ctx['showurl'], season_number, episode_number)
if 'url' in ctx:
return ctx
episode = get_object_or_404(Episode, show=show,season__number=season,episode=episode)
# I acknowledge that this is a mess. A functional mess. But a mess nonetheless. Hey, that rhymed!
......@@ -90,9 +118,17 @@ class EpisodeView(TemplateView):
ctx['episode'] = episode
ctx['submissions'] = submissions
ctx['highlight'] = highlight
ctx['has_previous'] = episode_number > 1 or season_number > 1
ctx['has_next'] = episode_number < int(lastep.episode) or season_number < season_count
return ctx
def render_to_response(self, context):
if 'url' in context:
return redirect(context['url'])
return super(EpisodeView, self).render_to_response(context)
def EpisodeFindSubmission(req, abbr, submission):
show = get_object_or_404(Show, abbr=abbr)
submission = int(submission)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment