Add better show url formation method

This commit is contained in:
Evert Prants 2018-03-02 15:46:25 +02:00
parent 028b1ab279
commit e59c03539d
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
21 changed files with 97 additions and 111 deletions

View File

@ -9,8 +9,8 @@
<div class="container mb-5 mt-5"> <div class="container mb-5 mt-5">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{show.name}}</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}/discuss">Discussions</a></li> <li class="breadcrumb-item"><a href="{{show.url}}/discuss">Discussions</a></li>
<li class="breadcrumb-item active" aria-current="page">{{board.title}}</li> <li class="breadcrumb-item active" aria-current="page">{{board.title}}</li>
</ol> </ol>
</nav> </nav>
@ -22,7 +22,7 @@
<p>This board is locked</p> <p>This board is locked</p>
{% else %} {% else %}
{% if user.is_authenticated %} {% if user.is_authenticated %}
<a href="{{showurl}}/discuss/board/reply/{{board.pk}}" class="btn btn-primary"><i class="fa fa-fw fa-pencil"></i>&nbsp;Reply</a> <a href="{{show.url}}/discuss/board/reply/{{board.pk}}" class="btn btn-primary"><i class="fa fa-fw fa-pencil"></i>&nbsp;Reply</a>
{% else %} {% else %}
<p><a href="/login">Log in</a> to reply</p> <p><a href="/login">Log in</a> to reply</p>
{% endif %} {% endif %}
@ -38,8 +38,8 @@
<span class="font-weight-light text-muted">ID: {{reply.pk}}</span> <span class="font-weight-light text-muted">ID: {{reply.pk}}</span>
{% if "can_moderate_board" in show_perms or board.user == user %} {% 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> <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="{{show.url}}/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> <a href="{{show.url}}/create_ban?user={{reply.user.username}}" class="btn btn-warning ml-1">Ban</a>
{% endif %} {% endif %}
<div class="w-100 mb-4"></div> <div class="w-100 mb-4"></div>
{% else %} {% else %}
@ -54,20 +54,20 @@
<div class="actions d-flex flex-row-reverse"> <div class="actions d-flex flex-row-reverse">
{% if user.is_authenticated %} {% if user.is_authenticated %}
{% if "can_moderate_board" in show_perms or board.user == user %} {% if "can_moderate_board" in show_perms or board.user == user %}
<a href="{{showurl}}/discuss/board/delete/reply/{{reply.id}}" class="btn btn-warning ml-1">Delete Content</a> <a href="{{show.url}}/discuss/board/delete/reply/{{reply.id}}" class="btn btn-warning ml-1">Delete Content</a>
<a href="{{showurl}}/create_ban?user={{reply.user.username}}" class="btn btn-warning ml-1">Ban</a> <a href="{{show.url}}/create_ban?user={{reply.user.username}}" class="btn btn-warning ml-1">Ban</a>
{% else %} {% else %}
<a href="{{showurl}}/discuss/board/report/{{reply.id}}" class="btn btn-secondary ml-1" title="Report" aria-label="Report"><i class="fa fa-fw fa-flag"></i></a> <a href="{{show.url}}/discuss/board/report/{{reply.id}}" class="btn btn-secondary ml-1" title="Report" aria-label="Report"><i class="fa fa-fw fa-flag"></i></a>
{% endif %} {% endif %}
{% endif %} {% endif %}
<div class="vote-btns"> <div class="vote-btns">
<form method="POST" class="d-inline" action="{{showurl}}/discuss/vote/{{reply.id}}/1"> <form method="POST" class="d-inline" action="{{show.url}}/discuss/vote/{{reply.id}}/1">
{% csrf_token %} {% csrf_token %}
<button href="#" class="btn btn-link text-success"> <button href="#" class="btn btn-link text-success">
<i class="fa fa-fw fa-thumbs-up"></i>&nbsp;{{reply.positives}} <i class="fa fa-fw fa-thumbs-up"></i>&nbsp;{{reply.positives}}
</button> </button>
</form> </form>
<form method="POST" class="d-inline" action="{{showurl}}/discuss/vote/{{reply.id}}/0"> <form method="POST" class="d-inline" action="{{show.url}}/discuss/vote/{{reply.id}}/0">
{% csrf_token %} {% csrf_token %}
<button href="#" class="btn btn-link text-danger"> <button href="#" class="btn btn-link text-danger">
<i class="fa fa-fw fa-thumbs-down"></i>&nbsp;{{reply.negatives}} <i class="fa fa-fw fa-thumbs-down"></i>&nbsp;{{reply.negatives}}
@ -121,7 +121,7 @@
{% if user.is_authenticated and not board.locked %} {% if user.is_authenticated and not board.locked %}
<h2>Quick Reply</h2> <h2>Quick Reply</h2>
<div class="reply-box"> <div class="reply-box">
<form class="form-horizontal" role="form" action="{{showurl}}/discuss/board/reply/{{board.pk}}" method="post"> <form class="form-horizontal" role="form" action="{{show.url}}/discuss/board/reply/{{board.pk}}" method="post">
{% include "form.html" %} {% include "form.html" %}
<div class="form-group"> <div class="form-group">
<button type="submit" class="btn btn-primary">Reply</button> <button type="submit" class="btn btn-primary">Reply</button>
@ -136,14 +136,14 @@
<h4>Board Tools</h4> <h4>Board Tools</h4>
<ul> <ul>
{% if not board.locked %} {% if not board.locked %}
<li><a href="{{showurl}}/discuss/board/reply/{{board.pk}}">Reply to the board</a></li> <li><a href="{{show.url}}/discuss/board/reply/{{board.pk}}">Reply to the board</a></li>
{% endif %} {% endif %}
{% if "can_moderate_board" in show_perms or board.user == user and not board.locked %} {% if "can_moderate_board" in show_perms or board.user == user and not board.locked %}
<li><a href="{{showurl}}/discuss/board/lock/{{board.pk}}">Lock the board from further replies</a></li> <li><a href="{{show.url}}/discuss/board/lock/{{board.pk}}">Lock the board from further replies</a></li>
{% endif %} {% endif %}
{% if "can_moderate_board" in show_perms %} {% if "can_moderate_board" in show_perms %}
<li><a href="{{showurl}}/discuss/board/pin/{{board.pk}}">{% if board.pinned %}Unpin the board{% else %}Pin the board at the top{% endif %}</a></li> <li><a href="{{show.url}}/discuss/board/pin/{{board.pk}}">{% if board.pinned %}Unpin the board{% else %}Pin the board at the top{% endif %}</a></li>
<li><a href="{{showurl}}/discuss/board/delete/{{board.pk}}">Delete the board</a></li> <li><a href="{{show.url}}/discuss/board/delete/{{board.pk}}">Delete the board</a></li>
{% endif %} {% endif %}
</ul> </ul>
{% endif %} {% endif %}

View File

@ -6,9 +6,9 @@
<section class="container mt-5 mb-5"> <section class="container mt-5 mb-5">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{show.name}}</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}/discuss">Discussions</a></li> <li class="breadcrumb-item"><a href="{{show.url}}/discuss">Discussions</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}/discuss/board/{{board.pk}}-{{board.title|slugify}}">{{board.title}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}/discuss/board/{{board.pk}}-{{board.title|slugify}}">{{board.title}}</a></li>
<li class="breadcrumb-item active" aria-current="page">Reply</li> <li class="breadcrumb-item active" aria-current="page">Reply</li>
</ol> </ol>
</nav> </nav>

