See #890: freeze more data in reports, fixed some failing tests
This commit is contained in:
parent
ca7178d1d1
commit
2ad5b9e9f3
8 changed files with 58 additions and 23 deletions
|
|
@ -358,7 +358,9 @@ class ManageReportFilterSet(filters.FilterSet):
|
|||
"assigned_to": get_actor_filter("assigned_to"),
|
||||
"target_owner": get_actor_filter("target_owner"),
|
||||
"submitter_email": {"to": "submitter_email"},
|
||||
"target": common_filters.get_generic_relation_filter("target", moderation_serializers.TARGET_CONFIG),
|
||||
"target": common_filters.get_generic_relation_filter(
|
||||
"target", moderation_serializers.TARGET_CONFIG
|
||||
),
|
||||
},
|
||||
)
|
||||
)
|
||||
|
|
@ -375,7 +377,9 @@ class ManageNoteFilterSet(filters.FilterSet):
|
|||
filter_fields={
|
||||
"uuid": {"to": "uuid"},
|
||||
"author": get_actor_filter("author"),
|
||||
"target": common_filters.get_generic_relation_filter("target", moderation_utils.NOTE_TARGET_FIELDS),
|
||||
"target": common_filters.get_generic_relation_filter(
|
||||
"target", moderation_utils.NOTE_TARGET_FIELDS
|
||||
),
|
||||
},
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -651,12 +651,10 @@ class ManageBaseNoteSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class ManageNoteSerializer(ManageBaseNoteSerializer):
|
||||
target = common_fields.GenericRelation(
|
||||
moderation_utils.NOTE_TARGET_FIELDS
|
||||
)
|
||||
target = common_fields.GenericRelation(moderation_utils.NOTE_TARGET_FIELDS)
|
||||
|
||||
class Meta(ManageBaseNoteSerializer.Meta):
|
||||
fields = ManageBaseNoteSerializer.Meta.fields + ['target']
|
||||
fields = ManageBaseNoteSerializer.Meta.fields + ["target"]
|
||||
|
||||
|
||||
class ManageReportSerializer(serializers.ModelSerializer):
|
||||
|
|
@ -701,5 +699,5 @@ class ManageReportSerializer(serializers.ModelSerializer):
|
|||
]
|
||||
|
||||
def get_notes(self, o):
|
||||
notes = getattr(o, '_prefetched_notes', [])
|
||||
notes = getattr(o, "_prefetched_notes", [])
|
||||
return ManageBaseNoteSerializer(notes, many=True).data
|
||||
|
|
|
|||
|
|
@ -470,10 +470,18 @@ class ManageReportViewSet(
|
|||
queryset = (
|
||||
moderation_models.Report.objects.all()
|
||||
.order_by("-creation_date")
|
||||
.select_related('submitter', 'target_owner', 'assigned_to', 'target_content_type')
|
||||
.prefetch_related('target')
|
||||
.select_related(
|
||||
"submitter", "target_owner", "assigned_to", "target_content_type"
|
||||
)
|
||||
.prefetch_related("target")
|
||||
.prefetch_related(
|
||||
Prefetch('notes', queryset=moderation_models.Note.objects.order_by('creation_date').select_related('author'), to_attr="_prefetched_notes")
|
||||
Prefetch(
|
||||
"notes",
|
||||
queryset=moderation_models.Note.objects.order_by(
|
||||
"creation_date"
|
||||
).select_related("author"),
|
||||
to_attr="_prefetched_notes",
|
||||
)
|
||||
)
|
||||
)
|
||||
serializer_class = serializers.ManageReportSerializer
|
||||
|
|
@ -491,9 +499,10 @@ class ManageNoteViewSet(
|
|||
):
|
||||
lookup_field = "uuid"
|
||||
queryset = (
|
||||
moderation_models.Note.objects.all().order_by("-creation_date")
|
||||
.select_related('author', 'target_content_type')
|
||||
.prefetch_related('target')
|
||||
moderation_models.Note.objects.all()
|
||||
.order_by("-creation_date")
|
||||
.select_related("author", "target_content_type")
|
||||
.prefetch_related("target")
|
||||
)
|
||||
serializer_class = serializers.ManageNoteSerializer
|
||||
filterset_class = filters.ManageNoteFilterSet
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue