diff --git a/funders/models.py b/funders/models.py index b0cba639a76892890c968812958aae7be5e62bd7..5ef9a4119c2a97da0fd36c758998004b93cf94e2 100644 --- a/funders/models.py +++ b/funders/models.py @@ -1,4 +1,7 @@ from django.db import models +from django.db.models import Q + +from journals.models import Publication class Funder(models.Model): @@ -19,6 +22,10 @@ class Funder(models.Model): result += ' (%s)' % self.acronym return result + def all_related_publications(self): + return Publication.objects.filter( + Q(funders_generic=self) | Q(grants__funder=self)).distinct() + class Grant(models.Model): """ @@ -26,7 +33,7 @@ class Grant(models.Model): In a Publication's metadata, all grants are listed in the Crossmark part of the metadata. """ - funder = models.ForeignKey(Funder, on_delete=models.CASCADE) + funder = models.ForeignKey('funders.Funder', on_delete=models.CASCADE) number = models.CharField(max_length=64) recipient_name = models.CharField(max_length=64, blank=True, null=True) recipient = models.ForeignKey('scipost.Contributor', blank=True, null=True, diff --git a/funders/templates/funders/funder_details.html b/funders/templates/funders/funder_details.html new file mode 100644 index 0000000000000000000000000000000000000000..cbb87326329e6355de796200919563e75fd01ed0 --- /dev/null +++ b/funders/templates/funders/funder_details.html @@ -0,0 +1,22 @@ +{% extends 'scipost/base.html' %} + +{% block pagetitle %}: Funder details{% endblock pagetitle %} + +{% load bootstrap %} + +{% block content %} + +<h1 class="highlight">Funder {{ funder.name }}</h1> + + +<h3>All Publications related to this Funder</h3> +<ul> + {% for publication in funder.all_related_publications %} + <li><a href="{{ publication.get_absolute_url }}">{{ publication }}</a></li> + {% empty %} + <li>No publications</li> + {% endfor %} +</ul> + + +{% endblock content %} diff --git a/funders/templates/funders/funders.html b/funders/templates/funders/funders.html index 1c6af178de2a883fbc15f36607d03268df0eb6d4..e3a3d70d3a27733024f34670ef93f192efdf83b7 100644 --- a/funders/templates/funders/funders.html +++ b/funders/templates/funders/funders.html @@ -64,11 +64,11 @@ </thead> <tbody id="accordion" role="tablist" aria-multiselectable="true"> {% for funder in funders %} - <tr data-toggle="collapse" data-parent="#accordion" href="#collapse{{ funder.id }}" aria-expanded="true" aria-controls="collapse{{ funder.id }}" style="cursor: pointer;"> + <tr> <td>{{ funder.name }}</td> <td>{{ funder.acronym }}</td> <td>{{ funder.identifier }}</td> - <td><a href="">See all Publications for Funder</a></td> + <td><a href="{% url 'funders:funder_publications' funder.id %}">See all Publications for Funder</a></td> </tr> {% empty %} <tr> @@ -110,7 +110,7 @@ </thead> <tbody id="accordion" role="tablist" aria-multiselectable="true"> {% for grant in grants %} - <tr data-toggle="collapse" data-parent="#accordion" href="#collapse{{ grant.id }}" aria-expanded="true" aria-controls="collapse{{ grant.id }}" style="cursor: pointer;"> + <tr> <td>{{ grant.funder.name }}</td> {% if grant.recipient %} <td>{{ grant.recipient }}</td> diff --git a/funders/urls.py b/funders/urls.py index abc0e82874c1f25ec1de7352335f25d13e1d9166..b424202a907b91320ab7dddbbb75d4e3d08a2376 100644 --- a/funders/urls.py +++ b/funders/urls.py @@ -7,5 +7,7 @@ urlpatterns = [ url(r'^query_crossref_for_funder$', views.query_crossref_for_funder, name='query_crossref_for_funder'), url(r'^funders/add$', views.add_funder, name='add_funder'), + url(r'^funders/(?P<funder_id>[0-9]+)/$', views.funder_publications, + name='funder_publications'), url(r'^grants/add$', views.add_grant, name='add_grant'), ] diff --git a/funders/views.py b/funders/views.py index dbcb1cc49945bb296af144881b190848d42b4438..8a2593f66dbad45d914f89e3efd0150c15f8749d 100644 --- a/funders/views.py +++ b/funders/views.py @@ -4,7 +4,7 @@ import json from django.contrib import messages from django.contrib.auth.decorators import permission_required from django.core.urlresolvers import reverse -from django.shortcuts import render, redirect +from django.shortcuts import get_object_or_404, render, redirect from .models import Funder, Grant from .forms import FunderRegistrySearchForm, FunderForm, GrantForm @@ -53,6 +53,16 @@ def add_funder(request): return redirect(reverse('funders:funders')) +@permission_required('scipost.can_view_all_funding_info', raise_exception=True) +def funder_publications(request, funder_id): + """ + See details of specific Funder. + """ + funder = get_object_or_404(Funder, id=funder_id) + context = {'funder': funder} + return render(request, 'funders/funder_details.html', context) + + @permission_required('scipost.can_publish_accepted_submission', raise_exception=True) def add_grant(request): grant_form = GrantForm(request.POST or None) @@ -63,14 +73,3 @@ def add_grant(request): elif grant_form.has_changed(): messages.warning(request, 'The form was invalidly filled (grant already exists?).') return redirect(reverse('funders:funders')) - - -@permission_required('scipost.can_view_all_funding_info', raise_exception=True) -def publication_per_funder(request): - funders = Funder.objects.all() - form = FunderRegistrySearchForm() - grants = Grant.objects.all() - grant_form = GrantForm() - context = {'form': form, 'funders': funders, - 'grants': grants, 'grant_form': grant_form} - return render(request, 'funders/funders.html', context) diff --git a/journals/models.py b/journals/models.py index c226cfb25aa772d38c17b6f8ee7d62e06c6c042b..f32b6386af8fc7c9c2e0241af54f67bd41711888 100644 --- a/journals/models.py +++ b/journals/models.py @@ -154,8 +154,9 @@ class Publication(models.Model): abstract = models.TextField() pdf_file = models.FileField(upload_to='UPLOADS/PUBLICATIONS/%Y/%m/', max_length=200) cc_license = models.CharField(max_length=32, choices=CC_LICENSES, default=CCBY4) - grants = models.ManyToManyField('funders.Grant', blank=True) - funders_generic = models.ManyToManyField('funders.Funder', blank=True) # not linked to a grant + grants = models.ManyToManyField('funders.Grant', blank=True, related_name="publications") + funders_generic = models.ManyToManyField('funders.Funder', blank=True, + related_name="publications") # not linked to a grant metadata = JSONField(default={}, blank=True, null=True) metadata_xml = models.TextField(blank=True, null=True) # for Crossref deposit latest_metadata_update = models.DateTimeField(blank=True, null=True) diff --git a/scipost/management/commands/add_groups_and_permissions.py b/scipost/management/commands/add_groups_and_permissions.py index 188cfc787e2c90035a8c035f2b58116452227c70..f94c680845f9d5a85f29aa35bb9b238e1e9124f3 100644 --- a/scipost/management/commands/add_groups_and_permissions.py +++ b/scipost/management/commands/add_groups_and_permissions.py @@ -245,6 +245,10 @@ class Command(BaseCommand): codename='can_publish_accepted_submission', name='Can publish accepted submission', content_type=content_type) + can_view_all_funding_info, created = Permission.objects.get_or_create( + codename='can_view_all_funding_info', + name='Can view all Funders info', + content_type=content_type) # Documentation can_view_docs_scipost, created = Permission.objects.get_or_create( @@ -312,6 +316,7 @@ class Command(BaseCommand): can_view_production, can_view_timesheets, can_publish_accepted_submission, + can_view_all_funding_info, can_attend_VGMs, can_manage_reports, can_assign_production_supervisor,