View File

@ -6,7 +6,7 @@
<div class="container mb-5 mt-5"> <div class="container mb-5 mt-5">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{show.name}}</a></li>
<li class="breadcrumb-item active" aria-current="page">Discussions</li> <li class="breadcrumb-item active" aria-current="page">Discussions</li>
</ol> </ol>
</nav> </nav>
@ -14,7 +14,7 @@
<p>Discuss {{show.name}} with your fellow community members!</p> <p>Discuss {{show.name}} with your fellow community members!</p>
<div class="d-flex flex-row-reverse mb-4"> <div class="d-flex flex-row-reverse mb-4">
{% if user.is_authenticated %} {% if user.is_authenticated %}
<a href="{{showurl}}/discuss/board/new" class="btn btn-primary"><i class="fa fa-fw fa-pencil"></i>&nbsp;Create New Board</a> <a href="{{show.url}}/discuss/board/new" class="btn btn-primary"><i class="fa fa-fw fa-pencil"></i>&nbsp;Create New Board</a>
{% else %} {% else %}
<p><a href="/login">Log in</a> to create boards</p> <p><a href="/login">Log in</a> to create boards</p>
{% endif %} {% endif %}
@ -27,7 +27,7 @@
<div class="board border-bottom"> <div class="board border-bottom">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h2><a href="{{showurl}}/discuss/board/{{board.pk}}-{{board.title|slugify}}">{% if board.locked %}<i class="fa fa-fw fa-lock"></i>{% endif %}{% if board.pinned %}<i class="fa fa-fw fa-thumb-tack"></i>{% endif %}{{board.title}}</a></h2> <h2><a href="{{show.url}}/discuss/board/{{board.pk}}-{{board.title|slugify}}">{% if board.locked %}<i class="fa fa-fw fa-lock"></i>{% endif %}{% if board.pinned %}<i class="fa fa-fw fa-thumb-tack"></i>{% endif %}{{board.title}}</a></h2>
<span class="text-muted font-weight-light">Submitted {{board.timestamp}} by <span class="text-muted font-weight-light">Submitted {{board.timestamp}} by
{% if board.user.is_staff %} {% if board.user.is_staff %}
<span class="mod"><i class="fa fa-fw fa-shield"></i></span> <span class="mod"><i class="fa fa-fw fa-shield"></i></span>

View File

@ -6,8 +6,8 @@
<section class="container mt-5 mb-5"> <section class="container mt-5 mb-5">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{show.name}}</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}/discuss">Discussions</a></li> <li class="breadcrumb-item"><a href="{{show.url}}/discuss">Discussions</a></li>
<li class="breadcrumb-item active" aria-current="page">New Board</li> <li class="breadcrumb-item active" aria-current="page">New Board</li>
</ol> </ol>
</nav> </nav>

View File

