diff --git a/Discussions/templates/board.html b/Discussions/templates/board.html index 2207024..53eebf4 100644 --- a/Discussions/templates/board.html +++ b/Discussions/templates/board.html @@ -39,6 +39,7 @@ {% if "can_moderate_board" in show_perms or board.user == user %}
{{reply.body}}
Restore + Ban {% endif %}
{% else %} diff --git a/Discussions/views.py b/Discussions/views.py index ebb8d79..6fc1b45 100644 --- a/Discussions/views.py +++ b/Discussions/views.py @@ -29,15 +29,12 @@ from django.utils.text import slugify from guardian.decorators import permission_required_or_403 from LandingPage.models import Show, DiscussionBoard, DiscussionReply, DiscussionVote, Ban, Report +from LandingPage.views import get_show_url from . import forms import datetime import re -# Append common values to context -def get_show_url(abbr): - return '/show/%s' % (abbr) - class Boards(TemplateView): template_name = "boards.html" diff --git a/LandingPage/views.py b/LandingPage/views.py index 946f09b..58253db 100644 --- a/LandingPage/views.py +++ b/LandingPage/views.py @@ -31,7 +31,10 @@ from .models import Show from .models import Submission from .models import DiscussionBoard -# Create your views here. +# Get a show's URL by its abbreviation +def get_show_url(abbr): + return '/show/%s' % (abbr) + # Redirect url should point to this view class LoginRedirect(View): def get(self, req): diff --git a/Show/templates/create_ban.html b/Show/templates/create_ban.html index dfdb19e..e798897 100644 --- a/Show/templates/create_ban.html +++ b/Show/templates/create_ban.html @@ -7,7 +7,7 @@
diff --git a/Show/templates/episode.html b/Show/templates/episode.html index 9a9d551..2502bc3 100644 --- a/Show/templates/episode.html +++ b/Show/templates/episode.html @@ -46,7 +46,7 @@
@@ -68,13 +68,13 @@
-
+ {% csrf_token %}
-
+ {% csrf_token %}
@@ -106,9 +106,9 @@
{% if user.is_authenticated %} {% if "can_moderate_show" in show_perms %} -  Add New Link +  Add New Link {% else %} -  Submit New Link +  Submit New Link {% endif %} {% else %} Log in to submit a link diff --git a/Show/templates/episode_add.html b/Show/templates/episode_add.html index 0c5dac9..27e3802 100644 --- a/Show/templates/episode_add.html +++ b/Show/templates/episode_add.html @@ -33,7 +33,7 @@
diff --git a/Show/templates/report.html b/Show/templates/report.html index 394d43b..acf5e6d 100644 --- a/Show/templates/report.html +++ b/Show/templates/report.html @@ -33,8 +33,8 @@
diff --git a/Show/templates/season_add.html b/Show/templates/season_add.html index f7e250e..70a0aa1 100644 --- a/Show/templates/season_add.html +++ b/Show/templates/season_add.html @@ -7,7 +7,7 @@
diff --git a/Show/templates/show.html b/Show/templates/show.html index 03d484a..0c106d0 100644 --- a/Show/templates/show.html +++ b/Show/templates/show.html @@ -41,14 +41,14 @@
{% if "can_moderate_show" in show_perms %}
- +
{% endif %} {% endfor %} {% if "can_moderate_show" in show_perms %} {% endif %}
diff --git a/Show/templates/submit.html b/Show/templates/submit.html index 6c01cda..30634e1 100644 --- a/Show/templates/submit.html +++ b/Show/templates/submit.html @@ -33,8 +33,8 @@
diff --git a/Show/templates/submit_mod.html b/Show/templates/submit_mod.html index 4ed99f0..cc4b8e1 100644 --- a/Show/templates/submit_mod.html +++ b/Show/templates/submit_mod.html @@ -35,8 +35,8 @@ {% get_obj_perms request.user for show as "show_perms" %} diff --git a/Show/views.py b/Show/views.py index 052b558..f0cdebd 100644 --- a/Show/views.py +++ b/Show/views.py @@ -27,6 +27,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from guardian.decorators import permission_required_or_403 from LandingPage.models import User, Show, Season, Episode, Submission, SubmissionVote, Ban, Report +from LandingPage.views import get_show_url from . import forms @@ -50,6 +51,7 @@ class IndexView(TemplateView): # Add fields to context ctx['show'] = show ctx['seasons'] = seasons + ctx['showurl'] = get_show_url(abbr) return ctx @@ -59,6 +61,7 @@ class EpisodeView(TemplateView): def get_context_data(self, abbr, season, episode, **kwargs): ctx = super().get_context_data() + ctx['showurl'] = get_show_url(abbr) highlight = self.request.GET.get('submission', None) if not highlight == None: @@ -93,10 +96,11 @@ class EpisodeView(TemplateView): def EpisodeFindSubmission(req, abbr, submission): show = get_object_or_404(Show, abbr=abbr) submission = int(submission) + showurl = get_show_url(abbr) episode = get_object_or_404(Episode, submissions__id=submission) - return HttpResponseRedirect('/show/%s/episode/%d/%d?submission=%d'%(abbr, episode.season.number, episode.episode, submission)) + return HttpResponseRedirect('%s/episode/%d/%d?submission=%d'%(showurl, episode.season.number, episode.episode, submission)) # Submission form GET and POST @login_required @@ -111,7 +115,8 @@ def SubmissionForm(req, abbr, season, episode): ctx = { 'form': form, 'show': show, - 'episode': episode + 'episode': episode, + 'showurl': get_show_url(abbr) } # Get bans for this user regarding this show @@ -144,7 +149,7 @@ def SubmissionForm(req, abbr, season, episode): new_submission.episode = episode new_submission.save() - return HttpResponseRedirect('/show/%s/episode/%d/%d'%(abbr, episode.season.number, episode.episode)) + return HttpResponseRedirect('%s/episode/%d/%d'%(ctx['showurl'], episode.season.number, episode.episode)) else: ctx['error'] = 'Invalid fields!' @@ -164,18 +169,19 @@ def SubmissionModForm(req, abbr, submission): ctx = { 'form': form, 'show': show, - 'episode': episode + 'episode': episode, + 'showurl': get_show_url(abbr) } # Handle POST if req.method == 'POST': if 'delete' in req.POST: submission.delete() - return HttpResponseRedirect('/show/%s/episode/%d/%d'%(abbr, episode.season.number, episode.episode)) + return HttpResponseRedirect('%s/episode/%d/%d'%(ctx['showurl'], episode.season.number, episode.episode)) if 'delete_ban' in req.POST: submission.delete() - return HttpResponseRedirect('/show/%s/create_ban?user=%s'%(abbr,submission.user.username)) + return HttpResponseRedirect('%s/create_ban?user=%s'%(ctx['showurl'],submission.user.username)) form = forms.SubmissionFormAdmin(req.POST, instance=submission) ctx['form'] = form @@ -184,7 +190,7 @@ def SubmissionModForm(req, abbr, submission): form_data = form.cleaned_data form.save() - return HttpResponseRedirect('/show/%s/episode/%d/%d'%(abbr, episode.season.number, episode.episode)) + return HttpResponseRedirect('%s/episode/%d/%d'%(ctx['showurl'], episode.season.number, episode.episode)) else: ctx['error'] = 'Invalid fields!' @@ -201,7 +207,8 @@ def SeasonSubmitForm(req, abbr): # Request context ctx = { 'form': form, - 'show': show + 'show': show, + 'showurl': get_show_url(abbr) } # Handle POST @@ -221,7 +228,7 @@ def SeasonSubmitForm(req, abbr): new_season.show = show new_season.save() - return HttpResponseRedirect('/show/%s'%(abbr)) + return HttpResponseRedirect(ctx['showurl']) else: ctx['error'] = 'Invalid fields!' @@ -240,7 +247,8 @@ def EpisodeSubmitForm(req, abbr, season): ctx = { 'form': form, 'season': season, - 'show': show + 'show': show, + 'showurl': get_show_url(abbr) } # Handle POST @@ -261,7 +269,7 @@ def EpisodeSubmitForm(req, abbr, season): new_episode.season = season new_episode.save() - return HttpResponseRedirect('/show/%s'%(abbr)) + return HttpResponseRedirect(ctx['showurl']) else: ctx['error'] = 'Invalid fields!' @@ -275,6 +283,7 @@ class SubmissionVoteSubmit(LoginRequiredMixin, View): pos_bool = int(positive) == 1 user = req.user + showurl = get_show_url(abbr) # Get the submission from the database submission = get_object_or_404(Submission, id=subid) @@ -307,7 +316,7 @@ class SubmissionVoteSubmit(LoginRequiredMixin, View): ) new_vote.save() - return HttpResponseRedirect('/show/%s/episode/%d/%d'%(abbr, submission.episode.season.number, submission.episode.episode)) + return HttpResponseRedirect('%s/episode/%d/%d'%(showurl, submission.episode.season.number, submission.episode.episode)) # Episode form GET and POST @permission_required_or_403('LandingPage.can_create_show_ban', (Show, 'abbr', 'abbr'), accept_global_perms=True) @@ -332,7 +341,8 @@ def BanFromShowForm(req, abbr): ctx = { 'form': form, 'show': show, - 'target': banTarget + 'target': banTarget, + 'showurl': get_show_url(abbr) } # Handle POST @@ -361,7 +371,7 @@ def BanFromShowForm(req, abbr): if 'delete' in req.POST: Submission.objects.filter(episode__show=show,user=banTarget).delete() - return HttpResponseRedirect('/show/%s'%(abbr)) + return HttpResponseRedirect(ctx['showurl']) else: ctx['error'] = 'Invalid fields!' @@ -387,10 +397,11 @@ def ReportSubmission(req, abbr, submission): 'form': form, 'show': show, 'episode': episode, - 'submission': submission + 'submission': submission, + 'showurl': get_show_url(abbr) } - url = '/show/%s/episode/%d/%d?submission=%s'%(abbr, episode.season.number, episode.episode,submission.pk) + url = '%s/episode/%d/%d?submission=%s'%(ctx['showurl'], episode.season.number, episode.episode,submission.pk) # Handle POST if req.method == 'POST': @@ -416,7 +427,7 @@ def ReportSubmission(req, abbr, submission): new_report.url = url new_report.save() - return HttpResponseRedirect('/show/%s/episode/%d/%d'%(abbr, episode.season.number, episode.episode)) + return HttpResponseRedirect('%s/episode/%d/%d'%(ctx['showurl'], episode.season.number, episode.episode)) else: ctx['error'] = 'Invalid fields!'