SciPost Code Repository

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

Improve Organizations list: paginate, use add_get_parameters

parent fea66ced
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
{% load staticfiles %} {% load staticfiles %}
{% load user_groups %} {% load user_groups %}
{% load add_get_parameters %}
{% load organizations_extras %} {% load organizations_extras %}
{% load countries %} {% load countries %}
...@@ -72,13 +73,14 @@ $(document).ready(function($) { ...@@ -72,13 +73,14 @@ $(document).ready(function($) {
<div class="row"> <div class="row">
<div class="col-3"> <div class="col-3">
<h3>Click on flag to view by Country</h3> <h3>Click on flag to view by Country</h3>
<p><a href="{% url 'organizations:organizations' %}">View all</a></p>
</div> </div>
<div class="col-8"> <div class="col-8">
<ul> <ul>
{% for code in countrycodes %} {% for code in countrycodes %}
{% get_country code as country_obj %} {% get_country code as country_obj %}
<li style="display: inline-block;"> <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> </li>
{% endfor %} {% endfor %}
</ul> </ul>
...@@ -90,16 +92,16 @@ $(document).ready(function($) { ...@@ -90,16 +92,16 @@ $(document).ready(function($) {
<table class="table table-hover mb-5"> <table class="table table-hover mb-5">
<thead class="thead-default"> <thead class="thead-default">
<tr> <tr>
<th><a href="?order_by=country">Country</a></th> <th><a href="{% add_get_parameters order_by='country' %}">Country</a></th>
<th><a href="?order_by=name">Name</a>&nbsp;&nbsp;<small>[acronym]</small></th> <th><a href="{% add_get_parameters order_by='name' %}">Name</a>&nbsp;&nbsp;<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> <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' %} {% 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 %} {% else %}
<a href="{% url 'organizations:organizations' %}"><i class="fa fa-sort-asc"></i></a> <a href="{% url 'organizations:organizations' %}"><i class="fa fa-sort-asc"></i></a>
{% endif %} {% endif %}
{% if request.GET.ordering != 'desc' %} {% 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 %} {% else %}
<a href="{% url 'organizations:organizations' %}"><i class="fa fa-sort-desc"></i></a> <a href="{% url 'organizations:organizations' %}"><i class="fa fa-sort-desc"></i></a>
{% endif %} {% endif %}
...@@ -144,6 +146,13 @@ $(document).ready(function($) { ...@@ -144,6 +146,13 @@ $(document).ready(function($) {
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% if is_paginated %}
<div class="col-12">
{% include 'partials/pagination.html' with page_obj=page_obj %}
</div>
{% endif %}
</div> </div>
</div> </div>
......
...@@ -62,8 +62,9 @@ class OrganizationDeleteView(PermissionsMixin, DeleteView): ...@@ -62,8 +62,9 @@ class OrganizationDeleteView(PermissionsMixin, DeleteView):
success_url = reverse_lazy('organizations:organizations') success_url = reverse_lazy('organizations:organizations')
class OrganizationListView(ListView): class OrganizationListView(PaginationMixin, ListView):
model = Organization model = Organization
paginate_by = 50
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs) context = super().get_context_data(*args, **kwargs)
...@@ -90,7 +91,8 @@ class OrganizationListView(ListView): ...@@ -90,7 +91,8 @@ class OrganizationListView(ListView):
elif order_by == 'name': elif order_by == 'name':
qs = qs.order_by('name') qs = qs.order_by('name')
elif order_by == 'nap': 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': if ordering == 'desc':
qs = qs.reverse() qs = qs.reverse()
return qs return qs
......
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