@ -6,9 +6,9 @@
<section class="container mb-5 mt-5"> <section class="container mb-5 mt-5">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{show.name}}</a></li>
<li class="breadcrumb-item"><a href="{{discuss}}">Discussions</a></li> <li class="breadcrumb-item"><a href="{{show.url}}/discuss">Discussions</a></li>
<li class="breadcrumb-item"><a href="{{discuss}}/board/{{reply.board.pk}}-{{reply.board.title|slugify}}">{{reply.board.title}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}/discuss/board/{{reply.board.pk}}-{{reply.board.title|slugify}}">{{reply.board.title}}</a></li>
<li class="breadcrumb-item active" aria-current="page">Report</li> <li class="breadcrumb-item active" aria-current="page">Report</li>
</ol> </ol>
</nav> </nav>

View File

@ -29,7 +29,6 @@ from django.utils.text import slugify
from guardian.decorators import permission_required_or_403 from guardian.decorators import permission_required_or_403
from LandingPage.models import Show, DiscussionBoard, DiscussionReply, DiscussionVote, Ban, Report from LandingPage.models import Show, DiscussionBoard, DiscussionReply, DiscussionVote, Ban, Report
from LandingPage.views import get_show_url
from . import forms from . import forms
import datetime import datetime
@ -41,7 +40,6 @@ class Boards(TemplateView):
def get_context_data(self, abbr, **kwargs): def get_context_data(self, abbr, **kwargs):
ctx = super().get_context_data() ctx = super().get_context_data()
ctx['showurl'] = get_show_url(abbr)
show = get_object_or_404(Show, abbr=abbr) show = get_object_or_404(Show, abbr=abbr)
@ -80,8 +78,6 @@ class Board(TemplateView):
def get_context_data(self, abbr, bid, **kwargs): def get_context_data(self, abbr, bid, **kwargs):
ctx = super().get_context_data() ctx = super().get_context_data()
ctx['showurl'] = get_show_url(abbr)
show = get_object_or_404(Show, abbr=abbr) show = get_object_or_404(Show, abbr=abbr)
board = get_object_or_404(DiscussionBoard, pk=bid) board = get_object_or_404(DiscussionBoard, pk=bid)
@ -109,7 +105,7 @@ class Board(TemplateView):
found = DiscussionReply.objects.filter(timestamp__lt=item.timestamp,board=board).count() found = DiscussionReply.objects.filter(timestamp__lt=item.timestamp,board=board).count()
page = int(found / perpage) + 1 page = int(found / perpage) + 1
index = int(found % perpage) + 1 index = int(found % perpage) + 1
ctx['url'] = ctx['showurl'] + '/discuss/board/%d-%s?page=%d#reply-%d'%(board.pk, slugify(board.title), page, index) ctx['url'] = show.url() + '/discuss/board/%d-%s?page=%d#reply-%d'%(board.pk, slugify(board.title), page, index)
return ctx return ctx
@ -181,7 +177,7 @@ def BoardForm(req, abbr):
new_post = DiscussionReply(user=user,board=new_board,body=form_data['body']) new_post = DiscussionReply(user=user,board=new_board,body=form_data['body'])
new_post.save() new_post.save()
return HttpResponseRedirect(ctx['showurl'] + '/discuss/board/%d-%s'%(new_board.pk, slugify(form_data['title']))) return HttpResponseRedirect(show.url() + '/discuss/board/%d-%s'%(new_board.pk, slugify(form_data['title'])))
else: else:
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'
@ -200,8 +196,7 @@ def BoardReplyForm(req, abbr, bid):
ctx = { ctx = {
'form': form, 'form': form,
'board': board, 'board': board,
'show': show, 'show': show
'showurl': get_show_url(abbr)
} }
# Get bans for this user regarding this show # Get bans for this user regarding this show
@ -240,7 +235,7 @@ def BoardReplyForm(req, abbr, bid):
new_reply.board = board new_reply.board = board
new_reply.save() new_reply.save()
return HttpResponseRedirect(ctx['showurl'] + '/discuss/board/%d-%s?findReply=%d'%(board.pk, slugify(board.title), new_reply.pk)) return HttpResponseRedirect(show.url() + '/discuss/board/%d-%s?findReply=%d'%(board.pk, slugify(board.title), new_reply.pk))
else: else:
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'
@ -254,10 +249,10 @@ class BoardVoteSubmit(LoginRequiredMixin, View):
pos_bool = int(positive) == 1 pos_bool = int(positive) == 1
user = req.user user = req.user
showurl = get_show_url(abbr)
# Get the reply from the database # Get the reply from the database
reply = get_object_or_404(DiscussionReply, id=replyid) reply = get_object_or_404(DiscussionReply, id=replyid)
showurl = reply.board.show.url()
# Prevent voting for own reply # Prevent voting for own reply
if reply.user == user: if reply.user == user:
@ -309,11 +304,10 @@ def ReportForm(req, abbr, rid):
ctx = { ctx = {
'form': form, 'form': form,
'show': show, 'show': show,
'reply': reply, 'reply': reply
'showurl': get_show_url(abbr)
} }
url = '%s/discuss/board/%d-%s?findReply=%d'%(ctx['showurl'], reply.board.pk, slugify(reply.board.title), reply.pk) url = '%s/discuss/board/%d-%s?findReply=%d'%(show.url(), reply.board.pk, slugify(reply.board.title), reply.pk)
# Handle POST # Handle POST
if req.method == 'POST': if req.method == 'POST':
@ -339,7 +333,7 @@ def ReportForm(req, abbr, rid):
new_report.url = url new_report.url = url
new_report.save() new_report.save()
return HttpResponseRedirect('%s/discuss/board/%d-%s'%(ctx['showurl'], reply.board.pk, slugify(reply.board.title))) return HttpResponseRedirect('%s/discuss/board/%d-%s'%(show.url(), reply.board.pk, slugify(reply.board.title)))
else: else:
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'
@ -349,27 +343,25 @@ def ReportForm(req, abbr, rid):
def BoardLock(req, abbr, bid): def BoardLock(req, abbr, bid):
user = req.user user = req.user
board = get_object_or_404(DiscussionBoard, pk=bid) board = get_object_or_404(DiscussionBoard, pk=bid)
showurl = get_show_url(abbr)
if not user.has_perm('LandingPage.can_moderate_board', board.show) and not board.user == user: if not user.has_perm('LandingPage.can_moderate_board', board.show) and not board.user == user:
return HttpResponse('<h1>Error</h1><p>You do not have permission to lock this show.</p><p>' return HttpResponse('<h1>Error</h1><p>You do not have permission to lock this show.</p><p>'
'<a href="%s/discuss/board/%d-%s">Return to board</a></p>' '<a href="%s/discuss/board/%d-%s">Return to board</a></p>'
% (showurl, board.pk, slugify(board.title)), status=400) % (board.show.url(), board.pk, slugify(board.title)), status=400)
lock = not board.locked lock = not board.locked
DiscussionBoard.objects.filter(pk=board.pk).update(locked=lock) DiscussionBoard.objects.filter(pk=board.pk).update(locked=lock)
return HttpResponseRedirect('%s/discuss/board/%d-%s'%(showurl, board.pk, slugify(board.title))) return HttpResponseRedirect('%s/discuss/board/%d-%s'%(board.show.url(), board.pk, slugify(board.title)))
@permission_required_or_403('LandingPage.can_moderate_board', (Show, 'abbr', 'abbr'), accept_global_perms=True) @permission_required_or_403('LandingPage.can_moderate_board', (Show, 'abbr', 'abbr'), accept_global_perms=True)
def BoardPin(req, abbr, bid): def BoardPin(req, abbr, bid):
board = get_object_or_404(DiscussionBoard, pk=bid) board = get_object_or_404(DiscussionBoard, pk=bid)
showurl = get_show_url(abbr)
pin = not board.pinned pin = not board.pinned
DiscussionBoard.objects.filter(pk=board.pk).update(pinned=pin) DiscussionBoard.objects.filter(pk=board.pk).update(pinned=pin)
return HttpResponseRedirect('%s/discuss/board/%d-%s'%(showurl, board.pk, slugify(board.title))) return HttpResponseRedirect('%s/discuss/board/%d-%s'%(board.show.url(), board.pk, slugify(board.title)))
@permission_required_or_403('LandingPage.can_moderate_board', (Show, 'abbr', 'abbr'), accept_global_perms=True) @permission_required_or_403('LandingPage.can_moderate_board', (Show, 'abbr', 'abbr'), accept_global_perms=True)
def BoardDelete(req, abbr, bid): def BoardDelete(req, abbr, bid):
@ -378,15 +370,14 @@ def BoardDelete(req, abbr, bid):
DiscussionBoard.objects.filter(pk=board.pk).delete() DiscussionBoard.objects.filter(pk=board.pk).delete()
return HttpResponseRedirect('%s/discuss' % (showurl)) return HttpResponseRedirect('%s/discuss' % (board.show.url()))
@permission_required_or_403('LandingPage.can_moderate_board', (Show, 'abbr', 'abbr'), accept_global_perms=True) @permission_required_or_403('LandingPage.can_moderate_board', (Show, 'abbr', 'abbr'), accept_global_perms=True)
def BoardDeleteReply(req, abbr, rid): def BoardDeleteReply(req, abbr, rid):
reply = get_object_or_404(DiscussionReply, pk=rid) reply = get_object_or_404(DiscussionReply, pk=rid)
showurl = get_show_url(abbr)
delete = not reply.deleted delete = not reply.deleted
DiscussionReply.objects.filter(pk=reply.pk).update(deleted=delete) DiscussionReply.objects.filter(pk=reply.pk).update(deleted=delete)
return HttpResponseRedirect('%s/discuss/board/%d-%s'%(showurl, reply.board.pk, slugify(reply.board.title))) return HttpResponseRedirect('%s/discuss/board/%d-%s'%(reply.show.url(), reply.board.pk, slugify(reply.board.title)))

