Use a function to create show urls instead of having them static
This commit is contained in:
parent
ed720adbc5
commit
adb14fe486
@ -39,6 +39,7 @@
|
||||
{% if "can_moderate_board" in show_perms or board.user == user %}
|
||||
<div class="alert alert-warning"><div class="font-weight-light">{{reply.body}}</div></div>
|
||||
<a href="{{showurl}}/discuss/board/delete/reply/{{reply.id}}" class="btn btn-warning ml-1">Restore</a>
|
||||
<a href="{{showurl}}/create_ban?user={{reply.user.username}}" class="btn btn-warning ml-1">Ban</a>
|
||||
{% endif %}
|
||||
<div class="w-100 mb-4"></div>
|
||||
{% else %}
|
||||
|
@ -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"
|
||||
|
@ -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):
|
||||
|
@ -7,7 +7,7 @@
|
||||
<section class="container mt-2 mb-5">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">New Season</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
@ -46,7 +46,7 @@
|
||||
<section class="container mb-5 mt-2">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">{{episode.name}}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
@ -68,13 +68,13 @@
|
||||
</div>
|
||||
<div class="col-md-2 text-md-right">
|
||||
<div class="vote-btns" data-vote-id="{{sbm.id}}">
|
||||
<form method="POST" class="d-inline" action="/show/{{show.abbr}}/vote/{{sbm.id}}/1">
|
||||
<form method="POST" class="d-inline" action="{{showurl}}/vote/{{sbm.id}}/1">
|
||||
{% csrf_token %}
|
||||
<button class="btn btn-success">
|
||||
<i class="fa fa-fw fa-thumbs-up"></i> {{sbm.positives}}
|
||||
</button>
|
||||
</form>
|
||||
<form method="POST" class="d-inline" action="/show/{{show.abbr}}/vote/{{sbm.id}}/0">
|
||||
<form method="POST" class="d-inline" action="{{showurl}}/vote/{{sbm.id}}/0">
|
||||
{% csrf_token %}
|
||||
<button class="btn btn-danger">
|
||||
<i class="fa fa-fw fa-thumbs-down"></i> {{sbm.negatives}}
|
||||
@ -93,9 +93,9 @@
|
||||
</span>
|
||||
<span class="divider">·</span>
|
||||
{% if "can_moderate_show" in show_perms %}
|
||||
<a href="/show/{{show.abbr}}/submission/{{sbm.id}}/moderate" class="button modbutton"><i class="fa fa-fw fa-shield"></i> Change</a>
|
||||
<a href="{{showurl}}/submission/{{sbm.id}}/moderate" class="button modbutton"><i class="fa fa-fw fa-shield"></i> Change</a>
|
||||
{% else %}
|
||||
<a href="/show/{{show.abbr}}/submission/{{sbm.id}}/report" class="report">Report Invalid or Spam</a>
|
||||
<a href="{{showurl}}/submission/{{sbm.id}}/report" class="report">Report Invalid or Spam</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@ -106,9 +106,9 @@
|
||||
<div class="d-flex flex-row-reverse mt-4">
|
||||
{% if user.is_authenticated %}
|
||||
{% if "can_moderate_show" in show_perms %}
|
||||
<a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="btn btn-warning"><i class="fa fa-fw fa-plus"></i> Add New Link</a>
|
||||
<a href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="btn btn-warning"><i class="fa fa-fw fa-plus"></i> Add New Link</a>
|
||||
{% else %}
|
||||
<a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="btn btn-primary"><i class="fa fa-fw fa-plus"></i> Submit New Link</a>
|
||||
<a href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="btn btn-primary"><i class="fa fa-fw fa-plus"></i> Submit New Link</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<span class="fillertext"><a href="/login">Log in</a> to submit a link</span>
|
||||
|
@ -33,7 +33,7 @@
|
||||
<section class="container mt-2 mb-5">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">New Episode</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
@ -33,8 +33,8 @@
|
||||
<section class="container mb-4 mt-2">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}">{{episode.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}">{{episode.name}}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Report</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<section class="container mt-5 mb-5">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">New Season</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
@ -41,14 +41,14 @@
|
||||
</div>
|
||||
{% if "can_moderate_show" in show_perms %}
|
||||
<div class="col-md-1 text-md-right">
|
||||
<a href="/show/{{show.abbr}}/season/{{season.number}}/append" class="action"><i class="fa fa-fw fa-plus"></i></a>
|
||||
<a href="{{showurl}}/season/{{season.number}}/append" class="action"><i class="fa fa-fw fa-plus"></i></a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% if "can_moderate_show" in show_perms %}
|
||||
<div class="d-flex flex-row-reverse">
|
||||
<a href="/show/{{show.abbr}}/season/new" class="btn btn-warning"><i class="fa fa-fw fa-plus"></i> Add a Season</a>
|
||||
<a href="{{showurl}}/season/new" class="btn btn-warning"><i class="fa fa-fw fa-plus"></i> Add a Season</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
@ -33,8 +33,8 @@
|
||||
<section class="container mt-5 mb-5">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}">{{episode.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}">{{episode.name}}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Submit</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
@ -35,8 +35,8 @@
|
||||
{% get_obj_perms request.user for show as "show_perms" %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}">{{episode.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}">{{episode.name}}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Edit Submission</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
@ -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!'
|
||||
|
||||
|
Reference in New Issue
Block a user