Skip to content

Commit

Permalink
Allow associated publications to be added on the management page for …
Browse files Browse the repository at this point in the history
…published projects.
  • Loading branch information
tompollard committed Jul 14, 2023
1 parent 40dc4e0 commit ed2b5cc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions physionet-django/console/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
PublishedAffiliation,
PublishedAuthor,
PublishedProject,
PublishedPublication,
exists_project_slug,
)
from project.projectfiles import ProjectFiles
Expand Down Expand Up @@ -705,6 +706,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.
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.PublishedProjectAddPublication(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.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)
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': ProjectFiles().can_make_zip(),
'can_make_checksum': ProjectFiles().can_make_checksum(),
},
Expand Down

0 comments on commit ed2b5cc

Please sign in to comment.