SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 10728f51 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

change pdf author clearing to signal, mute factory

parent 6e9ca349
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" ...@@ -2,6 +2,7 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3" __license__ = "AGPL v3"
from django.db.models.signals import post_save
import factory import factory
from common.faker import LazyRandEnum, fake from common.faker import LazyRandEnum, fake
...@@ -22,6 +23,7 @@ from submissions.constants import ( ...@@ -22,6 +23,7 @@ from submissions.constants import (
from submissions.models import Report from submissions.models import Report
@factory.django.mute_signals(post_save)
class ReportFactory(factory.django.DjangoModelFactory): class ReportFactory(factory.django.DjangoModelFactory):
class Meta: class Meta:
model = Report model = Report
......
...@@ -5,6 +5,8 @@ __license__ = "AGPL v3" ...@@ -5,6 +5,8 @@ __license__ = "AGPL v3"
import subprocess import subprocess
from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.fields import GenericRelation
from django.db import models from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse from django.urls import reverse
from django.utils.functional import cached_property from django.utils.functional import cached_property
...@@ -169,12 +171,7 @@ class Report(SubmissionRelatedObjectMixin, models.Model): ...@@ -169,12 +171,7 @@ class Report(SubmissionRelatedObjectMixin, models.Model):
new_report_nr = 1 new_report_nr = 1
self.report_nr = new_report_nr self.report_nr = new_report_nr
super_save = super().save(*args, **kwargs) return super().save(*args, **kwargs)
if self.pdf_report and self.anonymous:
clean_pdf(self.pdf_report.path)
return super_save
def get_absolute_url(self): def get_absolute_url(self):
"""Return url of the Report on the Submission detail page.""" """Return url of the Report on the Submission detail page."""
...@@ -323,3 +320,9 @@ class Report(SubmissionRelatedObjectMixin, models.Model): ...@@ -323,3 +320,9 @@ class Report(SubmissionRelatedObjectMixin, models.Model):
.order_by("submission__submission_date") .order_by("submission__submission_date")
.last() .last()
) )
@receiver(post_save, sender=Report)
def clean_anonymous_report_pdf(sender, instance, created, **kwargs):
if instance.pdf_report and instance.anonymous:
clean_pdf(instance.pdf_report.path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment