diff --git a/funders/forms.py b/funders/forms.py index 64676af4446f442411f856981a0393bf8a512945..c48a9287d37bd1beda528d7490d50fd944acd5b8 100644 --- a/funders/forms.py +++ b/funders/forms.py @@ -2,6 +2,9 @@ from django import forms from .models import Funder, Grant +from scipost.models import Contributor + + class FunderRegistrySearchForm(forms.Form): name = forms.CharField(max_length=128) @@ -9,7 +12,7 @@ class FunderRegistrySearchForm(forms.Form): class FunderForm(forms.ModelForm): class Meta: model = Funder - fields = ['name', 'identifier',] + fields = ['name', 'acronym', 'identifier',] class GrantForm(forms.ModelForm): @@ -17,6 +20,11 @@ class GrantForm(forms.ModelForm): model = Grant fields = ['funder', 'number', 'recipient_name', 'recipient',] + def __init__(self, *args, **kwargs): + super(GrantForm, self).__init__(*args, **kwargs) + self.fields['recipient'] = forms.ModelChoiceField( + queryset=Contributor.objects.all().order_by('user__last_name')) + class GrantSelectForm(forms.Form): grant = forms.ModelChoiceField(queryset=Grant.objects.all()) diff --git a/funders/migrations/0004_auto_20170726_2037.py b/funders/migrations/0004_auto_20170726_2037.py new file mode 100644 index 0000000000000000000000000000000000000000..59544eb74125ea1719eaa0443a713a567ee15159 --- /dev/null +++ b/funders/migrations/0004_auto_20170726_2037.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-26 18:37 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('funders', '0003_auto_20170726_0606'), + ] + + operations = [ + migrations.AlterModelOptions( + name='funder', + options={'ordering': ['name', 'acronym']}, + ), + migrations.AddField( + model_name='funder', + name='acronym', + field=models.CharField(blank=True, max_length=32, null=True), + ), + ] diff --git a/funders/models.py b/funders/models.py index 3957bf92f13ae9a3825a06aa780e68c6063e6b73..997ca57840cd1a6cc0c0a06c6c7c94983f3543f1 100644 --- a/funders/models.py +++ b/funders/models.py @@ -7,13 +7,17 @@ class Funder(models.Model): Fundref registry. """ name = models.CharField(max_length=256) + acronym = models.CharField(max_length=32, blank=True, null=True) identifier = models.CharField(max_length=200, unique=True) class Meta: - ordering = ['name'] + ordering = ['name', 'acronym'] def __str__(self): - return self.name + result = self.name + if self.acronym: + result += ' (%s)' % self.acronym + return result class Grant(models.Model): diff --git a/funders/templates/funders/funders.html b/funders/templates/funders/funders.html index 7ae67d06b8fa03d6fb504cd5475f30f1c22120cb..cd9dfd6d4c2f7afc44d157a94a4471d7113720b0 100644 --- a/funders/templates/funders/funders.html +++ b/funders/templates/funders/funders.html @@ -57,6 +57,7 @@ <thead class="thead-default"> <tr> <th>Name</th> + <th>Acronym</th> <th>Identifier</th> </tr> </thead> @@ -64,6 +65,7 @@ {% 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;"> <td>{{ funder.name }}</td> + <td>{{ funder.acronym }}</td> <td>{{ funder.identifier }}</td> </tr> {% empty %} diff --git a/funders/templates/funders/query_crossref_for_funder.html b/funders/templates/funders/query_crossref_for_funder.html index b8459c8a21ff63b830f9c8919fdefb2fe28f9174..35c1b9a7ee15dbe05d6c0dabdcad77b83ce9e30e 100644 --- a/funders/templates/funders/query_crossref_for_funder.html +++ b/funders/templates/funders/query_crossref_for_funder.html @@ -29,6 +29,7 @@ <form action="{% url 'funders:add_funder' %}" method="post"> {% csrf_token %} <input name='name' style="width: 64%" value='{{ item.name }}'> + <input name='acronym' style="width: 64%" placeholder='acronym (if known)'> <input name='identifier' style="width: 64%" value='{{ item.uri }}'> <input class="btn btn-secondary" type="submit" value="Add this funder"> </form>