Commit d006598f authored by Evert Prants's avatar Evert Prants

Board moderation tools

parent c3ce46b9
......@@ -3,24 +3,26 @@
{{board.title}} - {{show.name}} Discussions - Episodes.Community
{% endblock %}
{% load markdown %}
{% load guardian_tags %}
{% block content %}
{% get_obj_perms request.user for show as "show_perms" %}
<div class="container mb-5 mt-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}}/discuss">Discussions</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}/discuss">Discussions</a></li>
<li class="breadcrumb-item active" aria-current="page">{{board.title}}</li>
</ol>
</nav>
<div class="row">
<h1 class="col">{{board.title}}</h1>
<h1 class="col">{% 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}}</h1>
<div class="col-2">
<div class="d-flex flex-row-reverse mt-2">
{% if board.locked %}
<p>This board is locked</p>
{% else %}
{% if user.is_authenticated %}
<a href="/show/{{show.abbr}}/discuss/board/reply/{{board.pk}}" class="btn btn-primary"><i class="fa fa-fw fa-pencil"></i>&nbsp;Reply</a>
<a href="{{showurl}}/discuss/board/reply/{{board.pk}}" class="btn btn-primary"><i class="fa fa-fw fa-pencil"></i>&nbsp;Reply</a>
{% else %}
<p><a href="/login">Log in</a> to reply</p>
{% endif %}
......@@ -40,15 +42,15 @@
<p class="timestamp text-muted font-weight-light">Submitted {{board.timestamp}}</p>
<div class="user-content mb-auto">{{reply.body|markdown|safe}}</div>
<div class="actions d-flex flex-row-reverse">
<a href="/show/{{show.abbr}}/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="{{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>
<div class="vote-btns">
<form method="POST" class="d-inline" action="/show/{{show.abbr}}/discuss/vote/{{reply.id}}/1">
<form method="POST" class="d-inline" action="{{showurl}}/discuss/vote/{{reply.id}}/1">
{% csrf_token %}
<button href="#" class="btn btn-link text-success">
<i class="fa fa-fw fa-thumbs-up"></i>&nbsp;{{reply.positives}}
</button>
</form>
<form method="POST" class="d-inline" action="/show/{{show.abbr}}/discuss/vote/{{reply.id}}/0">
<form method="POST" class="d-inline" action="{{showurl}}/discuss/vote/{{reply.id}}/0">
{% csrf_token %}
<button href="#" class="btn btn-link text-danger">
<i class="fa fa-fw fa-thumbs-down"></i>&nbsp;{{reply.negatives}}
......@@ -101,7 +103,7 @@
{% if user.is_authenticated and not board.locked %}
<h2>Quick Reply</h2>
<div class="reply-box">
<form class="form-horizontal" role="form" action="/show/{{show.abbr}}/discuss/board/reply/{{board.pk}}" method="post">
<form class="form-horizontal" role="form" action="{{showurl}}/discuss/board/reply/{{board.pk}}" method="post">
{% include "form.html" %}
<div class="form-group">
<button type="submit" class="btn btn-primary">Reply</button>
......@@ -112,5 +114,20 @@
</form>
</div>
{% endif %}
{% if user.is_authenticated %}
<h4>Board Tools</h4>
<ul>
{% if not board.locked %}
<li><a href="{{showurl}}/discuss/board/reply/{{board.pk}}">Reply to the board</a></li>
{% endif %}
{% 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>
{% endif %}
{% 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="{{showurl}}/discuss/board/delete/{{board.pk}}">Delete the board</a></li>
{% endif %}
</ul>
{% endif %}
</div>
{% endblock %}
......@@ -6,9 +6,9 @@
<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}}/discuss">Discussions</a></li>
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}/discuss/board/{{board.pk}}-{{board.title|slugify}}">{{board.title}}</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}/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 active" aria-current="page">Reply</li>
</ol>
</nav>
......
......@@ -6,7 +6,7 @@
<div class="container mb-5 mt-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">Discussions</li>
</ol>
</nav>
......@@ -14,7 +14,7 @@
<p>Discuss {{show.name}} with your fellow community members!</p>
<div class="d-flex flex-row-reverse mb-4">
{% if user.is_authenticated %}
<a href="/show/{{show.abbr}}/discuss/board/new" class="btn btn-primary"><i class="fa fa-fw fa-pencil"></i>&nbsp;Create New Board</a>
<a href="{{showurl}}/discuss/board/new" class="btn btn-primary"><i class="fa fa-fw fa-pencil"></i>&nbsp;Create New Board</a>
{% else %}
<p><a href="/login">Log in</a> to create boards</p>
{% endif %}
......@@ -27,7 +27,7 @@
<div class="board border-bottom">
<div class="row">
<div class="col">
<h2><a href="/show/{{show.abbr}}/discuss/board/{{board.pk}}-{{board.title|slugify}}">{{board.title}}</a></h2>
<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>
<span class="text-muted font-weight-light">Submitted {{board.timestamp}} by
{% if board.user.is_staff %}
<span class="mod"><i class="fa fa-fw fa-shield"></i></span>
......
......@@ -6,8 +6,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}}/discuss">Discussions</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}">{{show.name}}</a></li>
<li class="breadcrumb-item"><a href="{{showurl}}/discuss">Discussions</a></li>
<li class="breadcrumb-item active" aria-current="page">New Board</li>
</ol>
</nav>
......
......@@ -7,8 +7,8 @@
<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}}/discuss">Discussions</a></li>
<li class="breadcrumb-item"><a href="/show/{{show.abbr}}/discuss/board/{{reply.board.pk}}-{{reply.board.title|slugify}}">{{reply.board.title}}</a></li>
<li class="breadcrumb-item"><a href="{{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 active" aria-current="page">Report</li>
</ol>
</nav>
......
......@@ -23,6 +23,9 @@ urlpatterns = [
url(r'^vote/(?P<replyid>\d+)/(?P<positive>[0-1])/?$', views.BoardVoteSubmit.as_view()),
url(r'^board/new$', views.BoardForm),
url(r'^board/report/(?P<rid>\d{1,4})/?$', views.ReportForm),
url(r'^board/pin/(?P<bid>\d{1,4})/?$', views.BoardPin),
url(r'^board/delete/(?P<bid>\d{1,4})/?$', views.BoardDelete),
url(r'^board/lock/(?P<bid>\d{1,4})/?$', views.BoardLock),
url(r'^board/reply/(?P<bid>\d{1,4})/?$', views.BoardReplyForm),
url(r'^board/(?P<bid>\d{1,4})(-[\w-]+)?/?$', views.Board.as_view()),
]
......
......@@ -34,12 +34,18 @@ 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"
def get_context_data(self, abbr, **kwargs):
ctx = super().get_context_data()
ctx['showurl'] = get_show_url(abbr)
show = get_object_or_404(Show, abbr=abbr)
page = self.request.GET.get('page', 1)
......@@ -56,7 +62,7 @@ class Boards(TemplateView):
then=Max('replies__timestamp')
)
),
).order_by('-recency')
).order_by('-pinned','-recency')
paginator = Paginator(boards_list, getattr(settings, "DISCUSSIONS_PER_PAGE", 26))
try:
......@@ -77,6 +83,8 @@ class Board(TemplateView):
def get_context_data(self, abbr, bid, **kwargs):
ctx = super().get_context_data()
ctx['showurl'] = get_show_url(abbr)
show = get_object_or_404(Show, abbr=abbr)
board = get_object_or_404(DiscussionBoard, pk=bid)
......@@ -104,7 +112,7 @@ class Board(TemplateView):
found = DiscussionReply.objects.filter(timestamp__lt=item.timestamp,board=board).count()
page = int(found / perpage) + 1
index = int(found % perpage) + 1
ctx['url'] = '/show/%s/discuss/board/%d-%s?page=%d#reply-%d'%(abbr, board.pk, slugify(board.title), page, index)
ctx['url'] = ctx['showurl'] + '/discuss/board/%d-%s?page=%d#reply-%d'%(board.pk, slugify(board.title), page, index)
return ctx
......@@ -139,7 +147,8 @@ def BoardForm(req, abbr):
# Request context
ctx = {
'form': form,
'show': show
'show': show,
'showurl': get_show_url(abbr)
}
# Get bans for this user regarding this show
......@@ -175,7 +184,7 @@ def BoardForm(req, abbr):
new_post = DiscussionReply(user=user,board=new_board,body=form_data['body'])
new_post.save()
return HttpResponseRedirect('/show/%s/discuss/board/%d-%s'%(abbr, new_board.pk, slugify(form_data['title'])))
return HttpResponseRedirect(ctx['showurl'] + '/discuss/board/%d-%s'%(new_board.pk, slugify(form_data['title'])))
else:
ctx['error'] = 'Invalid fields!'
......@@ -194,7 +203,8 @@ def BoardReplyForm(req, abbr, bid):
ctx = {
'form': form,
'board': board,
'show': show
'show': show,
'showurl': get_show_url(abbr)
}
# Get bans for this user regarding this show
......@@ -233,7 +243,7 @@ def BoardReplyForm(req, abbr, bid):
new_reply.board = board
new_reply.save()
return HttpResponseRedirect('/show/%s/discuss/board/%d-%s?findReply=%d'%(abbr, board.pk, slugify(board.title), new_reply.pk))
return HttpResponseRedirect(ctx['showurl'] + '/discuss/board/%d-%s?findReply=%d'%(board.pk, slugify(board.title), new_reply.pk))
else:
ctx['error'] = 'Invalid fields!'
......@@ -247,6 +257,7 @@ class BoardVoteSubmit(LoginRequiredMixin, View):
pos_bool = int(positive) == 1
user = req.user
showurl = get_show_url(abbr)
# Get the reply from the database
reply = get_object_or_404(DiscussionReply, id=replyid)
......@@ -254,8 +265,8 @@ class BoardVoteSubmit(LoginRequiredMixin, View):
# Prevent voting for own reply
if reply.user == user:
return HttpResponse('<h1>Error</h1><p>You cannot vote for your own reply.</p><p>'
'<a href="/show/%s/discuss/board/%d-%s">Return to board</a></p>'
% (abbr, reply.board.pk, slugify(reply.board.title)), status=400)
'<a href="%s/discuss/board/%d-%s">Return to board</a></p>'
% (showurl, reply.board.pk, slugify(reply.board.title)), status=400)
show = reply.board.show
......@@ -281,7 +292,7 @@ class BoardVoteSubmit(LoginRequiredMixin, View):
)
new_vote.save()
return HttpResponseRedirect('/show/%s/discuss/board/%d-%s?findReply=%d'%(abbr, reply.board.pk, slugify(reply.board.title), reply.pk))
return HttpResponseRedirect('%s/discuss/board/%d-%s?findReply=%d'%(showurl, reply.board.pk, slugify(reply.board.title), reply.pk))
@login_required
def ReportForm(req, abbr, rid):
......@@ -301,10 +312,11 @@ def ReportForm(req, abbr, rid):
ctx = {
'form': form,
'show': show,
'reply': reply
'reply': reply,
'showurl': get_show_url(abbr)
}
url = '/show/%s/discuss/board/%d-%s?findReply=%d'%(abbr, reply.board.pk, slugify(reply.board.title), reply.pk)
url = '%s/discuss/board/%d-%s?findReply=%d'%(ctx['showurl'], reply.board.pk, slugify(reply.board.title), reply.pk)
# Handle POST
if req.method == 'POST':
......@@ -330,8 +342,43 @@ def ReportForm(req, abbr, rid):
new_report.url = url
new_report.save()
return HttpResponseRedirect('/show/%s/discuss/board/%d-%s'%(abbr, reply.board.pk, slugify(reply.board.title)))
return HttpResponseRedirect('%s/discuss/board/%d-%s'%(ctx['showurl'], reply.board.pk, slugify(reply.board.title)))
else:
ctx['error'] = 'Invalid fields!'
return render(req, "report_reply.html", ctx)
@login_required
def BoardLock(req, abbr, bid):
user = req.user
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:
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>'
% (showurl, board.pk, slugify(board.title)), status=400)
lock = not board.locked
DiscussionBoard.objects.filter(pk=board.pk).update(locked=lock)
return HttpResponseRedirect('%s/discuss/board/%d-%s'%(showurl, board.pk, slugify(board.title)))
@permission_required_or_403('LandingPage.can_moderate_board', (Show, 'abbr', 'abbr'), accept_global_perms=True)
def BoardPin(req, abbr, bid):
board = get_object_or_404(DiscussionBoard, pk=bid)
showurl = get_show_url(abbr)
pin = not board.pinned
DiscussionBoard.objects.filter(pk=board.pk).update(pinned=pin)
return HttpResponseRedirect('%s/discuss/board/%d-%s'%(showurl, board.pk, slugify(board.title)))
@permission_required_or_403('LandingPage.can_moderate_board', (Show, 'abbr', 'abbr'), accept_global_perms=True)
def BoardDelete(req, abbr, bid):
board = get_object_or_404(DiscussionBoard, pk=bid)
showurl = get_show_url(abbr)
DiscussionBoard.objects.filter(pk=board.pk).delete()
return HttpResponseRedirect('%s/discuss' % (showurl))
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