View File

@ -176,7 +176,7 @@ DISCUSSIONS_PER_PAGE = 26
DISCUSSIONS_REPLIES_PER_PAGE = 10 DISCUSSIONS_REPLIES_PER_PAGE = 10
# Domain of this app # Domain of this app
DOMAIN='localhost' DOMAIN=options.get('domain')
# Use subdomains for each show # Use subdomains for each show
DOMAIN_SUBDOMAIN_SHOWS=False DOMAIN_SUBDOMAIN_SHOWS=options.get('use_subdomain_paths') == 'true'

View File

@ -15,6 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from django.db import models from django.db import models
from django.conf import settings
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.core.files.storage import FileSystemStorage from django.core.files.storage import FileSystemStorage
from django.conf import settings from django.conf import settings
@ -95,6 +96,15 @@ class Show(TimestampedModel):
('can_moderate_board', 'Can delete and edit boards and replies of this show'), ('can_moderate_board', 'Can delete and edit boards and replies of this show'),
) )
def url(self):
use_sdms = getattr(settings, "DOMAIN_SUBDOMAIN_SHOWS", False)
domain = getattr(settings, "DOMAIN", 'localhost')
if use_sdms:
return domain.format(sub=self.abbr + '.',path='')
return '/show/%s' % (self.abbr)
def __str__(self): def __str__(self):
return '%s [%s]'%(self.name,self.abbr) return '%s [%s]'%(self.name,self.abbr)
@ -253,7 +263,7 @@ class Season(models.Model):
help_text="The artwork associated with the season. Should display the name of the show in a movie-poster esque format. Aspect ration should be about 2:3", help_text="The artwork associated with the season. Should display the name of the show in a movie-poster esque format. Aspect ration should be about 2:3",
verbose_name="Artwork", verbose_name="Artwork",
blank=True blank=True
) )
def __str__(self): def __str__(self):
return self.show.name + " S%d"%self.number return self.show.name + " S%d"%self.number

