pedagogy: allow to deny removal request for comment in moderation

This commit is contained in:
Antoine Bartuccio 2019-06-20 13:19:35 +02:00
parent 04009a6a5b
commit 806084e707
Signed by: klmp200
GPG Key ID: E7245548C53F904B
3 changed files with 45 additions and 8 deletions

View File

@ -130,8 +130,16 @@ class UVCommentModerationForm(forms.Form):
Form handeling bulk comment deletion
"""
reports = forms.ModelMultipleChoiceField(
accepted_reports = forms.ModelMultipleChoiceField(
UVCommentReport.objects.all(),
label=_("Reported comments"),
label=_("Accepted reports"),
widget=forms.CheckboxSelectMultiple,
required=False,
)
denied_reports = forms.ModelMultipleChoiceField(
UVCommentReport.objects.all(),
label=_("Denied reports"),
widget=forms.CheckboxSelectMultiple,
required=False,
)

View File

@ -6,9 +6,9 @@
{% endblock title %}
{% block content %}
<form action="{{ url('pedagogy:moderation') }}", id="moderation_form" method="post" enctype="multipart/form-data">
<form action="{{ url('pedagogy:moderation') }}", id="moderation_delete_form" method="post" enctype="multipart/form-data">
{% csrf_token %}
<p style="margin-bottom: 1em;">{{ select_all_checkbox("moderation_form") }}</p>
<p style="margin-bottom: 1em;">{{ select_all_checkbox("moderation_delete_form") }}</p>
<table>
<thead>
<tr>
@ -19,8 +19,8 @@
</tr>
</thead>
<tbody>
{% set queryset = form.reports.field.queryset %}
{% for widget in form.reports.subwidgets %}
{% set queryset = form.accepted_reports.field.queryset %}
{% for widget in form.accepted_reports.subwidgets %}
{% set report = queryset.get(id=widget.data.value) %}
<tr>
<td>{{ report.comment.uv }}</td>
@ -33,4 +33,31 @@
</table>
<p><input type="submit" value="{% trans %}Delete comments{% endtrans %}"></p>
</form>
<form action="{{ url('pedagogy:moderation') }}", id="moderation_keep_form" method="post" enctype="multipart/form-data">
{% csrf_token %}
<p style="margin-bottom: 1em;">{{ select_all_checkbox("moderation_keep_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.denied_reports.field.queryset %}
{% for widget in form.denied_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 report{% endtrans %}"></p>
</form>
{% endblock content %}

View File

@ -247,8 +247,10 @@ class UVModerationFormView(FormView):
def form_valid(self, form):
form_clean = form.clean()
for report in form_clean.get("reports", []):
report.comment.delete()
for report in form_clean.get("accepted_reports", []):
report.comment.delete() # Delete the related comment
for report in form_clean.get("denied_reports", []):
report.delete() # Delete the report itself
return super(UVModerationFormView, self).form_valid(form)
def get_success_url(self):