kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
See #890: include notes in reports API representations
rodzic
7a7cc55143
commit
eb5b63c008
|
@ -641,11 +641,30 @@ class ManageTagActionSerializer(common_serializers.ActionSerializer):
|
||||||
return objects.delete()
|
return objects.delete()
|
||||||
|
|
||||||
|
|
||||||
|
class ManageBaseNoteSerializer(serializers.ModelSerializer):
|
||||||
|
author = ManageBaseActorSerializer(required=False, read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = moderation_models.Note
|
||||||
|
fields = ["id", "uuid", "creation_date", "summary", "author"]
|
||||||
|
read_only_fields = ["uuid", "creation_date", "author"]
|
||||||
|
|
||||||
|
|
||||||
|
class ManageNoteSerializer(ManageBaseNoteSerializer):
|
||||||
|
target = common_fields.GenericRelation(
|
||||||
|
moderation_utils.NOTE_TARGET_FIELDS
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta(ManageBaseNoteSerializer.Meta):
|
||||||
|
fields = ManageBaseNoteSerializer.Meta.fields + ['target']
|
||||||
|
|
||||||
|
|
||||||
class ManageReportSerializer(serializers.ModelSerializer):
|
class ManageReportSerializer(serializers.ModelSerializer):
|
||||||
assigned_to = ManageBaseActorSerializer()
|
assigned_to = ManageBaseActorSerializer()
|
||||||
target_owner = ManageBaseActorSerializer()
|
target_owner = ManageBaseActorSerializer()
|
||||||
submitter = ManageBaseActorSerializer()
|
submitter = ManageBaseActorSerializer()
|
||||||
target = moderation_serializers.TARGET_FIELD
|
target = moderation_serializers.TARGET_FIELD
|
||||||
|
notes = serializers.SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = moderation_models.Report
|
model = moderation_models.Report
|
||||||
|
@ -664,6 +683,7 @@ class ManageReportSerializer(serializers.ModelSerializer):
|
||||||
"target_owner",
|
"target_owner",
|
||||||
"submitter",
|
"submitter",
|
||||||
"submitter_email",
|
"submitter_email",
|
||||||
|
"notes",
|
||||||
]
|
]
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
"id",
|
"id",
|
||||||
|
@ -677,16 +697,9 @@ class ManageReportSerializer(serializers.ModelSerializer):
|
||||||
"target_state",
|
"target_state",
|
||||||
"target_owner",
|
"target_owner",
|
||||||
"summary",
|
"summary",
|
||||||
|
# "notes",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_notes(self, o):
|
||||||
class ManageNoteSerializer(serializers.ModelSerializer):
|
notes = getattr(o, '_prefetched_notes', [])
|
||||||
author = ManageBaseActorSerializer(required=False, read_only=True)
|
return ManageBaseNoteSerializer(notes, many=True).data
|
||||||
target = common_fields.GenericRelation(
|
|
||||||
moderation_utils.NOTE_TARGET_FIELDS
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = moderation_models.Note
|
|
||||||
fields = ["id", "uuid", "creation_date", "summary", "author", "target"]
|
|
||||||
read_only_fields = ["uuid", "creation_date", "author"]
|
|
||||||
|
|
|
@ -472,6 +472,9 @@ class ManageReportViewSet(
|
||||||
.order_by("-creation_date")
|
.order_by("-creation_date")
|
||||||
.select_related('submitter', 'target_owner', 'assigned_to', 'target_content_type')
|
.select_related('submitter', 'target_owner', 'assigned_to', 'target_content_type')
|
||||||
.prefetch_related('target')
|
.prefetch_related('target')
|
||||||
|
.prefetch_related(
|
||||||
|
Prefetch('notes', queryset=moderation_models.Note.objects.order_by('creation_date').select_related('author'), to_attr="_prefetched_notes")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
serializer_class = serializers.ManageReportSerializer
|
serializer_class = serializers.ManageReportSerializer
|
||||||
filterset_class = filters.ManageReportFilterSet
|
filterset_class = filters.ManageReportFilterSet
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
||||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.postgres.fields import JSONField
|
from django.contrib.postgres.fields import JSONField
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -149,6 +148,12 @@ class Report(federation_models.FederationMixin):
|
||||||
# delete
|
# delete
|
||||||
target_state = JSONField(null=True)
|
target_state = JSONField(null=True)
|
||||||
|
|
||||||
|
notes = GenericRelation(
|
||||||
|
"Note",
|
||||||
|
content_type_field="target_content_type",
|
||||||
|
object_id_field="target_id",
|
||||||
|
)
|
||||||
|
|
||||||
def get_federation_id(self):
|
def get_federation_id(self):
|
||||||
if self.fid:
|
if self.fid:
|
||||||
return self.fid
|
return self.fid
|
||||||
|
|
Ładowanie…
Reference in New Issue