From 3340f8bf1c340b551050ebb475a8f518d912ad2f Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Mon, 8 Apr 2024 15:07:48 +0200 Subject: [PATCH] alter journal acceptance_criteria to json rename verbose name of approaches --- ...er_journal_acceptance_criteria_and_more.py | 106 ++++++++++++++++++ scipost_django/journals/models/journal.py | 14 ++- scipost_django/journals/models/publication.py | 1 - scipost_django/submissions/forms/__init__.py | 14 ++- ...mission_acceptance_elaboration_and_more.py | 38 +++++++ .../submissions/models/submission.py | 3 +- .../0016_alter_thesislink_approaches.py | 33 ++++++ scipost_django/theses/models.py | 1 - 8 files changed, 200 insertions(+), 10 deletions(-) create mode 100644 scipost_django/journals/migrations/0131_alter_journal_acceptance_criteria_and_more.py create mode 100644 scipost_django/submissions/migrations/0151_submission_acceptance_elaboration_and_more.py create mode 100644 scipost_django/theses/migrations/0016_alter_thesislink_approaches.py diff --git a/scipost_django/journals/migrations/0131_alter_journal_acceptance_criteria_and_more.py b/scipost_django/journals/migrations/0131_alter_journal_acceptance_criteria_and_more.py new file mode 100644 index 000000000..bb2a51883 --- /dev/null +++ b/scipost_django/journals/migrations/0131_alter_journal_acceptance_criteria_and_more.py @@ -0,0 +1,106 @@ +# Generated by Django 4.2.10 on 2024-04-08 12:24 + +import json +import re +from django.db import migrations, models +import scipost.fields + + +def convert_acceptance_criteria_text_to_json(apps, schema_editor): + Journal = apps.get_model("journals", "Journal") + for journal in Journal.objects.all(): + previous_acceptance_criteria = journal.acceptance_criteria + acceptance_criteria = {"preamble": "", "sections": []} + + preamble = re.match( + r"^(.+?)(?:\*\*|$)", previous_acceptance_criteria, re.DOTALL + ) + if preamble: + acceptance_criteria["preamble"] = preamble.group(0).strip() + + for title, criteria in re.findall( + r"\*\*(.*?)\*\*\r\n(.*?)(?:\r\n\r\n|$)", + previous_acceptance_criteria, + re.DOTALL, + ): + section = { + "title": title, + "type": ( + "expectations" + if "expectations" in title.lower() + else "general_acceptance" + ), + "criteria": { + str(i): criterion.strip() + for i, criterion in enumerate( + re.findall( + r"(?:#\. |\*)?(.+?)$", criteria.strip(), re.MULTILINE + ) + ) + }, + } + + acceptance_criteria["sections"].append(section) + + journal.acceptance_criteria = json.dumps(acceptance_criteria) + journal.save() + + +class Migration(migrations.Migration): + dependencies = [ + ("journals", "0130_remove_publication_pubfractions_confirmed_by_authors"), + ] + + operations = [ + migrations.RunPython( + convert_acceptance_criteria_text_to_json, + reverse_code=migrations.RunPython.noop, + ), + migrations.AlterField( + model_name="journal", + name="acceptance_criteria", + field=models.JSONField( + default={ + "preamble": "Text before the list(s)", + "sections": [ + { + "criteria": { + "1": "First criterion", + "2": "Second criterion", + }, + "title": "First section", + "type": "expectations", + }, + { + "criteria": { + "1": "First criterion", + "2": "Second criterion", + }, + "title": "Second section", + "type": "general_acceptance", + }, + ], + } + ), + ), + migrations.AlterField( + model_name="publication", + name="approaches", + field=scipost.fields.ChoiceArrayField( + base_field=models.CharField( + choices=[ + ("theoretical", "Theoretical"), + ("experimental", "Experimental"), + ("computational", "Computational"), + ("phenomenological", "Phenomenological"), + ("observational", "Observational"), + ("clinical", "Clinical"), + ], + max_length=24, + ), + blank=True, + null=True, + size=None, + ), + ), + ] diff --git a/scipost_django/journals/models/journal.py b/scipost_django/journals/models/journal.py index 97b488615..d25e9eb28 100644 --- a/scipost_django/journals/models/journal.py +++ b/scipost_django/journals/models/journal.py @@ -3,6 +3,7 @@ __license__ = "AGPL v3" import datetime +import json from django.db import models from django.db.models import Avg, F @@ -108,9 +109,18 @@ class Journal(models.Model): description = models.TextField(default="[To be filled in; you can use markup]") scope = models.TextField(default="[To be filled in; you can use markup]") content = models.TextField(default="[To be filled in; you can use markup]") - acceptance_criteria = models.TextField( - default="[To be filled in; you can use markup]" + acceptance_criteria = models.JSONField( + default=json.loads( + """{"preamble": "Text before the list(s)", \ + "sections": [\ + {"type":"expectations", "title": "First section", \ + "criteria": {"1": "First criterion", "2": "Second criterion"}},\ + {"type": "general_acceptance", "title": "Second section", \ + "criteria": {"1": "First criterion", "2": "Second criterion"}}\ + ]}""" + ) ) + submission_insert = models.TextField( blank=True, null=True, default="[Optional; you can use markup]" ) diff --git a/scipost_django/journals/models/publication.py b/scipost_django/journals/models/publication.py index 31b6aca32..d1c9463fe 100644 --- a/scipost_django/journals/models/publication.py +++ b/scipost_django/journals/models/publication.py @@ -148,7 +148,6 @@ class Publication(models.Model): models.CharField(max_length=24, choices=SCIPOST_APPROACHES), blank=True, null=True, - verbose_name="approach(es) [optional]", ) cc_license = models.CharField(max_length=32, choices=CC_LICENSES, default=CCBY4) diff --git a/scipost_django/submissions/forms/__init__.py b/scipost_django/submissions/forms/__init__.py index 32a3935bc..92b3ff2dc 100644 --- a/scipost_django/submissions/forms/__init__.py +++ b/scipost_django/submissions/forms/__init__.py @@ -1329,7 +1329,7 @@ class SubmissionForm(forms.ModelForm): "Please submit the processed .pdf (not the source files; " "these will only be required at the post-acceptance proofs stage)" ), - required=False, + required=True, ) agree_to_terms = forms.BooleanField( required=False, @@ -1380,12 +1380,12 @@ class SubmissionForm(forms.ModelForm): "remarks_for_editors", "referees_suggested", "referees_flagged", - "preprint_file", "data_repository_url", "code_repository_url", "code_name", "code_version", "code_license", + "preprint_file", "agree_to_terms", ] widgets = { @@ -1394,14 +1394,18 @@ class SubmissionForm(forms.ModelForm): "is_resubmission_of": forms.HiddenInput(), "thread_hash": forms.HiddenInput(), "code_repository_url": forms.TextInput( - attrs={"placeholder": "If applicable; please give the full URL"} + attrs={ + "placeholder": "Optional: the full URL to the code repository, if applicable" + } ), "data_repository_url": forms.TextInput( - attrs={"placeholder": "If applicable; please give the full URL"} + attrs={ + "placeholder": "Optional: the full URL to the data repository, if applicable" + } ), "remarks_for_editors": forms.Textarea( attrs={ - "placeholder": "Any private remarks (for the editors only)", + "placeholder": "Optional: any private remarks (for the editors only)", "rows": 5, } ), diff --git a/scipost_django/submissions/migrations/0151_submission_acceptance_elaboration_and_more.py b/scipost_django/submissions/migrations/0151_submission_acceptance_elaboration_and_more.py new file mode 100644 index 000000000..47bbe8bee --- /dev/null +++ b/scipost_django/submissions/migrations/0151_submission_acceptance_elaboration_and_more.py @@ -0,0 +1,38 @@ +# Generated by Django 4.2.10 on 2024-03-28 11:53 + +from django.db import migrations, models +import scipost.fields + + +class Migration(migrations.Migration): + dependencies = [ + ("submissions", "0150_submission_code_metadata"), + ] + + operations = [ + migrations.AddField( + model_name="submission", + name="acceptance_elaboration", + field=models.TextField(blank=True, default=""), + ), + migrations.AlterField( + model_name="submission", + name="approaches", + field=scipost.fields.ChoiceArrayField( + base_field=models.CharField( + choices=[ + ("theoretical", "Theoretical"), + ("experimental", "Experimental"), + ("computational", "Computational"), + ("phenomenological", "Phenomenological"), + ("observational", "Observational"), + ("clinical", "Clinical"), + ], + max_length=24, + ), + blank=True, + null=True, + size=None, + ), + ), + ] diff --git a/scipost_django/submissions/models/submission.py b/scipost_django/submissions/models/submission.py index 0ada8a726..8c3671802 100644 --- a/scipost_django/submissions/models/submission.py +++ b/scipost_django/submissions/models/submission.py @@ -269,7 +269,6 @@ class Submission(models.Model): models.CharField(max_length=24, choices=SCIPOST_APPROACHES), blank=True, null=True, - verbose_name="approach(es) [optional]", ) editor_in_charge = models.ForeignKey( "scipost.Contributor", @@ -409,6 +408,8 @@ class Submission(models.Model): latest_activity = models.DateTimeField(auto_now=True) update_search_index = models.BooleanField(default=True) + acceptance_elaboration = models.TextField(blank=True, default="") + objects = SubmissionQuerySet.as_manager() # Temporary diff --git a/scipost_django/theses/migrations/0016_alter_thesislink_approaches.py b/scipost_django/theses/migrations/0016_alter_thesislink_approaches.py new file mode 100644 index 000000000..31df84ce4 --- /dev/null +++ b/scipost_django/theses/migrations/0016_alter_thesislink_approaches.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.10 on 2024-03-28 11:53 + +from django.db import migrations, models +import scipost.fields + + +class Migration(migrations.Migration): + dependencies = [ + ("theses", "0015_auto_20200927_1430"), + ] + + operations = [ + migrations.AlterField( + model_name="thesislink", + name="approaches", + field=scipost.fields.ChoiceArrayField( + base_field=models.CharField( + choices=[ + ("theoretical", "Theoretical"), + ("experimental", "Experimental"), + ("computational", "Computational"), + ("phenomenological", "Phenomenological"), + ("observational", "Observational"), + ("clinical", "Clinical"), + ], + max_length=24, + ), + blank=True, + null=True, + size=None, + ), + ), + ] diff --git a/scipost_django/theses/models.py b/scipost_django/theses/models.py index 49bd18e0e..01222027a 100644 --- a/scipost_django/theses/models.py +++ b/scipost_django/theses/models.py @@ -40,7 +40,6 @@ class ThesisLink(models.Model): models.CharField(max_length=24, choices=SCIPOST_APPROACHES), blank=True, null=True, - verbose_name="approach(es) [optional]", ) open_for_commenting = models.BooleanField(default=True) title = models.CharField(max_length=300, verbose_name="title") -- GitLab