Skip to content

Commit

Permalink
Simplify report views (#1872)
Browse files Browse the repository at this point in the history
* Simplify report views

* Prevent redundant update statement when creating a report
  • Loading branch information
krysal authored Apr 28, 2023
1 parent 271f33a commit 59a4411
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
5 changes: 4 additions & 1 deletion api/catalog/api/models/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ def save(self, *args, **kwargs):
)
if self.status != DEINDEXED:
same_reports = same_reports.filter(reason=self.reason)
same_reports.update(status=self.status)

# Prevent redundant update statement when creating the report
if self.status != PENDING:
same_reports.update(status=self.status)


class AbstractDeletedMedia(OpenLedgerModel):
Expand Down
4 changes: 2 additions & 2 deletions api/catalog/api/views/audio_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ def waveform(self, *_, **__):
methods=["post"],
serializer_class=AudioReportRequestSerializer,
)
def report(self, *args, **kwargs):
return super().report(*args, **kwargs)
def report(self, request, identifier):
return super().report(request, identifier)
4 changes: 2 additions & 2 deletions api/catalog/api/views/image_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def watermark(self, request, *_, **__):
methods=["post"],
serializer_class=ImageReportRequestSerializer,
)
def report(self, *args, **kwargs):
return super().report(*args, **kwargs)
def report(self, request, identifier):
return super().report(request, identifier)

# Helper functions

Expand Down
7 changes: 2 additions & 5 deletions api/catalog/api/views/media_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,11 @@ def related(self, request, identifier=None, *_, **__):
serializer = self.get_serializer(results, many=True)
return self.get_paginated_response(serializer.data)

def report(self, request, *_, **__):
media = self.get_object()
identifier = media.identifier
def report(self, request, identifier):
serializer = self.get_serializer(data=request.data | {"identifier": identifier})
serializer.is_valid(raise_exception=True)
report = serializer.save()
serializer.save()

serializer = self.get_serializer(report)
return Response(data=serializer.data, status=status.HTTP_201_CREATED)

def thumbnail(self, image_url, request, *_, **__):
Expand Down

0 comments on commit 59a4411

Please sign in to comment.