From 028b1ab279b006089f5837e38eecc791676da8d3 Mon Sep 17 00:00:00 2001 From: Evert Date: Fri, 2 Mar 2018 11:59:44 +0200 Subject: [PATCH] Add next and previous buttons to episode page --- EpisodesCommunity/settings.py | 6 ++++++ LandingPage/views.py | 6 ++++++ Show/templates/episode.html | 26 ++++++++++++++++++++++++ Show/templates/show.html | 1 + Show/views.py | 38 ++++++++++++++++++++++++++++++++++- 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/EpisodesCommunity/settings.py b/EpisodesCommunity/settings.py index d1fed2c..e646da2 100644 --- a/EpisodesCommunity/settings.py +++ b/EpisodesCommunity/settings.py @@ -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 diff --git a/LandingPage/views.py b/LandingPage/views.py index 58253db..cf848ce 100644 --- a/LandingPage/views.py +++ b/LandingPage/views.py @@ -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 diff --git a/Show/templates/episode.html b/Show/templates/episode.html index 2502bc3..5a94280 100644 --- a/Show/templates/episode.html +++ b/Show/templates/episode.html @@ -55,6 +55,11 @@
{% for sbm in submissions %}
+ {% if forloop.counter0 == 0 and sbm.embed and not sbm.positives < sbm.negatives %} +
+ +
+ {% endif %}
@@ -114,5 +119,26 @@ Log in to submit a link {% endif %}
+

Discuss {{episode.name}} on the discussion boards!

+ {% endblock %} diff --git a/Show/templates/show.html b/Show/templates/show.html index 0c106d0..bdb1df0 100644 --- a/Show/templates/show.html +++ b/Show/templates/show.html @@ -21,6 +21,7 @@ +

Discuss {{show.name}} on the discussion boards!

{% for season in seasons %}
diff --git a/Show/views.py b/Show/views.py index f0cdebd..8c1a966 100644 --- a/Show/views.py +++ b/Show/views.py @@ -15,7 +15,7 @@ # along with this program. If not, see . 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)