SciPost Code Repository

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

Add Organization selection in list

parent 7c114706
No related branches found
No related tags found
No related merge requests found
......@@ -12,14 +12,26 @@ from django.core.exceptions import ValidationError
from django.db import transaction
from django.utils import timezone
from dal import autocomplete
from guardian.shortcuts import assign_perm
from .constants import ROLE_GENERAL
from .models import OrganizationEvent, ContactPerson, Contact, ContactRole
from .models import Organization, OrganizationEvent, ContactPerson, Contact, ContactRole
from scipost.constants import TITLE_CHOICES
class SelectLinkedOrganizationForm(forms.Form):
topic = forms.ModelChoiceField(
queryset=Organization.objects.all(),
widget=autocomplete.ModelSelect2(
url='/organizations/organization-linked-autocomplete',
attrs={'data-html': True}
),
label='Type to search, select & then click on name'
)
class OrganizationEventForm(forms.ModelForm):
class Meta:
model = OrganizationEvent
......
......@@ -2,6 +2,7 @@
{% block pagetitle %}: Organizations{% endblock pagetitle %}
{% load bootstrap %}
{% load static %}
{% load user_groups %}
{% load add_get_parameters %}
......@@ -43,12 +44,12 @@
<div class="row">
<div class="col-5">
<div class="col-lg-5">
<p>Organizations are linked through appearing in a publication's author affiliations, grant-giving agencies or explicit support acknowledgements.</p>
<p>For each Organization, the NAP (number of associated publications) is given (you can order in decreasing/increasing NAP using the header arrows).</p>
</div>
<div class="col-1"></div>
<div class="col-5">
<div class="col-lg-1"></div>
<div class="col-lg-5">
<p>Click on a row to see more details about the Organization, including per-year breakdowns of:</p>
<ul>
<li>associated publications</li>
......@@ -62,11 +63,20 @@
</div>
<div class="row">
<div class="col-3">
<div class="col-lg-4">
<h3>Search for a particular Organization</h3>
<p>(by name or acronym)</p>
</div>
<div class="col-lg-8">
{{ select_linked_organization_form|bootstrap }}
</div>
</div>
<div class="row">
<div class="col-lg-3">
<h3>Click on flag to view by Country</h3>
<p><a href="{% url 'organizations:organizations' %}">View all</a></p>
</div>
<div class="col-8">
<div class="col-lg-8">
<ul>
{% for code in countrycodes %}
{% get_country code as country_obj %}
......@@ -152,4 +162,5 @@
{% block footer_script %}
<script src="{% static 'scipost/table-row-blank.js' %}"></script>
{{ select_linked_organization_form.media }}
{% endblock %}
......@@ -15,6 +15,11 @@ urlpatterns = [
views.OrganizationAutocompleteView.as_view(),
name='organization-autocomplete',
),
path(
'organization-linked-autocomplete',
views.OrganizationLinkedAutocompleteView.as_view(),
name='organization-linked-autocomplete',
),
url(
r'^$',
views.OrganizationListView.as_view(),
......
......@@ -22,7 +22,7 @@ from guardian.decorators import permission_required
from .constants import ORGTYPE_PRIVATE_BENEFACTOR,\
ORGANIZATION_EVENT_COMMENT, ORGANIZATION_EVENT_EMAIL_SENT
from .forms import OrganizationEventForm, ContactPersonForm,\
from .forms import SelectLinkedOrganizationForm, OrganizationEventForm, ContactPersonForm,\
NewContactForm, ContactActivationForm, ContactRoleForm
from .models import Organization, OrganizationEvent, ContactPerson, Contact, ContactRole
......@@ -80,6 +80,14 @@ class OrganizationAutocompleteView(autocomplete.Select2QuerySetView):
item.country.flag_css, item.country.name, item.name)
class OrganizationLinkedAutocompleteView(OrganizationAutocompleteView):
"""To feed the Select2 widget."""
def get_result_label(self, item):
return format_html(
'<a href="{}">{}</a>',
reverse('organizations:organization_details', kwargs={'pk': item.id}), item)
class OrganizationCreateView(PermissionsMixin, CreateView):
"""
Create a new Organization.
......@@ -122,6 +130,7 @@ class OrganizationListView(PaginationMixin, ListView):
context['pubyears'] = range(int(timezone.now().strftime('%Y')), 2015, -1)
context['countrycodes'] = [code['country'] for code in list(
Organization.objects.all().distinct('country').values('country'))]
context['select_linked_organization_form'] = SelectLinkedOrganizationForm()
return context
def get_queryset(self):
......
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