From b78b87ecfeabd2fc12b5d6d141da90339b6444c7 Mon Sep 17 00:00:00 2001 From: Esther Verreau Date: Wed, 25 Feb 2026 14:58:11 -0600 Subject: [PATCH] update for ror affiliations --- templates/back_content/author_form.html | 74 ++++------------- .../back_content/elements/add_new_author.html | 46 ++++++++++ views.py | 83 ++++++++----------- 3 files changed, 96 insertions(+), 107 deletions(-) create mode 100644 templates/back_content/elements/add_new_author.html diff --git a/templates/back_content/author_form.html b/templates/back_content/author_form.html index ef10fd8..cfc0ba8 100644 --- a/templates/back_content/author_form.html +++ b/templates/back_content/author_form.html @@ -17,71 +17,25 @@

Article Authors

- {% if frozen_author %} - Add Author - {% else %} - Add Author - {% endif %}
-
-
- {% csrf_token %} - - - - - - - - - - - - - - {% for f_author in article.frozen_authors %} - - - - - - - - - - {% endfor %} - -
NameEmailDisplay Email Link?InstitutionEditDelete
{{ f_author.full_name|se_can_see_pii:article }}{{ f_author.email|se_can_see_pii:article }}{{ f_author.display_email|bool_fa }}{{ f_author.institution|se_can_see_pii:article }}{% if can_see_pii %} -  Edit - {% else %} - Author data cannot be edited - {% endif %} - - - {% csrf_token %} - - -
-
- - - -
- +
+
+

{% trans "You can add an author by clicking the button below. This will open a popup modal for you to complete their details. If you do not have a legitimate email address for this author use @journal.com as a prefix for their email address and Janeway will ignore it." %}

+ {% trans "Add New Author" %} + {% include "back_content/elements/add_new_author.html" %} +

{% trans "If you know of an existing author, you can search for them." %}

+ Search Accounts for Authors + +
+
+

{% trans "Current Authors" %}

+ {% include "elements/current_authors.html" %} +
-{% include "admin/elements/submission/edit_author.html" %} +{% include "back_content/elements/add_new_author.html" %} {% endblock body %} {% block js %} diff --git a/templates/back_content/elements/add_new_author.html b/templates/back_content/elements/add_new_author.html new file mode 100644 index 0000000..b19e8fd --- /dev/null +++ b/templates/back_content/elements/add_new_author.html @@ -0,0 +1,46 @@ +{% load foundation %} +{% load i18n %} + +
+
+
+

 {% trans "Add New Author" %}

+
+
+ + {% include "admin/elements/forms/errors.html" with form=form %} +
+ {% csrf_token %} +
+
+ {% include "admin/elements/forms/field.html" with field=form.first_name %} + {% include "admin/elements/forms/field.html" with field=form.middle_name %} + {% include "admin/elements/forms/field.html" with field=form.last_name %} +
+
+ {% include "admin/elements/forms/field.html" with field=form.name_prefix %} + {% include "admin/elements/forms/field.html" with field=form.name_suffix %} + {% include "admin/elements/forms/field.html" with field=form.is_corporate %} +
+
+ {% include "admin/elements/forms/field.html" with field=form.frozen_email %} + {% include "admin/elements/forms/field.html" with field=form.display_email %} +
+
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/views.py b/views.py index f56151b..483ee44 100644 --- a/views.py +++ b/views.py @@ -17,7 +17,7 @@ FrozenAuthor, STAGE_PUBLISHED) from submission.forms import FileDetails, EditFrozenAuthor -from submission.logic import get_author +from submission.logic import add_new_author_from_form, get_credit_form from production.forms import GalleyForm from production.logic import (save_galley, @@ -126,48 +126,36 @@ def add_authors(request, article_id): pk=article_id, journal=request.journal, ) - - frozen_author, modal, author_form = None, None, EditFrozenAuthor() - if request.GET.get('author'): - frozen_author, modal = get_author(request, article) - author_form = EditFrozenAuthor(instance=frozen_author) - elif request.GET.get('modal') == 'author': - modal = 'author' - + author_form = EditFrozenAuthor() + modal = None if request.method == "POST": - if 'author' in request.POST: - author_form = EditFrozenAuthor( - request.POST, - instance=frozen_author, + if 'add_author' in request.POST: + add_new_author_from_form( + request, + article, ) - - if author_form.is_valid(): - saved_author = author_form.save() - saved_author.article = article - saved_author.save() - messages.add_message( + return redirect(reverse('bc_add_authors', kwargs={"article_id": article.pk})) + elif 'remove_author' in request.POST: + author_pk = request.POST.get('remove_author', None) + if author_pk: + author_to_remove = get_object_or_404( + FrozenAuthor, + pk=author_pk, + ) + author_to_remove.delete() + if author_to_remove.author == article.correspondence_author: + article.correspondence_author = None + article.save() + messages.success( request, - messages.SUCCESS, - _('Author {author_name} updated.').format( - author_name=saved_author.full_name(), - ), + f'{author_to_remove} removed from article.', + ) + else: + messages.warning( + request, + f'No author ID provided.', ) - return redirect(reverse('bc_add_authors', kwargs={"article_id": article.pk})) - elif 'delete' in request.POST: - frozen_author_id = request.POST.get('delete') - frozen_author = get_object_or_404( - FrozenAuthor, - pk=frozen_author_id, - article=article, - article__journal=request.journal, - ) - frozen_author.delete() - messages.add_message( - request, - messages.SUCCESS, - _('Frozen Author deleted.'), - ) return redirect(reverse('bc_add_authors', kwargs={"article_id": article.pk})) else: if "continue" in request.POST: @@ -177,11 +165,16 @@ def add_authors(request, article_id): else: return redirect(reverse('bc_index')) + authors = [] + for author, credits in article.authors_and_credits().items(): + credit_form = get_credit_form(request, author) + authors.append((author, credits, credit_form)) + context = { 'article': article, - 'author_form': author_form, + 'form': author_form, "modal": modal, - 'frozen_author': frozen_author, + "authors": authors, } return render(request, "back_content/author_form.html", context) @@ -406,13 +399,9 @@ def post(self, request, *args, **kwargs): pk=author_id, ) if author in self.get_queryset(): - self.article.authors.add(author) - ArticleAuthorOrder.objects.get_or_create( - article=self.article, - author=author, - defaults={ - 'order': self.article.next_author_sort(), - } + author, _created = FrozenAuthor.get_or_snapshot_if_email_found( + author.email, + self.article, ) messages.success( request,