View File

@ -16,7 +16,7 @@
{% if not recent %} Nothing to show {% endif %} {% if not recent %} Nothing to show {% endif %}
<div class="text-center"> <div class="text-center">
{% for show in recent %} {% for show in recent %}
<a class="show-promo" href="/show/{{show.abbr}}"> <a class="show-promo" href="{{show.url}}">
<img class="artwork" src="/media/uploaded_resources/{{show.artwork}}"> <img class="artwork" src="/media/uploaded_resources/{{show.artwork}}">
<span>{{show.name}}</span> <span>{{show.name}}</span>
</a> </a>

View File

@ -5,7 +5,7 @@
<div class="row"> <div class="row">
{% for show in shows %} {% for show in shows %}
<div class="col"> <div class="col">
<a href="/show/{{show.abbr}}">{{show.name}}</a> <a href="{{show.url}}">{{show.name}}</a>
</div> </div>
{% if forloop.counter|divisibleby:3 %} {% if forloop.counter|divisibleby:3 %}
<div class="w-100"></div> <div class="w-100"></div>

View File

@ -21,7 +21,7 @@ from django.contrib.auth import login as auth_login, authenticate
from django.conf import settings from django.conf import settings
from django.http import HttpResponse from django.http import HttpResponse
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.db.models import Max from django.db.models import Max, F
from django.contrib.auth.views import logout from django.contrib.auth.views import logout
import requests import requests
import hashlib import hashlib
@ -31,16 +31,6 @@ from .models import Show
from .models import Submission from .models import Submission
from .models import DiscussionBoard 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 # Redirect url should point to this view
class LoginRedirect(View): class LoginRedirect(View):
def get(self, req): def get(self, req):

View File

@ -7,7 +7,7 @@
<section class="container mt-2 mb-5"> <section class="container mt-2 mb-5">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{show.name}}</a></li>
<li class="breadcrumb-item active" aria-current="page">New Season</li> <li class="breadcrumb-item active" aria-current="page">New Season</li>
</ol> </ol>
</nav> </nav>

View File

