pedagogy: base for uv comment moderation

This commit is contained in:
Antoine Bartuccio 2019-06-20 01:29:12 +02:00
parent 437af4dd04
commit 3d0f5c0a15
Signed by: klmp200
GPG Key ID: E7245548C53F904B
6 changed files with 87 additions and 21 deletions

View File

@ -27,7 +27,7 @@ from django import forms
from core.views.forms import MarkdownInput
from core.models import User
from pedagogy.models import UV, UVComment
from pedagogy.models import UV, UVComment, UVCommentReport
class UVForm(forms.ModelForm):
@ -100,3 +100,25 @@ class UVCommentForm(forms.ModelForm):
self.fields["author"].initial = author_id
self.fields["uv"].queryset = UV.objects.filter(id=uv_id).all()
self.fields["uv"].initial = uv_id
class UVCommentReportForm(forms.ModelForm):
"""
Form handeling creation and edit of an UVReport
"""
class Meta:
model = UVCommentReport
fields = ("comment", "reporter", "reason")
widgets = {
"comment": forms.HiddenInput,
"reporter": forms.HiddenInput,
"reason": MarkdownInput,
}
def __init__(self, reporter_id, comment_id, *args, **kwargs):
super(UVCommentReportForm, self).__init__(*args, **kwargs)
self.fields["reporter"].queryset = User.objects.filter(id=reporter_id).all()
self.fields["reporter"].initial = reporter_id
self.fields["comment"].queryset = UVComment.objects.filter(id=comment_id).all()
self.fields["comment"].initial = comment_id

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-06-18 20:07
# Generated by Django 1.11.20 on 2019-06-19 23:05
from __future__ import unicode_literals
from django.conf import settings
@ -190,7 +190,7 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
("comment", models.TextField(verbose_name="comment")),
("comment", models.TextField(blank=True, verbose_name="comment")),
(
"grade_global",
models.IntegerField(
@ -281,7 +281,26 @@ class Migration(migrations.Migration):
serialize=False,
verbose_name="ID",
),
)
),
("reason", models.TextField(verbose_name="reason")),
(
"comment",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="reports",
to="pedagogy.UVComment",
verbose_name="report",
),
),
(
"reporter",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="reported_uv_comment",
to=settings.AUTH_USER_MODEL,
verbose_name="reporter",
),
),
],
),
migrations.CreateModel(

View File

@ -176,7 +176,7 @@ class UVComment(models.Model):
blank=False,
)
uv = models.ForeignKey(UV, related_name="comments", verbose_name=_("uv"))
comment = models.TextField(_("comment"))
comment = models.TextField(_("comment"), blank=True)
grade_global = models.IntegerField(
_("global grade"),
validators=[validators.MinValueValidator(-1), validators.MaxValueValidator(4)],
@ -251,4 +251,19 @@ class UVCommentReport(models.Model):
Report an inapropriate comment
"""
pass
def is_owned_by(self, user):
"""
Is owned by a pedagogy admin, a superuser or the author himself
"""
return self.reporter == user or user.is_owner(self.comment.uv)
comment = models.ForeignKey(
UVComment,
related_name="reports",
verbose_name=_("report"),
on_delete=models.CASCADE,
)
reporter = models.ForeignKey(
User, related_name="reported_uv_comment", verbose_name=_("reporter")
)
reason = models.TextField(_("reason"))

View File

@ -28,6 +28,7 @@
{% if user.is_owner(comment) %}
<p><a href="{{ url('pedagogy:comment_update', comment_id=comment.id) }}">{% trans %}Edit{% endtrans %}</a></p>
<p><a href="{{ url('pedagogy:comment_delete', comment_id=comment.id) }}">{% trans %}Delete{% endtrans %}</a></p>
<p><a href="{{ url('pedagogy:comment_report', comment_id=comment.id) }}">{% trans %}Report{% endtrans %}</a></p>
{% endif %}
{% endfor %}
{% endif %}

View File

@ -46,7 +46,6 @@ urlpatterns = [
name="comment_report",
),
# Moderation
url(r"^reported$", UVCommentReportListView.as_view(), name="comment_report_list"),
url(r"^moderation$", UVModerationFormView.as_view(), name="moderation"),
# Administration : Create Update Delete Edit
url(r"^uv/create$", UVCreateView.as_view(), name="uv_create"),

View File

@ -35,6 +35,7 @@ from django.core import serializers
from django.utils import html
from django.http import HttpResponse
from django.core.urlresolvers import reverse_lazy
from django.shortcuts import get_object_or_404
from core.views import (
DetailFormView,
@ -46,8 +47,8 @@ from core.views import (
from haystack.query import SearchQuerySet
from pedagogy.forms import UVForm, UVCommentForm
from pedagogy.models import UV, UVComment
from pedagogy.forms import UVForm, UVCommentForm, UVCommentReportForm
from pedagogy.models import UV, UVComment, UVCommentReport
# Some mixins
@ -200,25 +201,34 @@ class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
return queryset.filter(id__in=([o.object.id for o in qs]))
class UVCommentReportCreateView(CreateView):
class UVCommentReportCreateView(CanCreateMixin, CreateView):
"""
Create a new report for an inapropriate comment
"""
pass
model = UVCommentReport
form_class = UVCommentReportForm
template_name = "core/edit.jinja"
def dispatch(self, request, *args, **kwargs):
self.uv_comment = get_object_or_404(UVComment, pk=kwargs["comment_id"])
return super(UVCommentReportCreateView, self).dispatch(request, *args, **kwargs)
def get_form_kwargs(self):
kwargs = super(UVCommentReportCreateView, self).get_form_kwargs()
kwargs["reporter_id"] = self.request.user.id
kwargs["comment_id"] = self.uv_comment.id
return kwargs
def get_success_url(self):
return reverse_lazy(
"pedagogy:uv_detail", kwargs={"uv_id": self.uv_comment.uv.id}
)
class UVCommentReportListView(ListView):
class UVModerationFormView(CanEditPropMixin, FormView):
"""
List all UV reports for moderation (Privileged)
"""
pass
class UVModerationFormView(FormView):
"""
List all UVs to moderate and allow to moderate them (Privileged)
Moderation interface (Privileged)
"""
pass