SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 759b55de authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Add funders detail page

parent baf52cf2
No related branches found
No related tags found
No related merge requests found
from django.db import models from django.db import models
from django.db.models import Q
from journals.models import Publication
class Funder(models.Model): class Funder(models.Model):
...@@ -19,6 +22,10 @@ class Funder(models.Model): ...@@ -19,6 +22,10 @@ class Funder(models.Model):
result += ' (%s)' % self.acronym result += ' (%s)' % self.acronym
return result return result
def all_related_publications(self):
return Publication.objects.filter(
Q(funders_generic=self) | Q(grants__funder=self)).distinct()
class Grant(models.Model): class Grant(models.Model):
""" """
...@@ -26,7 +33,7 @@ class Grant(models.Model): ...@@ -26,7 +33,7 @@ class Grant(models.Model):
In a Publication's metadata, all grants are listed In a Publication's metadata, all grants are listed
in the Crossmark part of the metadata. 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) number = models.CharField(max_length=64)
recipient_name = models.CharField(max_length=64, blank=True, null=True) recipient_name = models.CharField(max_length=64, blank=True, null=True)
recipient = models.ForeignKey('scipost.Contributor', blank=True, null=True, recipient = models.ForeignKey('scipost.Contributor', blank=True, null=True,
......
{% 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 %}
...@@ -64,11 +64,11 @@ ...@@ -64,11 +64,11 @@
</thead> </thead>
<tbody id="accordion" role="tablist" aria-multiselectable="true"> <tbody id="accordion" role="tablist" aria-multiselectable="true">
{% for funder in funders %} {% 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.name }}</td>
<td>{{ funder.acronym }}</td> <td>{{ funder.acronym }}</td>
<td>{{ funder.identifier }}</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> </tr>
{% empty %} {% empty %}
<tr> <tr>
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
</thead> </thead>
<tbody id="accordion" role="tablist" aria-multiselectable="true"> <tbody id="accordion" role="tablist" aria-multiselectable="true">
{% for grant in grants %} {% 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> <td>{{ grant.funder.name }}</td>
{% if grant.recipient %} {% if grant.recipient %}
<td>{{ grant.recipient }}</td> <td>{{ grant.recipient }}</td>
......
...@@ -7,5 +7,7 @@ urlpatterns = [ ...@@ -7,5 +7,7 @@ urlpatterns = [
url(r'^query_crossref_for_funder$', views.query_crossref_for_funder, url(r'^query_crossref_for_funder$', views.query_crossref_for_funder,
name='query_crossref_for_funder'), name='query_crossref_for_funder'),
url(r'^funders/add$', views.add_funder, name='add_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'), url(r'^grants/add$', views.add_grant, name='add_grant'),
] ]
...@@ -4,7 +4,7 @@ import json ...@@ -4,7 +4,7 @@ import json
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import permission_required from django.contrib.auth.decorators import permission_required
from django.core.urlresolvers import reverse 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 .models import Funder, Grant
from .forms import FunderRegistrySearchForm, FunderForm, GrantForm from .forms import FunderRegistrySearchForm, FunderForm, GrantForm
...@@ -53,6 +53,16 @@ def add_funder(request): ...@@ -53,6 +53,16 @@ def add_funder(request):
return redirect(reverse('funders:funders')) 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) @permission_required('scipost.can_publish_accepted_submission', raise_exception=True)
def add_grant(request): def add_grant(request):
grant_form = GrantForm(request.POST or None) grant_form = GrantForm(request.POST or None)
...@@ -63,14 +73,3 @@ def add_grant(request): ...@@ -63,14 +73,3 @@ def add_grant(request):
elif grant_form.has_changed(): elif grant_form.has_changed():
messages.warning(request, 'The form was invalidly filled (grant already exists?).') messages.warning(request, 'The form was invalidly filled (grant already exists?).')
return redirect(reverse('funders:funders')) 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)
...@@ -154,8 +154,9 @@ class Publication(models.Model): ...@@ -154,8 +154,9 @@ class Publication(models.Model):
abstract = models.TextField() abstract = models.TextField()
pdf_file = models.FileField(upload_to='UPLOADS/PUBLICATIONS/%Y/%m/', max_length=200) 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) cc_license = models.CharField(max_length=32, choices=CC_LICENSES, default=CCBY4)
grants = models.ManyToManyField('funders.Grant', blank=True) grants = models.ManyToManyField('funders.Grant', blank=True, related_name="publications")
funders_generic = models.ManyToManyField('funders.Funder', blank=True) # not linked to a grant funders_generic = models.ManyToManyField('funders.Funder', blank=True,
related_name="publications") # not linked to a grant
metadata = JSONField(default={}, blank=True, null=True) metadata = JSONField(default={}, blank=True, null=True)
metadata_xml = models.TextField(blank=True, null=True) # for Crossref deposit metadata_xml = models.TextField(blank=True, null=True) # for Crossref deposit
latest_metadata_update = models.DateTimeField(blank=True, null=True) latest_metadata_update = models.DateTimeField(blank=True, null=True)
......
...@@ -245,6 +245,10 @@ class Command(BaseCommand): ...@@ -245,6 +245,10 @@ class Command(BaseCommand):
codename='can_publish_accepted_submission', codename='can_publish_accepted_submission',
name='Can publish accepted submission', name='Can publish accepted submission',
content_type=content_type) 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 # Documentation
can_view_docs_scipost, created = Permission.objects.get_or_create( can_view_docs_scipost, created = Permission.objects.get_or_create(
...@@ -312,6 +316,7 @@ class Command(BaseCommand): ...@@ -312,6 +316,7 @@ class Command(BaseCommand):
can_view_production, can_view_production,
can_view_timesheets, can_view_timesheets,
can_publish_accepted_submission, can_publish_accepted_submission,
can_view_all_funding_info,
can_attend_VGMs, can_attend_VGMs,
can_manage_reports, can_manage_reports,
can_assign_production_supervisor, can_assign_production_supervisor,
......
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