SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 41a3bd02 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add edadmin view to preallocate pubfracs from affiliations

parent 8dea2019
No related branches found
Tags 2023.04-01
No related merge requests found
......@@ -927,7 +927,9 @@ class BaseOrgPubFractionsFormSet(BaseModelFormSet):
form.is_valid()
norm += 1000 * form.cleaned_data.get("fraction", 0)
if norm != 1000:
raise forms.ValidationError("The fractions do not add up to one!")
raise forms.ValidationError(
f"The fractions do not add up to one! Getting {norm} / 1000"
)
OrgPubFractionsFormSet = modelformset_factory(
......
......@@ -28,6 +28,10 @@
<h3 class="highlight">Which Organizations supported the research in this publication?</h3>
<p>Please indicate <strong>which Organizations should be credited with supporting the research published in this publication</strong>.<br/>Data provided here is indicative and does not need to be extremely accurate.<br/>Note however that this data <strong>is used</strong> to set the suggested level of support from external Organizations which SciPost needs to remain sustainable.<br/><br/>The Organizations listed here appear as either host institutions for the authors, or as acknowledged funders.<br/>Is the list of Organizations incomplete? <a href="mailto:edadmin@{{ request.get_host }}?subject=Missing Organizations for {{ publication.doi_label }}&body=[Please provide the missing data here]">Please email EdAdmin with details</a>.</p>
{% if "edadmin" in user_roles %}
<p><span class="text-danger">EdAdmin</span>: <a href="{% url 'journals:preallocate_orgpubfractions_from_affiliations' doi_label=publication.doi_label %}">preallocate fractions based on author affiliations</a>
{% endif %}
<form method="post" action="{% url 'journals:allocate_orgpubfractions' doi_label=publication.doi_label %}">
{% csrf_token %}
{{ formset.management_form }}
......
......@@ -258,6 +258,11 @@ urlpatterns = [
journals_views.allocate_orgpubfractions,
name="allocate_orgpubfractions",
),
path(
"preallocate_orgpubfractions_from_affiliations/<publication_doi_label:doi_label>",
journals_views.preallocate_orgpubfractions_from_affiliations,
name="preallocate_orgpubfractions_from_affiliations",
),
path(
"request_pubfrac_check/<publication_doi_label:doi_label>",
journals_views.request_pubfrac_check,
......
......@@ -2,6 +2,7 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from decimal import Decimal, getcontext
import hashlib
import json
import os
......@@ -1280,6 +1281,35 @@ def allocate_orgpubfractions(request, doi_label):
return render(request, "journals/allocate_orgpubfractions.html", context)
@login_required
@permission_required("scipost.can_publish_accepted_submission", return_403=True)
def preallocate_orgpubfractions_from_affiliations(request, doi_label):
"""
Prefill the pubfractions based on the author affiliations.
"""
publication = get_object_or_404(Publication, doi_label=doi_label)
nr_authors = publication.authors.all().count()
# Reset all existing pubfracs to zero
OrgPubFraction.objects.filter(publication=publication).update(fraction=0)
fraction = {}
for org in publication.get_organizations():
fraction[org.id] = 0
for author in publication.authors.all():
nr_affiliations = author.affiliations.all().count()
for aff in author.affiliations.all():
fraction[aff.id] += 1.0/(nr_authors * nr_affiliations)
for org in publication.get_organizations():
OrgPubFraction.objects.filter(
publication=publication,
organization=org,
).update(fraction=Decimal(fraction[org.id]))
return redirect(reverse(
"journals:allocate_orgpubfractions",
kwargs={"doi_label": doi_label},
))
@login_required
@permission_required("scipost.can_publish_accepted_submission", return_403=True)
def request_pubfrac_check(request, doi_label):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment