From 9876cf2160493b671d671e0dfc63a77c922826fb Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Fri, 14 Jul 2023 17:33:38 -0400 Subject: [PATCH 1/3] Allow associated publications to be added on the management page for published projects. --- physionet-django/console/forms.py | 17 ++++++++++++++ .../console/manage_published_project.html | 23 +++++++++++++++++++ physionet-django/console/views.py | 8 +++++++ 3 files changed, 48 insertions(+) diff --git a/physionet-django/console/forms.py b/physionet-django/console/forms.py index 6d66637160..b87549f046 100644 --- a/physionet-django/console/forms.py +++ b/physionet-django/console/forms.py @@ -27,6 +27,7 @@ PublishedAffiliation, PublishedAuthor, PublishedProject, + PublishedPublication, SubmissionStatus, exists_project_slug, ) @@ -707,6 +708,22 @@ def save(self): return contact +class PublishedProjectAddPublication(forms.ModelForm): + class Meta: + model = PublishedPublication + fields = ('citation', 'url') + + def __init__(self, project, *args, **kwargs): + super().__init__(*args, **kwargs) + self.project = project + + def save(self): + publication = super().save(commit=False) + publication.project = self.project + publication.save() + return publication + + class CreateLegacyAuthorForm(forms.ModelForm): """ Create an author for a legacy project. diff --git a/physionet-django/console/templates/console/manage_published_project.html b/physionet-django/console/templates/console/manage_published_project.html index 7b3902ea2e..de933752d6 100644 --- a/physionet-django/console/templates/console/manage_published_project.html +++ b/physionet-django/console/templates/console/manage_published_project.html @@ -49,6 +49,7 @@

@@ -67,6 +68,28 @@

Add an author

{% endif %} + +
+
+ Associated publication +
+
+ {% if project.publications.all %} + {% for publication in project.publications.all %} +

Citation: {{ publication.citation }}
+ URL: {{ publication.url }}

+ {% endfor %} + {% else %} +
+ {% include "inline_form_snippet.html" with form=publication_form %} + +
+ {% endif %} + +
+
+ +
Contact information diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index 769ba2b0b4..5298ff4baa 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -833,6 +833,7 @@ def manage_published_project(request, project_slug, version): contact_form = forms.PublishedProjectContactForm(project=project, instance=project.contact) legacy_author_form = forms.CreateLegacyAuthorForm(project=project) + publication_form = forms.PublishedProjectAddPublication(project=project) if request.method == 'POST': if any(x in request.POST for x in ['create_doi_core', @@ -914,6 +915,12 @@ def manage_published_project(request, project_slug, version): if contact_form.is_valid(): contact_form.save() messages.success(request, 'The contact information has been updated') + elif 'set_publication' in request.POST: + publication_form = forms.PublishedProjectAddPublication( + project=project, data=request.POST) + if publication_form.is_valid(): + publication_form.save() + messages.success(request, 'The associated publication has been added') elif 'set_legacy_author' in request.POST: legacy_author_form = forms.CreateLegacyAuthorForm(project=project, data=request.POST) @@ -957,6 +964,7 @@ def manage_published_project(request, project_slug, version): 'bulk_url_prefix': bulk_url_prefix, 'contact_form': contact_form, 'legacy_author_form': legacy_author_form, + 'publication_form': publication_form, 'can_make_zip': project.files.can_make_zip(), 'can_make_checksum': project.files.can_make_checksum(), }, From 86ffb33d57efbc8a172f3c34e1b45f5924147247 Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Sat, 23 Sep 2023 18:07:58 -0400 Subject: [PATCH 2/3] add clean method to prevent multiple publications. the PublishedPublication model allows multiple publications to be added to a single project, but by policy we only allow a single publication to be added. --- physionet-django/console/forms.py | 16 +++++++++++++--- physionet-django/console/views.py | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/physionet-django/console/forms.py b/physionet-django/console/forms.py index b87549f046..03e18881bf 100644 --- a/physionet-django/console/forms.py +++ b/physionet-django/console/forms.py @@ -708,7 +708,7 @@ def save(self): return contact -class PublishedProjectAddPublication(forms.ModelForm): +class AddPublishedPublicationForm(forms.ModelForm): class Meta: model = PublishedPublication fields = ('citation', 'url') @@ -717,10 +717,20 @@ def __init__(self, project, *args, **kwargs): super().__init__(*args, **kwargs) self.project = project - def save(self): + def clean(self): + cleaned_data = super().clean() + existing_publication = PublishedPublication.objects.filter(project=self.project).first() + + if existing_publication: + raise forms.ValidationError("A publication already exists for this project.") + + return cleaned_data + + def save(self, commit=True): publication = super().save(commit=False) publication.project = self.project - publication.save() + if commit: + publication.save() return publication diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index 5298ff4baa..c03ec5725f 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -833,7 +833,7 @@ def manage_published_project(request, project_slug, version): contact_form = forms.PublishedProjectContactForm(project=project, instance=project.contact) legacy_author_form = forms.CreateLegacyAuthorForm(project=project) - publication_form = forms.PublishedProjectAddPublication(project=project) + publication_form = forms.AddPublishedPublicationForm(project=project) if request.method == 'POST': if any(x in request.POST for x in ['create_doi_core', @@ -916,7 +916,7 @@ def manage_published_project(request, project_slug, version): contact_form.save() messages.success(request, 'The contact information has been updated') elif 'set_publication' in request.POST: - publication_form = forms.PublishedProjectAddPublication( + publication_form = forms.AddPublishedPublicationForm( project=project, data=request.POST) if publication_form.is_valid(): publication_form.save() From 2832a819c352987da875ad9300f5e96f44d3024a Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Sat, 23 Sep 2023 22:03:38 -0400 Subject: [PATCH 3/3] remove unused and repeated imports. --- physionet-django/console/forms.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/physionet-django/console/forms.py b/physionet-django/console/forms.py index 03e18881bf..c085efaf12 100644 --- a/physionet-django/console/forms.py +++ b/physionet-django/console/forms.py @@ -1,10 +1,5 @@ -import pdb import re -from django.forms.widgets import RadioSelect - -from django.forms.widgets import RadioSelect - from console.utility import generate_doi_payload, register_doi from dal import autocomplete from django import forms