diff --git a/scipost_django/journals/templates/journals/author_affiliations.html b/scipost_django/journals/templates/journals/author_affiliations.html index 6577f4f2a4f9bb452ac784c75b119baa636c9f36..f277f632a28ecf97ab15d166840d88b9a05e4249 100644 --- a/scipost_django/journals/templates/journals/author_affiliations.html +++ b/scipost_django/journals/templates/journals/author_affiliations.html @@ -3,6 +3,7 @@ {% block pagetitle %}: Author Affiliations{% endblock pagetitle %} {% load bootstrap %} +{% load common_extras %} {% block breadcrumb %} <div class="breadcrumb-container"> @@ -22,32 +23,41 @@ <div class="col-12"> <h1 class="highlight">Author affiliations for <a href="{{ publication.get_absolute_url }}">{{ publication.doi_label }}</a></h1> <br> + <div> + <p>Can't find it in the selector? <a href="{% url 'organizations:organization_create' %}" target="_blank">Add a new organization to our database</a> (opens in new window)</p> + </div> - <h3>Current Author Affiliations:</h3> - <ul> - {% for auth in publication.authors.all %} - <li> - <div class="row"> - <div class="col-6"> - <h3>{{ auth }}</h3> - <ul> - {% for aff in auth.affiliations.all %} - <li>{{ aff }} <a href="{% url 'journals:author_affiliation_remove' doi_label=publication.doi_label pk=auth.pk organization_id=aff.id %}">remove</a></li> - {% empty %} - <li>No affiliation found</li> - {% endfor %} - </ul> - </div> - <div class="col-6"> - <a href="{% url 'journals:author_affiliation_update' doi_label=publication.doi_label pk=auth.pk %}">Add an affiliation</a> (at moment of publication) to this Author - </div> - </div> - </li> - {% empty %} - <li>No author relation found!</li> - {% endfor %} - </ul> - + <div class="d-flex flex-row gap-2"> + <form hx-post="{% url 'journals:author_affiliations' doi_label=publication.doi_label%}" id="add_affiliation_form" hx-swap="outerHTML"> + {% csrf_token %} + {{ form|bootstrap_inline }} + <input name="add" class="btn btn-primary" type="submit" value="Add Organization" form="add_affiliation_form"/> + </form> + <form action="{% url 'journals:author_affiliations' doi_label=publication.doi_label%}" id="submit_affiliation_form" method="POST"> + {% csrf_token %} + <input name="submit" class="btn btn-secondary" type="submit" value="Submit" form="submit_affiliation_form"/> + <input type="hidden" name="total_affiliations" value="{{ affiliation_texts|length }}"/> + </form> + </div> + + <br> + <h3>List of affiliations:</h3> + <table class = "ms-4" id="author_affiliations_list"> + <tr> + <th> </th> + <th class="ps-3"> # </th> + <th class="ps-2"> Affiliation Text </th> + <th class="ps-4"> Organization </th> + </tr> + {% for affiliation_tex, default_affiliation in affiliation_texts|zip_dj:default_affiliations %} + <tr> + <td> <input type="radio" name="checked_row_id" value="{{ forloop.counter }}" form = "add_affiliation_form" id="{{ forloop.counter }}" {% if forloop.counter == checked_row_id %}checked{% endif %}> </td> + <td class="ps-3"><label for="{{ forloop.counter }}">{{ forloop.counter }}.</label></td> + <td class="ps-2"><label for="{{ forloop.counter }}">{{affiliation_tex}}</label></td> + {% include "journals/author_affiliations_orgcell.html" with checked_row_id=forloop.counter organization=default_affiliation %} + </tr> + {% endfor %} + </table> </div> </div> @@ -55,5 +65,5 @@ {% block footer_script %} {{ block.super }} - {{ add_affiliation_form.media }} + {{ form.media }} {% endblock footer_script %} diff --git a/scipost_django/journals/templates/journals/author_affiliations_orgcell.html b/scipost_django/journals/templates/journals/author_affiliations_orgcell.html new file mode 100644 index 0000000000000000000000000000000000000000..f6752ba9907527a8e3e60e73a6c657b90510cebc --- /dev/null +++ b/scipost_django/journals/templates/journals/author_affiliations_orgcell.html @@ -0,0 +1,9 @@ +<td class="ps-4" id="organization_column_{{checked_row_id}}"> + <input type="hidden" value="{{organization.id}}" form="submit_affiliation_form" name="affiliation_id_{{checked_row_id}}"> + {% if organization is not None %} + <img src="{{ organization.country.flag }}" style="width:15px;" alt="{{ organization.country }} flag" title="{{organization.get_country_display}}" data-bs-toggle="tooltip"/> + <a href="{{ organization.get_absolute_url }}">{{ organization.name }} </a> + {% else %} + -- No affiliation -- + {% endif %} +</td> \ No newline at end of file diff --git a/scipost_django/journals/urls/general.py b/scipost_django/journals/urls/general.py index 2426b96fd20e717495eb751e00d7a7907fb2e0ed..9cb803b8f72aa1a488261e907de3c986b6cbd2a3 100644 --- a/scipost_django/journals/urls/general.py +++ b/scipost_django/journals/urls/general.py @@ -110,7 +110,7 @@ urlpatterns = [ ), path( "admin/<publication_doi_label:doi_label>/authoraffiliations/", - journals_views.AuthorAffiliationView.as_view(), + journals_views.author_affiliations, name="author_affiliations", ), path( diff --git a/scipost_django/journals/views.py b/scipost_django/journals/views.py index da564a497dedc822cd85d5255007368d378b9b57..d1d73433166c3748ab0ae20047927121c21876ec 100644 --- a/scipost_django/journals/views.py +++ b/scipost_django/journals/views.py @@ -6,6 +6,7 @@ from decimal import Decimal, getcontext import hashlib import json import os +import re from profiles.models import Profile import random import string @@ -659,6 +660,7 @@ class PublicationGrantsRemovalView(PermissionsMixin, DetailView): reverse("journals:update_grants", args=(self.object.doi_label,)) ) + class DraftPublicationCreateView(PermissionsMixin, CreateView): """ Create a draft of a Publication. @@ -905,7 +907,7 @@ def manage_metadata(request, doi_label=None): @permission_required("scipost.can_draft_publication", return_403=True) @transaction.atomic -def reset_authors(request, doi_label): +def reset_authors(request, doi_label: str) -> HttpResponse: publication = get_object_or_404(Publication, doi_label=doi_label) if not publication.is_draft and not request.user.has_perm( "can_publish_accepted_submission" @@ -1017,7 +1019,6 @@ def search_for_authors(publication_object: Publication) -> list: ): query_results = Profile.objects.search(tex_author) else: - print("Skipping search for author: ", tex_author) query_results = Profile.objects.filter( id=authors_metadata_table[i].profile.id ) @@ -1070,13 +1071,46 @@ class AuthorAffiliationView(PublicationMixin, PermissionsMixin, DetailView): Handle the author affiliations for a Publication. """ - permission_required = "scipost.can_draft_publication" - template_name = "journals/author_affiliations.html" - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context["add_affiliation_form"] = AuthorsTableOrganizationSelectForm() - return context +# permission_required = "scipost.can_draft_publication" +# template_name = "journals/author_affiliations.html" + +# form_class = AuthorsTableOrganizationSelectForm + + +def get_affiliations() -> dict: + # First we find the section where the affiliations exist. --TODO: Enable below for git integration. + # section = re.findall('TODO: AFFILIATIONS\n(.*?)\n%%%%%%%%%% END', paper, re.DOTALL)[0] + "%" # We add a % to the end to make sure the regex works. + section = ( + r"""{\bf 1} Martin Fisher School of Physics, Brandeis University, Waltham, Massachusetts 02453, USA +\\ +{\bf 2} California Institute of Technology, Pasadena, California 91125, USA""" + + "%" + ) + affids = re.findall( + r"\{\\bf (\d+)\}", section + ) # We look for affiliations based on the {\bf k} format. + if affids: + affids = [int(i) for i in affids] # We count the number of affiliations. + + if affids != list(range(1, len(affids) + 1)): + raise ValueError( + "Affiliation numbers not in correct order! Check the TeX file. Are they all present?" + ) + + affiliations = [] # We create a list of affiliations. + for k in affids: # Extract the affiliation text for each affiliation id. + aff = re.findall(rf"bf {k}}} (.*?)({{|\%)", section, re.DOTALL)[0][0] + aff = ( + aff.replace("\\", " ").replace(" ", " ").strip() + ) # Remove leading and trailing whitespaces. + + affiliations.append(aff) + return affiliations + else: # There is only one affiliation OR something went wrong. We return all as is. + return [ + section[:-1] + ] # We remove the % at the end (which was put for the other case to work). @permission_required("scipost.can_draft_publication", return_403=True)