-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
apps/classifications/migrations/0002_userclassification.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 2.2.19 on 2021-04-07 13:41 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('a4comments', '0007_comment_is_moderator_marked'), | ||
('a4_candy_classifications', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserClassification', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created', models.DateTimeField(default=django.utils.timezone.now, editable=False)), | ||
('modified', models.DateTimeField(blank=True, editable=False, null=True)), | ||
('classification', models.CharField(choices=[('OFFENSIVE', 'Offensive'), ('OTHER', 'Other')], max_length=50)), | ||
('comment_text', models.TextField(max_length=4000)), | ||
('user_message', models.TextField(max_length=1024)), | ||
('comment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='a4comments.Comment')), | ||
('creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from rest_framework import mixins | ||
from rest_framework import permissions | ||
from rest_framework import viewsets | ||
|
||
from adhocracy4.comments.models import Comment | ||
from adhocracy4.reports import emails | ||
from adhocracy4.reports.models import Report | ||
from adhocracy4.reports.serializers import ReportSerializer | ||
from apps.classifications.models import UserClassification | ||
|
||
''' | ||
overwrites ReportViewSet from adhocracy4 in order to | ||
save a UserClassification object every time a comment is | ||
reported | ||
''' | ||
|
||
|
||
class ReportViewSet(mixins.CreateModelMixin, | ||
viewsets.GenericViewSet): | ||
|
||
serializer_class = ReportSerializer | ||
queryset = Report.objects.all() | ||
permission_classes = (permissions.IsAuthenticated,) | ||
|
||
def perform_create(self, serializer): | ||
report = serializer.save(creator=self.request.user) | ||
emails.ReportModeratorEmail.send(report) | ||
if serializer.data['content_type'] == \ | ||
ContentType.objects.get(app_label='a4comments', | ||
model='comment').pk: | ||
|
||
classification = UserClassification( | ||
creator=self.request.user, | ||
comment=Comment.objects.get(pk=serializer.data['object_pk']), | ||
classification='OFFENSIVE', | ||
user_message=serializer.data['description']) | ||
classification.save() |