@ -46,7 +46,7 @@
<section class="container mb-5 mt-2"> <section class="container mb-5 mt-2">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{show.name}}</a></li>
<li class="breadcrumb-item active" aria-current="page">{{episode.name}}</li> <li class="breadcrumb-item active" aria-current="page">{{episode.name}}</li>
</ol> </ol>
</nav> </nav>
@ -73,13 +73,13 @@
</div> </div>
<div class="col-md-2 text-md-right"> <div class="col-md-2 text-md-right">
<div class="vote-btns" data-vote-id="{{sbm.id}}"> <div class="vote-btns" data-vote-id="{{sbm.id}}">
<form method="POST" class="d-inline" action="{{showurl}}/vote/{{sbm.id}}/1"> <form method="POST" class="d-inline" action="{{show.url}}/vote/{{sbm.id}}/1">
{% csrf_token %} {% csrf_token %}
<button class="btn btn-success"> <button class="btn btn-success">
<i class="fa fa-fw fa-thumbs-up"></i>&nbsp;{{sbm.positives}} <i class="fa fa-fw fa-thumbs-up"></i>&nbsp;{{sbm.positives}}
</button> </button>
</form> </form>
<form method="POST" class="d-inline" action="{{showurl}}/vote/{{sbm.id}}/0"> <form method="POST" class="d-inline" action="{{show.url}}/vote/{{sbm.id}}/0">
{% csrf_token %} {% csrf_token %}
<button class="btn btn-danger"> <button class="btn btn-danger">
<i class="fa fa-fw fa-thumbs-down"></i>&nbsp;{{sbm.negatives}} <i class="fa fa-fw fa-thumbs-down"></i>&nbsp;{{sbm.negatives}}
@ -98,9 +98,9 @@
</span> </span>
<span class="divider">&middot;</span> <span class="divider">&middot;</span>
{% if "can_moderate_show" in show_perms %} {% if "can_moderate_show" in show_perms %}
<a href="{{showurl}}/submission/{{sbm.id}}/moderate" class="button modbutton"><i class="fa fa-fw fa-shield"></i>&nbsp;Change</a> <a href="{{show.url}}/submission/{{sbm.id}}/moderate" class="button modbutton"><i class="fa fa-fw fa-shield"></i>&nbsp;Change</a>
{% else %} {% else %}
<a href="{{showurl}}/submission/{{sbm.id}}/report" class="report">Report Invalid or Spam</a> <a href="{{show.url}}/submission/{{sbm.id}}/report" class="report">Report Invalid or Spam</a>
{% endif %} {% endif %}
</div> </div>
</div> </div>
@ -111,19 +111,19 @@
<div class="d-flex flex-row-reverse mt-4"> <div class="d-flex flex-row-reverse mt-4">
{% if user.is_authenticated %} {% if user.is_authenticated %}
{% if "can_moderate_show" in show_perms %} {% if "can_moderate_show" in show_perms %}
<a href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="btn btn-warning"><i class="fa fa-fw fa-plus"></i>&nbsp;Add New Link</a> <a href="{{show.url}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="btn btn-warning"><i class="fa fa-fw fa-plus"></i>&nbsp;Add New Link</a>
{% else %} {% else %}
<a href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="btn btn-primary"><i class="fa fa-fw fa-plus"></i>&nbsp;Submit New Link</a> <a href="{{show.url}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="btn btn-primary"><i class="fa fa-fw fa-plus"></i>&nbsp;Submit New Link</a>
{% endif %} {% endif %}
{% else %} {% else %}
<span class="fillertext"><a href="/login">Log in</a> to submit a link</span> <span class="fillertext"><a href="/login">Log in</a> to submit a link</span>
{% endif %} {% endif %}
</div> </div>
<p>Discuss <q>{{episode.name}}</q> on the <a href="{{showurl}}/discuss">discussion boards</a>!</p> <p>Discuss <q>{{episode.name}}</q> on the <a href="{{show.url}}/discuss">discussion boards</a>!</p>
<ul class="nav fixed-bottom d-flex justify-content-center border-top bg-light"> <ul class="nav fixed-bottom d-flex justify-content-center border-top bg-light">
{% if has_previous %} {% if has_previous %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode|add:'-1'}}">Previous Episode</a> <a class="nav-link" href="{{show.url}}/episode/{{episode.season.number}}/{{episode.episode|add:'-1'}}">Previous Episode</a>
</li> </li>
{% else %} {% else %}
<li class="nav-item"> <li class="nav-item">
@ -132,7 +132,7 @@
{% endif %} {% endif %}
{% if has_next %} {% if has_next %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{showurl}}/episode/{{episode.season.number}}/{{episode.episode|add:'1'}}">Next Episode</a> <a class="nav-link" href="{{show.url}}/episode/{{episode.season.number}}/{{episode.episode|add:'1'}}">Next Episode</a>
</li> </li>
{% else %} {% else %}
<li class="nav-item"> <li class="nav-item">

View File

@ -33,7 +33,7 @@
<section class="container mt-2 mb-5"> <section class="container mt-2 mb-5">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{show.name}}</a></li>
<li class="breadcrumb-item active" aria-current="page">New Episode</li> <li class="breadcrumb-item active" aria-current="page">New Episode</li>
</ol> </ol>
</nav> </nav>

View File

@ -33,8 +33,8 @@
<section class="container mb-4 mt-2"> <section class="container mb-4 mt-2">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{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"><a href="{{show.url}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}">{{episode.name}}</a></li>
<li class="breadcrumb-item active" aria-current="page">Report</li> <li class="breadcrumb-item active" aria-current="page">Report</li>
</ol> </ol>
</nav> </nav>

View File

@ -7,7 +7,7 @@
<section class="container mt-5 mb-5"> <section class="container mt-5 mb-5">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{show.name}}</a></li>
<li class="breadcrumb-item active" aria-current="page">New Season</li> <li class="breadcrumb-item active" aria-current="page">New Season</li>
</ol> </ol>
</nav> </nav>

View File

@ -42,14 +42,14 @@
</div> </div>
{% if "can_moderate_show" in show_perms %} {% if "can_moderate_show" in show_perms %}
<div class="col-md-1 text-md-right"> <div class="col-md-1 text-md-right">
<a href="{{showurl}}/season/{{season.number}}/append" class="action"><i class="fa fa-fw fa-plus"></i></a> <a href="{{show.url}}/season/{{season.number}}/append" class="action"><i class="fa fa-fw fa-plus"></i></a>
</div> </div>
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}
{% if "can_moderate_show" in show_perms %} {% if "can_moderate_show" in show_perms %}
<div class="d-flex flex-row-reverse"> <div class="d-flex flex-row-reverse">
<a href="{{showurl}}/season/new" class="btn btn-warning"><i class="fa fa-fw fa-plus"></i>&nbsp;Add a Season</a> <a href="{{show.url}}/season/new" class="btn btn-warning"><i class="fa fa-fw fa-plus"></i>&nbsp;Add a Season</a>
</div> </div>
{% endif %} {% endif %}
</section> </section>

