From c36bae05c55f94edfdcd2915f08d69de73506262 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Sun, 24 Feb 2019 07:47:15 +0100 Subject: [PATCH] Improve Organizations list: paginate, use add_get_parameters --- .../organizations/organization_list.html | 19 ++++++++++++++----- organizations/views.py | 6 ++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/organizations/templates/organizations/organization_list.html b/organizations/templates/organizations/organization_list.html index f3184b454..f67cd4f73 100644 --- a/organizations/templates/organizations/organization_list.html +++ b/organizations/templates/organizations/organization_list.html @@ -4,6 +4,7 @@ {% load staticfiles %} {% load user_groups %} +{% load add_get_parameters %} {% load organizations_extras %} {% load countries %} @@ -72,13 +73,14 @@ $(document).ready(function($) { <div class="row"> <div class="col-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"> <ul> {% for code in countrycodes %} {% get_country code as country_obj %} <li style="display: inline-block;"> - <a href="?country={{ code }}"><i class="{{ country_obj.flag_css }}" aria-label="{{ country_obj.code }}" data-toggle="tooltip" title="{{ country_obj.name }}"></i></a> + <a href="{% add_get_parameters country=code %}"><i class="{{ country_obj.flag_css }}" aria-label="{{ country_obj.code }}" data-toggle="tooltip" title="{{ country_obj.name }}"></i></a> </li> {% endfor %} </ul> @@ -90,16 +92,16 @@ $(document).ready(function($) { <table class="table table-hover mb-5"> <thead class="thead-default"> <tr> - <th><a href="?order_by=country">Country</a></th> - <th><a href="?order_by=name">Name</a> <small>[acronym]</small></th> + <th><a href="{% add_get_parameters order_by='country' %}">Country</a></th> + <th><a href="{% add_get_parameters order_by='name' %}">Name</a> <small>[acronym]</small></th> <th>NAP <i class="fa fa-info-circle" data-toggle="tooltip" data-html="true" title="" data-original-title="Number of associated publications<br/>For details, click on the Organization and consult the Associated Publications tab"></i> {% if request.GET.ordering != 'asc' %} - <a href="?order_by=nap&ordering=asc"><i class="fa fa-sort-asc"></i></a> + <a href="{% add_get_parameters order_by='nap' ordering='asc' %}"><i class="fa fa-sort-asc"></i></a> {% else %} <a href="{% url 'organizations:organizations' %}"><i class="fa fa-sort-asc"></i></a> {% endif %} {% if request.GET.ordering != 'desc' %} - <a href="?order_by=nap&ordering=desc"><i class="fa fa-sort-desc"></i></a> + <a href="{% add_get_parameters order_by='nap' ordering='desc' %}"><i class="fa fa-sort-desc"></i></a> {% else %} <a href="{% url 'organizations:organizations' %}"><i class="fa fa-sort-desc"></i></a> {% endif %} @@ -144,6 +146,13 @@ $(document).ready(function($) { {% endfor %} </tbody> </table> + + {% if is_paginated %} + <div class="col-12"> + {% include 'partials/pagination.html' with page_obj=page_obj %} + </div> + {% endif %} + </div> </div> diff --git a/organizations/views.py b/organizations/views.py index 879b2af49..d95080507 100644 --- a/organizations/views.py +++ b/organizations/views.py @@ -62,8 +62,9 @@ class OrganizationDeleteView(PermissionsMixin, DeleteView): success_url = reverse_lazy('organizations:organizations') -class OrganizationListView(ListView): +class OrganizationListView(PaginationMixin, ListView): model = Organization + paginate_by = 50 def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) @@ -90,7 +91,8 @@ class OrganizationListView(ListView): elif order_by == 'name': qs = qs.order_by('name') elif order_by == 'nap': - qs = qs.order_by('cf_nr_associated_publications') + qs = qs.exclude(cf_nr_associated_publications__isnull=True + ).order_by('cf_nr_associated_publications') if ordering == 'desc': qs = qs.reverse() return qs -- GitLab