diff --git a/peachjam/migrations/0156_publicationfile.py b/peachjam/migrations/0156_publicationfile.py index c9631a898..c09899b9e 100644 --- a/peachjam/migrations/0156_publicationfile.py +++ b/peachjam/migrations/0156_publicationfile.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.16 on 2024-09-11 14:00 +# Generated by Django 4.2.16 on 2024-09-11 14:44 import django.db.models.deletion from django.db import migrations, models @@ -61,6 +61,14 @@ class Migration(migrations.Migration): verbose_name="trusted URL", ), ), + ( + "use_source_file", + models.BooleanField( + default=False, + help_text="Set to True if the source file on the same document can be used instead", + verbose_name="use source file", + ), + ), ( "document", models.OneToOneField( diff --git a/peachjam/models/core_document_model.py b/peachjam/models/core_document_model.py index eb3bf48b1..21cb3652b 100644 --- a/peachjam/models/core_document_model.py +++ b/peachjam/models/core_document_model.py @@ -911,6 +911,13 @@ class PublicationFile(AttachmentAbstractModel): trusted_url = models.URLField( _("trusted URL"), max_length=2048, null=True, blank=True ) + use_source_file = models.BooleanField( + _("use source file"), + default=False, + help_text=_( + "Set to True if the source file on the same document can be used instead" + ), + ) class Meta: verbose_name = _("publication file") diff --git a/peachjam/views/documents.py b/peachjam/views/documents.py index 66e2ce11b..118767094 100644 --- a/peachjam/views/documents.py +++ b/peachjam/views/documents.py @@ -135,6 +135,13 @@ def render_to_response(self, context, **response_kwargs): # TODO: review all of this if hasattr(self.object, "publication_file"): publication_file = self.object.publication_file + if publication_file.use_source_file: + return redirect( + reverse( + "document_source", + kwargs={"frbr_uri": self.object.expression_frbr_uri[1:]}, + ) + ) # don't do anything if it's not a PDF if publication_file.mimetype == "application/pdf": # if the publication file is remote, just redirect there