pedagogy: moderation interface

This commit is contained in:
Antoine Bartuccio 2019-06-20 12:15:12 +02:00
parent 3d0f5c0a15
commit 04009a6a5b
Signed by: klmp200
GPG Key ID: E7245548C53F904B
3 changed files with 73 additions and 3 deletions

View File

@ -23,6 +23,7 @@
# #
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _
from core.views.forms import MarkdownInput from core.views.forms import MarkdownInput
from core.models import User from core.models import User
@ -122,3 +123,15 @@ class UVCommentReportForm(forms.ModelForm):
self.fields["reporter"].initial = reporter_id self.fields["reporter"].initial = reporter_id
self.fields["comment"].queryset = UVComment.objects.filter(id=comment_id).all() self.fields["comment"].queryset = UVComment.objects.filter(id=comment_id).all()
self.fields["comment"].initial = comment_id self.fields["comment"].initial = comment_id
class UVCommentModerationForm(forms.Form):
"""
Form handeling bulk comment deletion
"""
reports = forms.ModelMultipleChoiceField(
UVCommentReport.objects.all(),
label=_("Reported comments"),
widget=forms.CheckboxSelectMultiple,
)

View File

@ -0,0 +1,36 @@
{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import select_all_checkbox %}
{% block title %}
{% trans %}UV comment moderation{% endtrans %}
{% endblock title %}
{% block content %}
<form action="{{ url('pedagogy:moderation') }}", id="moderation_form" method="post" enctype="multipart/form-data">
{% csrf_token %}
<p style="margin-bottom: 1em;">{{ select_all_checkbox("moderation_form") }}</p>
<table>
<thead>
<tr>
<td>{% trans %}UV{% endtrans %}</td>
<td>{% trans %}Comment{% endtrans %}</td>
<td>{% trans %}Reason{% endtrans %}</td>
<td>{% trans %}Delete{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% set queryset = form.reports.field.queryset %}
{% for widget in form.reports.subwidgets %}
{% set report = queryset.get(id=widget.data.value) %}
<tr>
<td>{{ report.comment.uv }}</td>
<td>{{ report.comment.comment|markdown }}</td>
<td>{{ report.reason|markdown }}</td>
<td>{{ widget.tag() }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<p><input type="submit" value="{% trans %}Delete comments{% endtrans %}"></p>
</form>
{% endblock content %}

View File

@ -34,6 +34,7 @@ from django.views.generic import (
from django.core import serializers from django.core import serializers
from django.utils import html from django.utils import html
from django.http import HttpResponse from django.http import HttpResponse
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
@ -47,7 +48,12 @@ from core.views import (
from haystack.query import SearchQuerySet from haystack.query import SearchQuerySet
from pedagogy.forms import UVForm, UVCommentForm, UVCommentReportForm from pedagogy.forms import (
UVForm,
UVCommentForm,
UVCommentReportForm,
UVCommentModerationForm,
)
from pedagogy.models import UV, UVComment, UVCommentReport from pedagogy.models import UV, UVComment, UVCommentReport
# Some mixins # Some mixins
@ -226,12 +232,27 @@ class UVCommentReportCreateView(CanCreateMixin, CreateView):
) )
class UVModerationFormView(CanEditPropMixin, FormView): class UVModerationFormView(FormView):
""" """
Moderation interface (Privileged) Moderation interface (Privileged)
""" """
pass form_class = UVCommentModerationForm
template_name = "pedagogy/moderation.jinja"
def dispatch(self, request, *args, **kwargs):
if not request.user.is_owner(UV()):
raise PermissionDenied
return super(UVModerationFormView, self).dispatch(request, *args, **kwargs)
def form_valid(self, form):
form_clean = form.clean()
for report in form_clean.get("reports", []):
report.comment.delete()
return super(UVModerationFormView, self).form_valid(form)
def get_success_url(self):
return reverse_lazy("pedagogy:moderation")
class UVCreateView(CanCreateMixin, CreateView): class UVCreateView(CanCreateMixin, CreateView):