From 8c538cb2290a4c2360f5dfe390ea99ffab03d6e5 Mon Sep 17 00:00:00 2001 From: SwoopDoable <swoop-doable.0v@icloud.com> Date: Fri, 13 Sep 2024 11:55:18 +0200 Subject: [PATCH] Add alternate metadata field for docx publications --- scipost_django/journals/forms.py | 12 +++++++++++- .../0136_publication_author_info_source.py | 18 ++++++++++++++++++ scipost_django/journals/models/publication.py | 4 ++++ scipost_django/production/models.py | 5 ++--- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 scipost_django/journals/migrations/0136_publication_author_info_source.py diff --git a/scipost_django/journals/forms.py b/scipost_django/journals/forms.py index 5dc20c62a..28c9184f2 100644 --- a/scipost_django/journals/forms.py +++ b/scipost_django/journals/forms.py @@ -612,6 +612,7 @@ class DraftPublicationForm(forms.ModelForm): "title", "author_list", "abstract", + "author_info_source", "acad_field", "specialties", "approaches", @@ -625,6 +626,7 @@ class DraftPublicationForm(forms.ModelForm): "submission_date": forms.DateInput(attrs={"type": "date"}), "acceptance_date": forms.DateInput(attrs={"type": "date"}), "publication_date": forms.DateInput(attrs={"type": "date"}), + "author_info_source": forms.Textarea(attrs={"rows": 1, "placeholder": "Required for docx files! Add a tex-like file with authors and affiliation information."}), } def __init__( @@ -667,6 +669,14 @@ class DraftPublicationForm(forms.ModelForm): else: self.fields["in_issue"].queryset = self.get_possible_issues() self.delete_secondary_fields() + + if self.submission: # For when creating the publication object. + repository = self.submission.production_stream.proofs_repository + else: # For when Updating the publication object. + repository = self.instance.proofs_repository + + if repository.fetch_tex(): + self.fields["author_info_source"].required = False def get_possible_issues(self): issues = Issue.objects.filter(until_date__gte=timezone.now()) @@ -725,7 +735,7 @@ class DraftPublicationForm(forms.ModelForm): if do_prefill: self.first_time_fill() # We cannot trust the author associations ordered in Submission. - self.instance.reset_author_associations() + self.instance.reset_author_associations() return self.instance diff --git a/scipost_django/journals/migrations/0136_publication_author_info_source.py b/scipost_django/journals/migrations/0136_publication_author_info_source.py new file mode 100644 index 000000000..3f76951ab --- /dev/null +++ b/scipost_django/journals/migrations/0136_publication_author_info_source.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.10 on 2024-09-02 13:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("journals", "0135_alter_publicationresource__type"), + ] + + operations = [ + migrations.AddField( + model_name="publication", + name="author_info_source", + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/scipost_django/journals/models/publication.py b/scipost_django/journals/models/publication.py index 503d4017c..5016779bb 100644 --- a/scipost_django/journals/models/publication.py +++ b/scipost_django/journals/models/publication.py @@ -182,6 +182,7 @@ class Publication(models.Model): doideposit_needs_updating = models.BooleanField(default=False) citedby = models.JSONField(default=dict, blank=True, null=True) number_of_citations = models.PositiveIntegerField(default=0) + author_info_source = models.TextField(blank=True, null=True) # To handle docx files better. # Date fields submission_date = models.DateField(verbose_name="submission date") @@ -618,6 +619,9 @@ class Publication(models.Model): @cached_property def tex_contents(self) -> str | None: + if self.author_info_source != "": # For docx files use author_info_source. + return self.author_info_source + return self.proofs_repository.fetch_tex() def construct_tex_author_info(self) -> tuple[list[str], list[list[int]]]: diff --git a/scipost_django/production/models.py b/scipost_django/production/models.py index ae05406e9..0ed51561c 100644 --- a/scipost_django/production/models.py +++ b/scipost_django/production/models.py @@ -16,6 +16,7 @@ from django.db.models import Value from django.db.models.functions import Concat from django.conf import settings import gitlab +import re from guardian.shortcuts import assign_perm, remove_perm @@ -551,9 +552,6 @@ class ProofsRepository(models.Model): except: return None - publication: "Publication" = self.stream.submission.publications.first() - publication_filename = publication.doi_label.replace(".", "_") + ".tex" - # Attempt to fetch the project from GitLab try: project = gl.projects.get(self.git_path) @@ -562,6 +560,7 @@ class ProofsRepository(models.Model): # Attempt to fetch the publication file try: + publication_filename = [file["name"] for file in project.repository_tree() if re.findall("\d+(_\d+)*.tex", file["name"])][0] publication_file = project.files.get( file_path=publication_filename, ref="main" ) -- GitLab