mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 22:23:23 +00:00
pedagogy: base for uv comment moderation
This commit is contained in:
parent
437af4dd04
commit
3d0f5c0a15
@ -27,7 +27,7 @@ from django import forms
|
|||||||
from core.views.forms import MarkdownInput
|
from core.views.forms import MarkdownInput
|
||||||
from core.models import User
|
from core.models import User
|
||||||
|
|
||||||
from pedagogy.models import UV, UVComment
|
from pedagogy.models import UV, UVComment, UVCommentReport
|
||||||
|
|
||||||
|
|
||||||
class UVForm(forms.ModelForm):
|
class UVForm(forms.ModelForm):
|
||||||
@ -100,3 +100,25 @@ class UVCommentForm(forms.ModelForm):
|
|||||||
self.fields["author"].initial = author_id
|
self.fields["author"].initial = author_id
|
||||||
self.fields["uv"].queryset = UV.objects.filter(id=uv_id).all()
|
self.fields["uv"].queryset = UV.objects.filter(id=uv_id).all()
|
||||||
self.fields["uv"].initial = uv_id
|
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
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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 __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -190,7 +190,7 @@ class Migration(migrations.Migration):
|
|||||||
verbose_name="ID",
|
verbose_name="ID",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
("comment", models.TextField(verbose_name="comment")),
|
("comment", models.TextField(blank=True, verbose_name="comment")),
|
||||||
(
|
(
|
||||||
"grade_global",
|
"grade_global",
|
||||||
models.IntegerField(
|
models.IntegerField(
|
||||||
@ -281,7 +281,26 @@ class Migration(migrations.Migration):
|
|||||||
serialize=False,
|
serialize=False,
|
||||||
verbose_name="ID",
|
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(
|
migrations.CreateModel(
|
||||||
|
@ -176,7 +176,7 @@ class UVComment(models.Model):
|
|||||||
blank=False,
|
blank=False,
|
||||||
)
|
)
|
||||||
uv = models.ForeignKey(UV, related_name="comments", verbose_name=_("uv"))
|
uv = models.ForeignKey(UV, related_name="comments", verbose_name=_("uv"))
|
||||||
comment = models.TextField(_("comment"))
|
comment = models.TextField(_("comment"), blank=True)
|
||||||
grade_global = models.IntegerField(
|
grade_global = models.IntegerField(
|
||||||
_("global grade"),
|
_("global grade"),
|
||||||
validators=[validators.MinValueValidator(-1), validators.MaxValueValidator(4)],
|
validators=[validators.MinValueValidator(-1), validators.MaxValueValidator(4)],
|
||||||
@ -251,4 +251,19 @@ class UVCommentReport(models.Model):
|
|||||||
Report an inapropriate comment
|
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"))
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
{% if user.is_owner(comment) %}
|
{% 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_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_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 %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -46,7 +46,6 @@ urlpatterns = [
|
|||||||
name="comment_report",
|
name="comment_report",
|
||||||
),
|
),
|
||||||
# Moderation
|
# Moderation
|
||||||
url(r"^reported$", UVCommentReportListView.as_view(), name="comment_report_list"),
|
|
||||||
url(r"^moderation$", UVModerationFormView.as_view(), name="moderation"),
|
url(r"^moderation$", UVModerationFormView.as_view(), name="moderation"),
|
||||||
# Administration : Create Update Delete Edit
|
# Administration : Create Update Delete Edit
|
||||||
url(r"^uv/create$", UVCreateView.as_view(), name="uv_create"),
|
url(r"^uv/create$", UVCreateView.as_view(), name="uv_create"),
|
||||||
|
@ -35,6 +35,7 @@ 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.urlresolvers import reverse_lazy
|
from django.core.urlresolvers import reverse_lazy
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from core.views import (
|
from core.views import (
|
||||||
DetailFormView,
|
DetailFormView,
|
||||||
@ -46,8 +47,8 @@ from core.views import (
|
|||||||
|
|
||||||
from haystack.query import SearchQuerySet
|
from haystack.query import SearchQuerySet
|
||||||
|
|
||||||
from pedagogy.forms import UVForm, UVCommentForm
|
from pedagogy.forms import UVForm, UVCommentForm, UVCommentReportForm
|
||||||
from pedagogy.models import UV, UVComment
|
from pedagogy.models import UV, UVComment, UVCommentReport
|
||||||
|
|
||||||
# Some mixins
|
# Some mixins
|
||||||
|
|
||||||
@ -200,25 +201,34 @@ class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
|
|||||||
return queryset.filter(id__in=([o.object.id for o in qs]))
|
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
|
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)
|
Moderation interface (Privileged)
|
||||||
"""
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class UVModerationFormView(FormView):
|
|
||||||
"""
|
|
||||||
List all UVs to moderate and allow to moderate them (Privileged)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user