Skip to content

Commit

Permalink
Merge pull request #2045 from MIT-LCP/tp/add_associated_paper
Browse files Browse the repository at this point in the history
Allow an associated publication to be added on the management page for published projects
  • Loading branch information
tompollard authored Oct 5, 2023
2 parents f71a607 + 2832a81 commit 6c3d475
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
32 changes: 27 additions & 5 deletions physionet-django/console/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,6 +22,7 @@
PublishedAffiliation,
PublishedAuthor,
PublishedProject,
PublishedPublication,
SubmissionStatus,
exists_project_slug,
)
Expand Down Expand Up @@ -707,6 +703,32 @@ def save(self):
return contact


class AddPublishedPublicationForm(forms.ModelForm):
class Meta:
model = PublishedPublication
fields = ('citation', 'url')

def __init__(self, project, *args, **kwargs):
super().__init__(*args, **kwargs)
self.project = project

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
if commit:
publication.save()
return publication


class CreateLegacyAuthorForm(forms.ModelForm):
"""
Create an author for a legacy project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h4 class="card-title"><a href="{% url 'published_project' project.slug project.
</div>
</div>
</div>

<!-- legacy project management -->
{% if project.is_legacy %}
<div class="card mb-3">
Expand All @@ -67,6 +68,28 @@ <h3>Add an author</h3>
</div>
{% endif %}

<!-- Associated publication -->
<div class="card mb-3">
<div class="card-header">
Associated publication
</div>
<div class="card-body">
{% if project.publications.all %}
{% for publication in project.publications.all %}
<p><strong>Citation</strong>: {{ publication.citation }}<br />
<strong>URL</strong>: {{ publication.url }}</p>
{% endfor %}
{% else %}
<form method="POST" id="publication_form">
{% include "inline_form_snippet.html" with form=publication_form %}
<button class="btn btn-primary btn-fixed" name="set_publication" type="submit">Add publication</button>
</form>
{% endif %}

</div>
</div>


<div class="card mb-3">
<div class="card-header">
Contact information
Expand Down
8 changes: 8 additions & 0 deletions physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.AddPublishedPublicationForm(project=project)

if request.method == 'POST':
if any(x in request.POST for x in ['create_doi_core',
Expand Down Expand Up @@ -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.AddPublishedPublicationForm(
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)
Expand Down Expand Up @@ -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(),
},
Expand Down

0 comments on commit 6c3d475

Please sign in to comment.