diff --git a/journals/migrations/0037_publication_pubfractions_confirmed_by_authors.py b/journals/migrations/0037_publication_pubfractions_confirmed_by_authors.py new file mode 100644 index 0000000000000000000000000000000000000000..480588aea5798df098ca0e1290a28d36a14b9665 --- /dev/null +++ b/journals/migrations/0037_publication_pubfractions_confirmed_by_authors.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-18 18:27 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('journals', '0036_auto_20180918_1723'), + ] + + operations = [ + migrations.AddField( + model_name='publication', + name='pubfractions_confirmed_by_authors', + field=models.BooleanField(default=False), + ), + ] diff --git a/journals/models.py b/journals/models.py index 9a74c61832f2e3861f01cc423ac17d8c80931500..2051ae9c3d48e7df10ecb5dbeae6bc54034e37e3 100644 --- a/journals/models.py +++ b/journals/models.py @@ -7,7 +7,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.postgres.fields import JSONField from django.core.exceptions import ValidationError from django.db import models -from django.db.models import Avg, F +from django.db.models import Avg, Sum, F from django.utils import timezone from django.urls import reverse @@ -410,6 +410,7 @@ class Publication(models.Model): grants = models.ManyToManyField('funders.Grant', blank=True) funders_generic = models.ManyToManyField('funders.Funder', blank=True) # not linked to a grant institutions = models.ManyToManyField('affiliations.Institution', blank=True) + pubfractions_confirmed_by_authors = models.BooleanField(default=False) # Metadata metadata = JSONField(default={}, blank=True, null=True) @@ -537,6 +538,11 @@ class Publication(models.Model): def has_funding_statement(self): return 'funding_statement' in self.metadata and self.metadata['funding_statement'] + @property + def pubfractions_sum_to_1(self): + """ Checks that the support fractions sum up to one. """ + return self.pubfractions.aggregate(Sum('fraction'))['fraction__sum'] == 1 + @property def citation(self): """ @@ -608,7 +614,7 @@ class OrgPubFraction(models.Model): This data is used to compile publicly-displayed information on Organizations as well as to set suggested contributions from Partners. - To be set during production phase, based on information provided by the authors. + To be set (ideally) during production phase, based on information provided by the authors. """ organization = models.ForeignKey('partners.Organization', on_delete=models.CASCADE, related_name='pubfractions') diff --git a/journals/templates/journals/allocate_orgpubfractions.html b/journals/templates/journals/allocate_orgpubfractions.html index f0546e01eb584e8d17b73c9983a6c9731895b4ca..8e4d09eb5b602133c235c7b66c34891f245bf4c0 100644 --- a/journals/templates/journals/allocate_orgpubfractions.html +++ b/journals/templates/journals/allocate_orgpubfractions.html @@ -1,6 +1,6 @@ {% extends 'scipost/base.html' %} -{% block pagetitle %}: Allocate pub org fractions{% endblock pagetitle %} +{% block pagetitle %}: Allocate support fractions{% endblock pagetitle %} {% block breadcrumb %} <div class="container-outside header"> @@ -9,7 +9,7 @@ <a href="{% url 'journals:journals' %}" class="breadcrumb-item">Journals</a> <a href="{% url 'journals:manage_metadata' %}" class="breadcrumb-item">Administration</a> <a href="{% url 'journals:manage_metadata' doi_label=publication.doi_label %}" class="breadcrumb-item">{{ publication.citation }}</a> - <span class="breadcrumb-item active">Allocate pub org fractions</span> + <span class="breadcrumb-item active">Allocate support fractions</span> </nav> </div> </div> @@ -21,13 +21,14 @@ <div class="row"> <div class="col-12"> - <h1 class="highlight">Allocate funding fractions for <a href="{{ publication.get_absolute_url }}">{{ publication.doi_label }}</a></h1> + <h1 class="highlight">Allocate support fractions for <a href="{{ publication.get_absolute_url }}">{{ publication.doi_label }}</a></h1> {% include 'partials/journals/publication_li_content.html' with publication=publication %} <hr class="divider"> <h3 class="highlight">Which Organizations supported the research in this publication?</h3> <p>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.</p> + <form method="post" action="{% url 'journals:allocate_orgpubfractions' doi_label=publication.doi_label %}"> {% csrf_token %} {{ formset.management_form }} @@ -60,7 +61,7 @@ {% if formset.non_form_errors %} <h4 class="text-danger">Error: {{ formset.non_form_errors }}</h4> {% endif %} - <input type="submit" class="btn btn-primary" value="Save fractions"> + <input type="submit" class="btn btn-primary" value="Save/confirm fractions"> </form> <br/> <a href="{% url 'journals:manage_metadata' doi_label=publication.doi_label %}" class="ml-3 btn btn-link">Back to Admin for {{ publication.doi_label }}</a> diff --git a/journals/views.py b/journals/views.py index e316d9cd84a1698e71d54e1cd99ca26d5b3b62d6..c74dcfec0efea73f9f7f27d1d8fc6a474c08f646 100644 --- a/journals/views.py +++ b/journals/views.py @@ -737,9 +737,20 @@ def metadata_DOAJ_deposit(request, doi_label): kwargs={'doi_label': publication.doi_label})) -@permission_required('scipost.can_publish_accepted_submission', return_403=True) def allocate_orgpubfractions(request, doi_label): + """ + Set the relative support obtained from Organizations + for the research contained in a Publication. + + This view is accessible to EdAdmin as well as to the corresponding author + of the Publication. + """ publication = get_object_or_404(Publication, doi_label=doi_label) + if not request.user.is_authenticated: + raise Http404 + elif not (request.user == publication.accepted_submission.submitted_by.user or + request.user.has_perm('scipost.can_publish_accepted_submission')): + raise Http404 initial = [] if not publication.pubfractions.all().exists(): # Create new OrgPubFraction objects from existing data, spreading weight evenly @@ -751,6 +762,9 @@ def allocate_orgpubfractions(request, doi_label): queryset=publication.pubfractions.all()) if formset.is_valid(): formset.save() + if request.user == publication.accepted_submission.submitted_by.user: + publication.pubfractions_confirmed_by_authors = True + publication.save() messages.success(request, 'Funding fractions successfully allocated.') return redirect(publication.get_absolute_url()) context = { diff --git a/scipost/templates/partials/scipost/personal_page/publications.html b/scipost/templates/partials/scipost/personal_page/publications.html index 302090e22d865ec6c41654a8311462e886883fb5..4a10e24f855f92dff7dd5befa7e800f8347ff364 100644 --- a/scipost/templates/partials/scipost/personal_page/publications.html +++ b/scipost/templates/partials/scipost/personal_page/publications.html @@ -23,7 +23,13 @@ {% for pub in own_publications %} <li> <div class="card card-grey card-publication" id="{{pub.doi_label}}"> - {% include 'journals/_publication_card_content.html' with publication=pub current_user=request.user %} + {% include 'journals/_publication_card_content.html' with publication=pub current_user=request.user %} + {% if request.user == pub.accepted_submission.submitted_by.user %} + {% if not pub.pubfractions_confirmed_by_authors or not pub.pubfractions_sum_to_1 %} + + <h4 class="m-2"><a href="{% url 'journals:allocate_orgpubfractions' doi_label=pub.doi_label %}"><span class="text-danger">Intervention needed:</span> review support fractions</a></h4> + {% endif %} + {% endif %} </div> </li> {% empty %}