View File

@ -33,8 +33,8 @@
<section class="container mt-5 mb-5"> <section class="container mt-5 mb-5">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{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"><a href="{{show.url}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}">{{episode.name}}</a></li>
<li class="breadcrumb-item active" aria-current="page">Submit</li> <li class="breadcrumb-item active" aria-current="page">Submit</li>
</ol> </ol>
</nav> </nav>

View File

@ -35,8 +35,8 @@
{% get_obj_perms request.user for show as "show_perms" %} {% get_obj_perms request.user for show as "show_perms" %}
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li> <li class="breadcrumb-item"><a href="{{show.url}}">{{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"><a href="{{show.url}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}">{{episode.name}}</a></li>
<li class="breadcrumb-item active" aria-current="page">Edit Submission</li> <li class="breadcrumb-item active" aria-current="page">Edit Submission</li>
</ol> </ol>
</nav> </nav>

View File

@ -27,7 +27,6 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from guardian.decorators import permission_required_or_403 from guardian.decorators import permission_required_or_403
from LandingPage.models import User, Show, Season, Episode, Submission, SubmissionVote, Ban, Report from LandingPage.models import User, Show, Season, Episode, Submission, SubmissionVote, Ban, Report
from LandingPage.views import get_show_url
from . import forms from . import forms
@ -51,7 +50,6 @@ class IndexView(TemplateView):
# Add fields to context # Add fields to context
ctx['show'] = show ctx['show'] = show
ctx['seasons'] = seasons ctx['seasons'] = seasons
ctx['showurl'] = get_show_url(abbr)
return ctx return ctx
@ -61,7 +59,6 @@ class EpisodeView(TemplateView):
def get_context_data(self, abbr, season, episode, **kwargs): def get_context_data(self, abbr, season, episode, **kwargs):
ctx = super().get_context_data() ctx = super().get_context_data()
ctx['showurl'] = get_show_url(abbr)
highlight = self.request.GET.get('submission', None) highlight = self.request.GET.get('submission', None)
if not highlight == None: if not highlight == None:
@ -88,11 +85,11 @@ class EpisodeView(TemplateView):
raise Http404('No Episode matches the given query.') raise Http404('No Episode matches the given query.')
episode_number = int(epobj.episode) episode_number = int(epobj.episode)
ctx['url'] = '%s/episode/%d/%d'%(ctx['showurl'], season_number, episode_number) ctx['url'] = '%s/episode/%d/%d'%(show.url(), season_number, episode_number)
elif episode_number > int(lastep.episode): elif episode_number > int(lastep.episode):
season_number += 1 season_number += 1
episode_number = 1 episode_number = 1
ctx['url'] = '%s/episode/%d/%d'%(ctx['showurl'], season_number, episode_number) ctx['url'] = '%s/episode/%d/%d'%(show.url(), season_number, episode_number)
if 'url' in ctx: if 'url' in ctx:
return ctx return ctx
@ -132,11 +129,10 @@ class EpisodeView(TemplateView):
def EpisodeFindSubmission(req, abbr, submission): def EpisodeFindSubmission(req, abbr, submission):
show = get_object_or_404(Show, abbr=abbr) show = get_object_or_404(Show, abbr=abbr)
submission = int(submission) submission = int(submission)
showurl = get_show_url(abbr)
episode = get_object_or_404(Episode, submissions__id=submission) episode = get_object_or_404(Episode, submissions__id=submission)
return HttpResponseRedirect('%s/episode/%d/%d?submission=%d'%(showurl, episode.season.number, episode.episode, submission)) return HttpResponseRedirect('%s/episode/%d/%d?submission=%d'%(show.url(), episode.season.number, episode.episode, submission))
# Submission form GET and POST # Submission form GET and POST
@login_required @login_required
@ -151,8 +147,7 @@ def SubmissionForm(req, abbr, season, episode):
ctx = { ctx = {
'form': form, 'form': form,
'show': show, 'show': show,
'episode': episode, 'episode': episode
'showurl': get_show_url(abbr)
} }
# Get bans for this user regarding this show # Get bans for this user regarding this show
@ -185,7 +180,7 @@ def SubmissionForm(req, abbr, season, episode):
new_submission.episode = episode new_submission.episode = episode
new_submission.save() new_submission.save()
return HttpResponseRedirect('%s/episode/%d/%d'%(ctx['showurl'], episode.season.number, episode.episode)) return HttpResponseRedirect('%s/episode/%d/%d'%(show.url(), episode.season.number, episode.episode))
else: else:
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'
@ -205,19 +200,18 @@ def SubmissionModForm(req, abbr, submission):
ctx = { ctx = {
'form': form, 'form': form,
'show': show, 'show': show,
'episode': episode, 'episode': episode
'showurl': get_show_url(abbr)
} }
# Handle POST # Handle POST
if req.method == 'POST': if req.method == 'POST':
if 'delete' in req.POST: if 'delete' in req.POST:
submission.delete() submission.delete()
return HttpResponseRedirect('%s/episode/%d/%d'%(ctx['showurl'], episode.season.number, episode.episode)) return HttpResponseRedirect('%s/episode/%d/%d'%(show.url(), episode.season.number, episode.episode))
if 'delete_ban' in req.POST: if 'delete_ban' in req.POST:
submission.delete() submission.delete()
return HttpResponseRedirect('%s/create_ban?user=%s'%(ctx['showurl'],submission.user.username)) return HttpResponseRedirect('%s/create_ban?user=%s'%(show.url(),submission.user.username))
form = forms.SubmissionFormAdmin(req.POST, instance=submission) form = forms.SubmissionFormAdmin(req.POST, instance=submission)
ctx['form'] = form ctx['form'] = form
@ -226,7 +220,7 @@ def SubmissionModForm(req, abbr, submission):
form_data = form.cleaned_data form_data = form.cleaned_data
form.save() form.save()
return HttpResponseRedirect('%s/episode/%d/%d'%(ctx['showurl'], episode.season.number, episode.episode)) return HttpResponseRedirect('%s/episode/%d/%d'%(show.url(), episode.season.number, episode.episode))
else: else:
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'
@ -243,8 +237,7 @@ def SeasonSubmitForm(req, abbr):
# Request context # Request context
ctx = { ctx = {
'form': form, 'form': form,
'show': show, 'show': show
'showurl': get_show_url(abbr)
} }
# Handle POST # Handle POST
@ -264,7 +257,7 @@ def SeasonSubmitForm(req, abbr):
new_season.show = show new_season.show = show
new_season.save() new_season.save()
return HttpResponseRedirect(ctx['showurl']) return HttpResponseRedirect(show.url())
else: else:
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'
@ -283,8 +276,7 @@ def EpisodeSubmitForm(req, abbr, season):
ctx = { ctx = {
'form': form, 'form': form,
'season': season, 'season': season,
'show': show, 'show': show
'showurl': get_show_url(abbr)
} }
# Handle POST # Handle POST
@ -305,7 +297,7 @@ def EpisodeSubmitForm(req, abbr, season):
new_episode.season = season new_episode.season = season
new_episode.save() new_episode.save()
return HttpResponseRedirect(ctx['showurl']) return HttpResponseRedirect(show.url())
else: else:
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'
@ -319,7 +311,6 @@ class SubmissionVoteSubmit(LoginRequiredMixin, View):
pos_bool = int(positive) == 1 pos_bool = int(positive) == 1
user = req.user user = req.user
showurl = get_show_url(abbr)
# Get the submission from the database # Get the submission from the database
submission = get_object_or_404(Submission, id=subid) submission = get_object_or_404(Submission, id=subid)
@ -352,7 +343,7 @@ class SubmissionVoteSubmit(LoginRequiredMixin, View):
) )
new_vote.save() new_vote.save()
return HttpResponseRedirect('%s/episode/%d/%d'%(showurl, submission.episode.season.number, submission.episode.episode)) return HttpResponseRedirect('%s/episode/%d/%d'%(show.url(), submission.episode.season.number, submission.episode.episode))
# Episode form GET and POST # Episode form GET and POST
@permission_required_or_403('LandingPage.can_create_show_ban', (Show, 'abbr', 'abbr'), accept_global_perms=True) @permission_required_or_403('LandingPage.can_create_show_ban', (Show, 'abbr', 'abbr'), accept_global_perms=True)
@ -407,7 +398,7 @@ def BanFromShowForm(req, abbr):
if 'delete' in req.POST: if 'delete' in req.POST:
Submission.objects.filter(episode__show=show,user=banTarget).delete() Submission.objects.filter(episode__show=show,user=banTarget).delete()
return HttpResponseRedirect(ctx['showurl']) return HttpResponseRedirect(show.url())
else: else:
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'
@ -437,7 +428,7 @@ def ReportSubmission(req, abbr, submission):
'showurl': get_show_url(abbr) 'showurl': get_show_url(abbr)
} }
url = '%s/episode/%d/%d?submission=%s'%(ctx['showurl'], episode.season.number, episode.episode,submission.pk) url = '%s/episode/%d/%d?submission=%s'%(show.url(), episode.season.number, episode.episode, submission.pk)
# Handle POST # Handle POST
if req.method == 'POST': if req.method == 'POST':
@ -463,7 +454,7 @@ def ReportSubmission(req, abbr, submission):
new_report.url = url new_report.url = url
new_report.save() new_report.save()
return HttpResponseRedirect('%s/episode/%d/%d'%(ctx['showurl'], episode.season.number, episode.episode)) return HttpResponseRedirect('%s/episode/%d/%d'%(show.url(), episode.season.number, episode.episode))
else: else:
ctx['error'] = 'Invalid fields!' ctx['error'] = 'Invalid fields!'

View File

@ -9,6 +9,10 @@ secret_key=5up3r s3cr3t k3y
#For configuration details #For configuration details
database=sqlite:///database.sqlite3 database=sqlite:///database.sqlite3
#Domain of this website to use in show path manufacturing
domain=http://{sub}localhost:8000{path}
use_subdomain_paths=false
[OAuth] [OAuth]
#The root of the oauth endpoint you are using for oauth settings #The root of the oauth endpoint you are using for oauth settings
token_endpoint=https://icynet.eu/oauth/ token_endpoint=https://icynet.eu/oauth/