--- a/src/iconolab/templates/iconolab/collection_home.html Mon Nov 28 14:34:07 2016 +0100
+++ b/src/iconolab/templates/iconolab/collection_home.html Tue Nov 29 10:50:38 2016 +0100
@@ -40,46 +40,7 @@
<div id="list-recent" class="recent-ann-wrapper collection-home-block col-md-12 {% if active_list == 'recent' %}selected{% endif %}">
{% include "partials/image_annotations_list.html" with annotation_list=recent_list %}
{% if recent_list %}
- <ul class="pagination pull-right recent-perpage" style="margin-left: 15px;">
- <li class="active pagination-label"><a>Annotations par page : </a></li>
- <li class="{% if recent_list.paginator.per_page == 5 %}active{% endif %}">
- <a {% if recent_list.paginator.per_page != 5 %}href="{% url 'collection_home' collection_name %}?show=recent&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page=1&recent_perpage=5&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>5</a>
- </li>
- <li class="{% if recent_list.paginator.per_page == 10 %}active{% endif %}">
- <a {% if recent_list.paginator.per_page != 10 %}href="{% url 'collection_home' collection_name %}?show=recent&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page=1&recent_perpage=10&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>10</a>
- </li>
- <li class="{% if recent_list.paginator.per_page == 25 %}active{% endif %}">
- <a {% if recent_list.paginator.per_page != 25 %}href="{% url 'collection_home' collection_name %}?show=recent&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page=1&recent_perpage=25&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>25</a>
- </li>
- <li class="{% if recent_list.paginator.per_page == 100 %}active{% endif %}">
- <a {% if recent_list.paginator.per_page != 100 %}href="{% url 'collection_home' collection_name %}?show=recent&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page=1&recent_perpage=100&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>100</a>
- </li>
- </ul>
- {% if recent_list.has_previous or recent_list.has_next %}
- <ul class="pagination pull-right recent-pagination">
- {% if recent_list.has_previous %}
- <li>
- <a href="{% url 'collection_home' collection_name %}?show=recent&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_list.previous_page_number}}&recent_perpage={{recent_list.paginator.per_page}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}" aria-label="Précédent">
- <span aria-hidden="true">«</span>
- </a>
- </li>
- {% endif %}
-
- {% for page in recent_list.paginator.page_range %}
- <li id="page-link-{{page}}" class="pagination-link {% if page == recent_list.number %}active{% endif %}">
- <a {% if page != revised_list.number %}href="{% url 'collection_home' collection_name %}?show=recent&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{page}}&recent_perpage={{recent_list.paginator.per_page}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>{{page}}</a>
- </li>
- {% endfor %}
-
- {% if recent_list.has_next %}
- <li>
- <a href="{% url 'collection_home' collection_name %}?show=recent&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_list.next_page_number}}&recent_perpage={{recent_list.paginator.per_page}}&revised_page={{revised_page}}&revised_perpage={{revised_.perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}" aria-label="Suivant">
- <span aria-hidden="true">»</span>
- </a>
- </li>
- {% endif %}
- </ul>
- {% endif %}
+ {% include "partials/collection_home_pagination_links.html" with pagination_data=recent_pagination_data list_identifier="recent" %}
{% endif %}
</div>
</div>
@@ -87,46 +48,7 @@
<div id="list-revised" class="revised-ann-wrapper collection-home-block col-md-12 {% if active_list == 'revised' %}selected{% endif %}">
{% include "partials/image_annotations_list.html" with annotation_list=revised_list %}
{% if revised_list %}
- <ul class="pagination pull-right revised-perpage" style="margin-left: 15px;">
- <li class="active pagination-label"><a>Annotations par page : </a></li>
- <li class="{% if revised_list.paginator.per_page == 5 %}active{% endif %}">
- <a {% if revised_list.paginator.per_page != 5 %}href="{% url 'collection_home' collection_name %}?show=revised&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page=1&revised_perpage=5&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>5</a>
- </li>
- <li class="{% if revised_list.paginator.per_page == 10 %}active{% endif %}">
- <a {% if revised_list.paginator.per_page != 10 %}href="{% url 'collection_home' collection_name %}?show=revised&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page=1&revised_perpage=10&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>10</a>
- </li>
- <li class="{% if revised_list.paginator.per_page == 25 %}active{% endif %}">
- <a {% if revised_list.paginator.per_page != 25 %}href="{% url 'collection_home' collection_name %}?show=revised&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page=1&revised_perpage=25&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>25</a>
- </li>
- <li class="{% if revised_list.paginator.per_page == 100 %}active{% endif %}">
- <a {% if revised_list.paginator.per_page != 100 %}href="{% url 'collection_home' collection_name %}?show=revised&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page=1&revised_perpage=100&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>100</a>
- </li>
- </ul>
- {% if revised_list.has_previous or revised_list.has_next %}
- <ul class="pagination pull-right revised-pagination">
- {% if revised_list.has_previous %}
- <li>
- <a href="{% url 'collection_home' collection_name %}?show=revised&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_list.previous_page_number}}&revised_perpage={{revised_list.paginator.per_page}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}" aria-label="Précédent">
- <span aria-hidden="true">«</span>
- </a>
- </li>
- {% endif %}
-
- {% for page in revised_list.paginator.page_range %}
- <li id="page-link-{{page}}" class="pagination-link {% if page == revised_list.number %}active{% endif %}">
- <a {% if page != revised_list.number %}href="{% url 'collection_home' collection_name %}?show=revised&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{page}}&revised_perpage={{revised_list.paginator.per_page}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>{{page}}</a>
- </li>
- {% endfor %}
-
- {% if revised_list.has_next %}
- <li>
- <a href="{% url 'collection_home' collection_name %}?show=revised&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_list.next_page_number}}&revised_perpage={{revised_list.paginator.per_page}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}" aria-label="Suivant">
- <span aria-hidden="true">»</span>
- </a>
- </li>
- {% endif %}
- </ul>
- {% endif %}
+ {% include "partials/collection_home_pagination_links.html" with pagination_data=revised_pagination_data list_identifier="revised" %}
{% endif %}
</div>
</div>
@@ -134,54 +56,14 @@
<div id="list-contribution" class="contributions-ann-wrapper collection-home-block col-md-12 {% if active_list == 'contributions' %}selected{% endif %}">
{% include "partials/image_annotations_list.html" with annotation_list=contributions_list %}
{% if contributions_list %}
- <ul class="pagination pull-right contributions-perpage" style="margin-left: 15px;">
- <li class="active pagination-label"><a>Annotations par page : </a></li>
- <li class="{% if contributions_list.paginator.per_page == 5 %}active{% endif %}">
- <a {% if contributions_list.paginator.per_page != 5 %}href="{% url 'collection_home' collection_name %}?show=contributions&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page=1&contributions_perpage=5"{% endif %}>5</a>
- </li>
- <li class="{% if contributions_list.paginator.per_page == 10 %}active{% endif %}">
- <a {% if contributions_list.paginator.per_page != 10 %}href="{% url 'collection_home' collection_name %}?show=contributions&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page=1&contributions_perpage=10"{% endif %}>10</a>
- </li>
- <li class="{% if contributions_list.paginator.per_page == 25 %}active{% endif %}">
- <a {% if contributions_list.paginator.per_page != 25 %}href="{% url 'collection_home' collection_name %}?show=contributions&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page=1&contributions_perpage=25"{% endif %}>25</a>
- </li>
- <li class="{% if contributions_list.paginator.per_page == 100 %}active{% endif %}">
- <a {% if contributions_list.paginator.per_page != 100 %}href="{% url 'collection_home' collection_name %}?show=contributions&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page=1&contributions_perpage=100"{% endif %}>100</a>
- </li>
- </ul>
- {% if contributions_list.has_previous or contributions_list.has_next %}
- <ul class="pagination pull-right contributions-pagination">
- {% if contributions_list.has_previous %}
- <li>
- <a href="{% url 'collection_home' collection_name %}?show=contributions&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_list.previous_page_number}}&contributions_perpage={{contributions_list.paginator.per_page}}" aria-label="Précédent">
- <span aria-hidden="true">«</span>
- </a>
- </li>
- {% endif %}
-
- {% for page in contributions_list.paginator.page_range %}
- <li id="page-link-{{page}}" class="pagination-link {% if page == contributions_list.number %}active{% endif %}">
- <a {% if page != contributions_list.number %}href="{% url 'collection_home' collection_name %}?show=contributions&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{page}}&contributions_perpage={{contributions_list.paginator.per_page}}"{% endif %}>{{page}}</a>
- </li>
- {% endfor %}
-
- {% if contributions_list.has_next %}
- <li>
- <a href="{% url 'collection_home' collection_name %}?show=contributions&items_page={{items_page}}&items_perpage={{items_perpage}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_list.next_page_number}}&contributions_perpage={{contributions_list.paginator.per_page}}" aria-label="Suivant">
- <span aria-hidden="true">»</span>
- </a>
- </li>
- {% endif %}
- </ul>
- {% endif %}
+ {% include "partials/collection_home_pagination_links.html" with pagination_data=contributions_pagination_data list_identifier="contributions" %}
{% endif %}
</div>
</div>
<div class="row">
<div id="list-items" class="collection-home-block col-md-12 text-center {% if active_list == 'items' %}selected{% endif %}">
- <ul class="image-list-wrapper list-inline">
-
- {% for item in items_list %}
+ <ul class="image-list-wrapper list-inline">
+ {% for item in items_pagination_data.list %}
<li class="image-list-li small-image-wrapper panel panel-default">
<div class="object-infos text-center" style="margin-top: 10px;">
<a class="btn btn-default btn-xs collection-home-item-btn" href="{% url 'item_detail' collection_name item.item_guid %}"><i class="fa fa-eye"></i> Détail de l'objet</a>
@@ -190,46 +72,7 @@
</li>
{% endfor %}
</ul>
- <ul class="pagination pull-right items-perpage" style="margin-left: 15px;">
- <li class="active pagination-label"><a>Objets par page : </a></li>
- <li class="{% if items_list.paginator.per_page == 6 %}active{% endif %}">
- <a {% if items_list.paginator.per_page != 6 %}href="{% url 'collection_home' collection_name %}?show=items&items_page=1&items_perpage=6&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>6</a>
- </li>
- <li class="{% if items_list.paginator.per_page == 12 %}active{% endif %}">
- <a {% if items_list.paginator.per_page != 12 %}href="{% url 'collection_home' collection_name %}?show=items&items_page=1&items_perpage=12&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>12</a>
- </li>
- <li class="{% if items_list.paginator.per_page == 48 %}active{% endif %}">
- <a {% if items_list.paginator.per_page != 48 %}href="{% url 'collection_home' collection_name %}?show=items&items_page=1&items_perpage=48&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>48</a>
- </li>
- <li class="{% if items_list.paginator.per_page == 256 %}active{% endif %}">
- <a {% if items_list.paginator.per_page != 256 %}href="{% url 'collection_home' collection_name %}?show=items&items_page=1&items_perpage=256&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>256</a>
- </li>
- </ul>
- {% if items_list.has_previous or items_list.has_next %}
- <ul class="pagination pull-right items-pagination">
- {% if items_list.has_previous %}
- <li>
- <a href="{% url 'collection_home' collection_name %}?show=items&items_page={{items_list.previous_page_number}}&items_perpage={{items_list.paginator.per_page}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}" aria-label="Précédent">
- <span aria-hidden="true">«</span>
- </a>
- </li>
- {% endif %}
-
- {% for page in items_list.paginator.page_range %}
- <li id="page-link-{{page}}" class="pagination-link {% if page == items_list.number %}active{% endif %}">
- <a {% if page != items_list.number %}href="{% url 'collection_home' collection_name %}?show=items&items_page={{page}}&items_perpage={{items_list.paginator.per_page}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}"{% endif %}>{{page}}</a>
- </li>
- {% endfor %}
-
- {% if items_list.has_next %}
- <li>
- <a href="{% url 'collection_home' collection_name %}?show=items&items_page={{items_list.next_page_number}}&items_perpage={{items_list.paginator.per_page}}&recent_page={{recent_page}}&recent_perpage={{recent_perpage}}&revised_page={{revised_page}}&revised_perpage={{revised_perpage}}&contributions_page={{contributions_page}}&contributions_perpage={{contributions_perpage}}" aria-label="Suivant">
- <span aria-hidden="true">»</span>
- </a>
- </li>
- {% endif %}
- </ul>
- {% endif %}
+ {% include "partials/collection_home_pagination_links.html" with pagination_data=items_pagination_data list_identifier="items" %}
</div>
</div>
{% endblock %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/iconolab/templates/partials/collection_home_pagination_links.html Tue Nov 29 10:50:38 2016 +0100
@@ -0,0 +1,55 @@
+<ul class="pagination pull-right {{list_identifier}}-perpage" style="margin-left: 15px;">
+ <li class="active pagination-label"><a>Élements par page : </a></li>
+ {% for perpage in pagination_data.perpage_range %}
+ <li class="{% if pagination_data.perpage == perpage %}active{% endif %}">
+ <a {% if pagination_data.per_page != perpage %}href="{% url 'collection_home' collection_name %}?show={{list_identifier}}&{{list_identifier}}_page=1&{{list_identifier}}_perpage={{perpage}}{{pagination_data.trailing_qarg}}"{% endif %}>{{perpage}}</a>
+ </li>
+ {% endfor %}
+</ul>
+{% if pagination_data.list.has_previous or pagination_data.list.has_next %}
+ <ul class="pagination pull-right {{list_identifier}}-pagination">
+ {% if pagination_data.list.has_previous %}
+ <li>
+ <a href="{% url 'collection_home' collection_name %}?show={{list_identifier}}&{{list_identifier}}_page={{pagination_data.list.previous_page_number}}&{{list_identifier}}_perpage={{pagination_data.list.paginator.per_page}}{{pagination_data.trailing_qarg}}" aria-label="Suivant">
+ <span aria-hidden="true">«</span>
+ </a>
+ </li>
+ {% endif %}
+
+ {% if pagination_data.show_first %}
+ <li id="page-link-first" class="pagination-link {% if page == pagination_data.list.number %}active{% endif %}">
+ <a href="{% url 'collection_home' collection_name %}?show={{list_identifier}}&{{list_identifier}}_page=1&{{list_identifier}}_perpage={{pagination_data.perpage}}{{pagination_data.trailing_qarg}}">1</a>
+ </li>
+ {% if pagination_data.ellipsis_first %}
+ <li class="pagination-link pagination-link-ellipsis">
+ <a>...</a>
+ </li>
+ {% endif %}
+ {% endif %}
+
+ {% for page in pagination_data.page_range %}
+ <li id="page-link-{{pagination_data.page}}" class="pagination-link {% if page == pagination_data.list.number %}active{% endif %}">
+ <a {% if page != pagination_data.list.number %}href="{% url 'collection_home' collection_name %}?show={{list_identifier}}&{{list_identifier}}_page={{page}}&items_perpage={{pagination_data.perpage}}{{pagination_data.trailing_qarg}}"{% endif %}>{{page}}</a>
+ </li>
+ {% endfor %}
+
+ {% if pagination_data.show_last %}
+ {% if pagination_data.ellipsis_last %}
+ <li class="pagination-link pagination-link-ellipsis">
+ <a>...</a>
+ </li>
+ {% endif %}
+ <li id="page-link-{{pagination_data.page}}" class="pagination-link {% if page == pagination_data.list.number %}active{% endif %}">
+ <a href="{% url 'collection_home' collection_name %}?show={{list_identifier}}&{{list_identifier}}_page={{pagination_data.list.paginator.num_pages}}&{{list_identifier}}_perpage={{pagination_data.perpage}}{{pagination_data.trailing_qarg}}">{{pagination_data.list.paginator.num_pages}}</a>
+ </li>
+ {% endif %}
+
+ {% if pagination_data.list.has_next %}
+ <li>
+ <a href="{% url 'collection_home' collection_name %}?show={{list_identifier}}&{{list_identifier}}_page={{pagination_data.list.next_page_number}}&{{list_identifier}}_perpage={{pagination_data.list.paginator.per_page}}{{pagination_data.trailing_qarg}}" aria-label="Suivant">
+ <span aria-hidden="true">»</span>
+ </a>
+ </li>
+ {% endif %}
+ </ul>
+{% endif %}
\ No newline at end of file
--- a/src/iconolab/views/objects.py Mon Nov 28 14:34:07 2016 +0100
+++ b/src/iconolab/views/objects.py Tue Nov 29 10:50:38 2016 +0100
@@ -65,7 +65,34 @@
except (ValueError, AnnotationRevision.DoesNotExist):
return False, RedirectView.as_view(url=reverse('404error'))
return True, objects_tuple
-
+
+ def get_pagination_data(self, list_to_paginate, page, perpage, adjacent_pages_count, perpage_range=[5, 10, 25, 100], trailing_qarg=""):
+ """
+ Takes a queryset or a list and returns a dict with pagination data
+ """
+ pagination_data = {}
+ pagination_data["page"] = page
+ pagination_data["perpage"] = perpage
+ pagination_data["perpage_range"] = perpage_range
+ pagination_data["trailing_qarg"] = trailing_qarg
+ paginator = Paginator(list_to_paginate, perpage)
+ try:
+ pagination_data["list"] = paginator.page(page)
+ except PageNotAnInteger:
+ pagination_data["list"] = paginator.page(1)
+ except EmptyPage:
+ pagination_data["list"] = paginator.page(paginator.num_pages)
+ pagination_data["page_range"] = [
+ n for n in \
+ range(page - adjacent_pages_count, page + adjacent_pages_count + 1) \
+ if n > 0 and n <= paginator.num_pages
+ ]
+ pagination_data["show_first"] = page - adjacent_pages_count > 1
+ pagination_data["ellipsis_first"] = pagination_data["show_first"] and (page - adjacent_pages_count != 2)
+ pagination_data["show_last"] = page + adjacent_pages_count < paginator.num_pages
+ pagination_data["ellipsis_last"] = pagination_data["show_last"] and (page + adjacent_pages_count != paginator.num_pages - 1)
+ return pagination_data
+
class CollectionHomepageView(View, ContextMixin, IconolabObjectView):
def get(self, request, *args, **kwargs):
success, result = self.check_kwargs(kwargs)
@@ -119,50 +146,63 @@
active_list = 'items'
context["active_list"] = active_list
+
+ # Pagination values
+ adjacent_pages_count = 2
+
# Paginated objects list
- context["items_page"] = items_page
- context["items_perpage"] = items_per_page
- items_paginator = Paginator(collection.items.order_by("metadatas__inventory_number").all(), items_per_page)
- try:
- context["items_list"] = items_paginator.page(items_page)
- except PageNotAnInteger:
- context["items_list"] = items_paginator.page(1)
- except EmptyPage:
- context["items_list"] = items_paginator.page(items_paginator.num_pages)
+ items_list = collection.items.order_by("metadatas__inventory_number").all()
+ context["items_pagination_data"] = self.get_pagination_data(
+ items_list,
+ items_page,
+ items_per_page,
+ adjacent_pages_count,
+ perpage_range=[6, 12, 48, 192],
+ trailing_qarg="&recent_page="+str(recent_page)
+ +"&recent_perpage="+str(recent_per_page)
+ +"&revised_page="+str(revised_page)
+ +"&revised_perpage="+str(revised_per_page)
+ +"&contributions_page="+str(contributions_page)
+ +"&contributions_perpage="+str(contributions_per_page)
+ )
# Paginated recent annotations list
- context["recent_page"] = recent_page
- context["recent_perpage"] = recent_per_page
recent_annotations = Annotation.objects.filter(image__item__collection__name=collection.name).prefetch_related(
'current_revision',
'stats'
).order_by('-current_revision__created')
- recent_paginator = Paginator(recent_annotations, recent_per_page)
- try:
- context["recent_list"] = recent_paginator.page(recent_page)
- except PageNotAnInteger:
- context["recent_list"] = recent_paginator.page(1)
- except EmptyPage:
- context["recent_list"] = recent_paginator.page(recent_paginator.num_pages)
+ context["recent_pagination_data"] = self.get_pagination_data(
+ recent_annotations,
+ recent_page,
+ recent_per_page,
+ adjacent_pages_count,
+ trailing_qarg="&items_page="+str(items_page)
+ +"&items_perpage="+str(items_per_page)
+ +"&revised_page="+str(revised_page)
+ +"&revised_perpage="+str(revised_per_page)
+ +"&contributions_page="+str(contributions_page)
+ +"&contributions_perpage="+str(contributions_per_page)
+ )
# Paginated revised annotations list
- context["revised_page"] = revised_page
- context["revised_perpage"] = revised_per_page
revised_annotations = Annotation.objects.filter(image__item__collection__name=collection.name).prefetch_related(
'current_revision',
'stats'
).annotate(revision_count=Count('revisions')).order_by('-revision_count')
- revised_paginator = Paginator(revised_annotations, revised_per_page)
- try:
- context["revised_list"] = revised_paginator.page(revised_page)
- except PageNotAnInteger:
- context["revised_list"] = revised_paginator.page(1)
- except EmptyPage:
- context["revised_list"] = revised_paginator.page(revised_paginator.num_pages)
+ context["revised_pagination_data"] = self.get_pagination_data(
+ revised_annotations,
+ revised_page,
+ revised_per_page,
+ adjacent_pages_count,
+ trailing_qarg="&items_page="+str(items_page)
+ +"&items_perpage="+str(items_per_page)
+ +"&recent_page="+str(recent_page)
+ +"&recent_perpage="+str(recent_per_page)
+ +"&contributions_page="+str(contributions_page)
+ +"&contributions_perpage="+str(contributions_per_page)
+ )
# Paginated contribution calls annotation list
- context["contributions_page"] = contributions_page
- context["contributions_perpage"] = contributions_per_page
contrib_calls_annotations_ids = list(set(MetaCategoryInfo.objects.filter(
metacategory__collection__name=collection.name,
metacategory__triggers_notifications=MetaCategory.CONTRIBUTORS
@@ -170,13 +210,18 @@
collection_annotations = Annotation.objects.filter(id__in=contrib_calls_annotations_ids).all()
collection_ann_dict = dict([(str(annotation.id), annotation) for annotation in collection_annotations])
contributions_annotations = [collection_ann_dict[id] for id in contrib_calls_annotations_ids]
- contributions_paginator = Paginator(contributions_annotations, contributions_per_page)
- try:
- context["contributions_list"] = contributions_paginator.page(contributions_page)
- except PageNotAnInteger:
- context["contributions_list"] = contributions_paginator.page(1)
- except EmptyPage:
- context["contributions_list"] = contributions_paginator.page(contributions_paginator.num_pages)
+ context["contributions_pagination_data"] = self.get_pagination_data(
+ contributions_annotations,
+ contributions_page,
+ contributions_per_page,
+ adjacent_pages_count,
+ trailing_qarg="&items_page="+str(items_page)
+ +"&items_perpage="+str(items_per_page)
+ +"&recent_page="+str(recent_page)
+ +"&recent_perpage="+str(recent_per_page)
+ +"&revised_page="+str(revised_page)
+ +"&revised_perpage="+str(revised_per_page)
+ )
return render(request, 'iconolab/collection_home.html', context)