mirror of
https://github.com/ae-utbm/sith.git
synced 2024-10-31 19:38:04 +00:00
pedagogy: moderation interface
This commit is contained in:
parent
3d0f5c0a15
commit
04009a6a5b
@ -23,6 +23,7 @@
|
||||
#
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from core.views.forms import MarkdownInput
|
||||
from core.models import User
|
||||
@ -122,3 +123,15 @@ class UVCommentReportForm(forms.ModelForm):
|
||||
self.fields["reporter"].initial = reporter_id
|
||||
self.fields["comment"].queryset = UVComment.objects.filter(id=comment_id).all()
|
||||
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,
|
||||
)
|
||||
|
36
pedagogy/templates/pedagogy/moderation.jinja
Normal file
36
pedagogy/templates/pedagogy/moderation.jinja
Normal 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 %}
|
@ -34,6 +34,7 @@ from django.views.generic import (
|
||||
from django.core import serializers
|
||||
from django.utils import html
|
||||
from django.http import HttpResponse
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
@ -47,7 +48,12 @@ from core.views import (
|
||||
|
||||
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
|
||||
|
||||
# Some mixins
|
||||
@ -226,12 +232,27 @@ class UVCommentReportCreateView(CanCreateMixin, CreateView):
|
||||
)
|
||||
|
||||
|
||||
class UVModerationFormView(CanEditPropMixin, FormView):
|
||||
class UVModerationFormView(FormView):
|
||||
"""
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user