feat: Add reports for comments, add to admin
This commit is contained in:
parent
a6b9c9f094
commit
273bef9526
@ -1,9 +1,11 @@
|
|||||||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import User, Language, Text
|
from django.utils.html import format_html
|
||||||
|
|
||||||
|
from .models import User, Language, Text, ReportComment, ReportAdoptionNotice
|
||||||
|
|
||||||
from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \
|
from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \
|
||||||
Report, Member, Comment
|
Member, Comment, Report
|
||||||
|
|
||||||
|
|
||||||
# Define an inline admin descriptor for Employee model
|
# Define an inline admin descriptor for Employee model
|
||||||
@ -22,6 +24,34 @@ class UserAdmin(BaseUserAdmin):
|
|||||||
# Re-register UserAdmin
|
# Re-register UserAdmin
|
||||||
admin.site.register(User, UserAdmin)
|
admin.site.register(User, UserAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
def _reported_content_link(obj):
|
||||||
|
reported_content = obj.reported_content
|
||||||
|
return format_html(f'<a href="{reported_content.get_absolute_url}">{reported_content}</a>')
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(ReportComment)
|
||||||
|
class ReportCommentAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ["user_comment", "reported_content_link"]
|
||||||
|
date_hierarchy = "created_at"
|
||||||
|
|
||||||
|
def reported_content_link(self, obj):
|
||||||
|
return _reported_content_link(obj)
|
||||||
|
|
||||||
|
reported_content_link.short_description = "Reported Content"
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(ReportAdoptionNotice)
|
||||||
|
class ReportAdoptionNoticeAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ["user_comment", "reported_content_link"]
|
||||||
|
date_hierarchy = "created_at"
|
||||||
|
|
||||||
|
def reported_content_link(self, obj):
|
||||||
|
return _reported_content_link(obj)
|
||||||
|
|
||||||
|
reported_content_link.short_description = "Reported Content"
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Animal)
|
admin.site.register(Animal)
|
||||||
admin.site.register(Species)
|
admin.site.register(Species)
|
||||||
admin.site.register(RescueOrganization)
|
admin.site.register(RescueOrganization)
|
||||||
@ -29,8 +59,6 @@ admin.site.register(Location)
|
|||||||
admin.site.register(AdoptionNotice)
|
admin.site.register(AdoptionNotice)
|
||||||
admin.site.register(Rule)
|
admin.site.register(Rule)
|
||||||
admin.site.register(Image)
|
admin.site.register(Image)
|
||||||
admin.site.register(Report)
|
|
||||||
admin.site.register(ModerationAction)
|
admin.site.register(ModerationAction)
|
||||||
admin.site.register(Language)
|
admin.site.register(Language)
|
||||||
admin.site.register(Text)
|
admin.site.register(Text)
|
||||||
admin.site.register(Comment)
|
|
||||||
|
@ -2,7 +2,8 @@ import datetime
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from .models import AdoptionNotice, Animal, Image, Report, ModerationAction, User, Species, Comment
|
from .models import AdoptionNotice, Animal, Image, ReportAdoptionNotice, ReportComment, ModerationAction, User, Species, \
|
||||||
|
Comment
|
||||||
from django_registration.forms import RegistrationForm
|
from django_registration.forms import RegistrationForm
|
||||||
from crispy_forms.helper import FormHelper
|
from crispy_forms.helper import FormHelper
|
||||||
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field
|
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field
|
||||||
@ -53,10 +54,16 @@ class ImageForm(forms.ModelForm):
|
|||||||
fields = ('title', 'image', 'alt_text')
|
fields = ('title', 'image', 'alt_text')
|
||||||
|
|
||||||
|
|
||||||
class ReportForm(forms.ModelForm):
|
class ReportAdoptionNoticeForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Report
|
model = ReportAdoptionNotice
|
||||||
fields = ('reported_broken_rules', 'comment')
|
fields = ('reported_broken_rules', 'user_comment')
|
||||||
|
|
||||||
|
|
||||||
|
class ReportCommentForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = ReportComment
|
||||||
|
fields = ('reported_broken_rules', 'user_comment')
|
||||||
|
|
||||||
|
|
||||||
class CommentForm(forms.ModelForm):
|
class CommentForm(forms.ModelForm):
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-06-04 06:22
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("fellchensammlung", "0002_comment"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="report",
|
||||||
|
name="adoption_notice",
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="report",
|
||||||
|
old_name="comment",
|
||||||
|
new_name="user_comment",
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="ReportComment",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"report_ptr",
|
||||||
|
models.OneToOneField(
|
||||||
|
auto_created=True,
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
parent_link=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
to="fellchensammlung.report",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"reported_comment",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to="fellchensammlung.comment",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
bases=("fellchensammlung.report",),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="ReportAdoptionNotice",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"report_ptr",
|
||||||
|
models.OneToOneField(
|
||||||
|
auto_created=True,
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
parent_link=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
to="fellchensammlung.report",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"adoption_notice",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to="fellchensammlung.adoptionnotice",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
bases=("fellchensammlung.report",),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-06-04 08:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("fellchensammlung", "0003_remove_report_adoption_notice_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="report",
|
||||||
|
name="reported_broken_rules",
|
||||||
|
field=models.ManyToManyField(to="fellchensammlung.rule"),
|
||||||
|
),
|
||||||
|
]
|
@ -241,13 +241,12 @@ class Report(models.Model):
|
|||||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text=_('ID dieses reports'),
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text=_('ID dieses reports'),
|
||||||
verbose_name=_('ID'))
|
verbose_name=_('ID'))
|
||||||
status = models.CharField(max_length=30, choices=STATES)
|
status = models.CharField(max_length=30, choices=STATES)
|
||||||
reported_broken_rules = models.ManyToManyField(Rule, blank=True)
|
reported_broken_rules = models.ManyToManyField(Rule)
|
||||||
adoption_notice = models.ForeignKey("AdoptionNotice", on_delete=models.CASCADE)
|
user_comment = models.TextField(blank=True)
|
||||||
comment = models.TextField(blank=True)
|
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"[{self.status}]: {self.adoption_notice.name}"
|
return f"[{self.status}]: {self.user_comment:.20}"
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
"""Returns the url to access a detailed page for the report."""
|
"""Returns the url to access a detailed page for the report."""
|
||||||
@ -260,6 +259,22 @@ class Report(models.Model):
|
|||||||
return ModerationAction.objects.filter(report=self)
|
return ModerationAction.objects.filter(report=self)
|
||||||
|
|
||||||
|
|
||||||
|
class ReportAdoptionNotice(Report):
|
||||||
|
adoption_notice = models.ForeignKey("AdoptionNotice", on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reported_content(self):
|
||||||
|
return self.adoption_notice
|
||||||
|
|
||||||
|
|
||||||
|
class ReportComment(Report):
|
||||||
|
reported_comment = models.ForeignKey("Comment", on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reported_content(self):
|
||||||
|
return self.reported_comment
|
||||||
|
|
||||||
|
|
||||||
class ModerationAction(models.Model):
|
class ModerationAction(models.Model):
|
||||||
BAN = "user_banned"
|
BAN = "user_banned"
|
||||||
DELETE = "content_deleted"
|
DELETE = "content_deleted"
|
||||||
@ -368,3 +383,10 @@ class Comment(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.user} at {self.created_at.strftime('%H:%M %d.%m.%y')}: {self.text:.10}"
|
return f"{self.user} at {self.created_at.strftime('%H:%M %d.%m.%y')}: {self.text:.10}"
|
||||||
|
|
||||||
|
def get_report_url(self):
|
||||||
|
return reverse('report-comment', args=[str(self.id)])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return self.adoption_notice.get_absolute_url()
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<div class="comment-header">
|
<div class="comment-header">
|
||||||
<b>{{ comment.user }}</b>
|
<b>{{ comment.user }}</b>
|
||||||
{{ comment.created_at }}
|
{{ comment.created_at }}
|
||||||
|
<a class="adoption-card-report-link" href="{{ comment.get_report_url }}"><i class="fa-solid fa-flag"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
{{ comment.text | render_markdown }}
|
{{ comment.text | render_markdown }}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<div class="report">
|
<div class="report">
|
||||||
<h2>
|
<h2>
|
||||||
{% blocktranslate %}
|
{% blocktranslate %}
|
||||||
Meldung von {{ report.adoption_notice.name }}
|
Meldung von {{ report.reported_content }}
|
||||||
{% endblocktranslate %}
|
{% endblocktranslate %}
|
||||||
</h2>
|
</h2>
|
||||||
{% if report.reported_broken_rules %}
|
{% if report.reported_broken_rules %}
|
||||||
@ -14,6 +14,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p><b>{% translate "Kommentar zur Meldung" %}:</b>
|
<p><b>{% translate "Kommentar zur Meldung" %}:</b>
|
||||||
{{ report.comment }}
|
{{ report.user_comment }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
@ -28,7 +28,9 @@ urlpatterns = [
|
|||||||
#############
|
#############
|
||||||
## Reports ##
|
## Reports ##
|
||||||
#############
|
#############
|
||||||
path("melden/<int:adoption_notice_id>/", views.report_adoption, name="report-adoption-notice"),
|
path("vermittlung/<int:adoption_notice_id>/report", views.report_adoption, name="report-adoption-notice"),
|
||||||
|
|
||||||
|
path("kommentar/<int:comment_id>/report", views.report_comment, name="report-comment"),
|
||||||
path("meldung/<uuid:report_id>/", views.report_detail, name="report-detail"),
|
path("meldung/<uuid:report_id>/", views.report_detail, name="report-detail"),
|
||||||
path("meldung/<uuid:report_id>/sucess", views.report_detail_success, name="report-detail-success"),
|
path("meldung/<uuid:report_id>/sucess", views.report_detail_success, name="report-detail-success"),
|
||||||
path("modqueue/", views.modqueue, name="modqueue"),
|
path("modqueue/", views.modqueue, name="modqueue"),
|
||||||
|
@ -13,7 +13,7 @@ from notfellchen import settings
|
|||||||
from fellchensammlung import logger
|
from fellchensammlung import logger
|
||||||
from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
|
from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
|
||||||
Member
|
Member
|
||||||
from .forms import AdoptionNoticeForm, ImageForm, ReportForm, CommentForm
|
from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm
|
||||||
from .models import Language
|
from .models import Language
|
||||||
|
|
||||||
|
|
||||||
@ -223,17 +223,38 @@ def report_adoption(request, adoption_notice_id):
|
|||||||
Form to report adoption notices
|
Form to report adoption notices
|
||||||
"""
|
"""
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = ReportForm(request.POST)
|
form = ReportAdoptionNoticeForm(request.POST)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
report_instance = form.save(commit=False)
|
report_instance = form.save(commit=False)
|
||||||
report_instance.adoption_notice_id = adoption_notice_id
|
report_instance.adoption_notice_id = adoption_notice_id
|
||||||
report_instance.status = Report.WAITING
|
report_instance.status = Report.WAITING
|
||||||
report_instance.save()
|
report_instance.save()
|
||||||
|
form.save_m2m()
|
||||||
mail_admins_new_report(report_instance)
|
mail_admins_new_report(report_instance)
|
||||||
return redirect(reverse("report-detail-success", args=[report_instance.pk], ))
|
return redirect(reverse("report-detail-success", args=[report_instance.pk], ))
|
||||||
else:
|
else:
|
||||||
form = ReportForm()
|
form = ReportAdoptionNoticeForm()
|
||||||
|
return render(request, 'fellchensammlung/forms/form-report.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
def report_comment(request, comment_id):
|
||||||
|
"""
|
||||||
|
Form to report comments
|
||||||
|
"""
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = ReportCommentForm(request.POST)
|
||||||
|
|
||||||
|
if form.is_valid():
|
||||||
|
report_instance = form.save(commit=False)
|
||||||
|
report_instance.reported_comment_id = comment_id
|
||||||
|
report_instance.status = Report.WAITING
|
||||||
|
report_instance.save()
|
||||||
|
form.save_m2m()
|
||||||
|
mail_admins_new_report(report_instance)
|
||||||
|
return redirect(reverse("report-detail-success", args=[report_instance.pk], ))
|
||||||
|
else:
|
||||||
|
form = ReportCommentForm()
|
||||||
return render(request, 'fellchensammlung/forms/form-report.html', {'form': form})
|
return render(request, 'fellchensammlung/forms/form-report.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user