# HG changeset patch # User durandn # Date 1475765316 -7200 # Node ID 5f16c5f1efff8acd9fbef71d7def85e2a2e3f1f4 # Parent 43aa7c58904894819d8bf31dfc09f6a163da648b Work on pagination: item_detail + keep active list when navigating pagination on collection_home #39 diff -r 43aa7c589048 -r 5f16c5f1efff src/iconolab/templates/iconolab/collection_home.html --- a/src/iconolab/templates/iconolab/collection_home.html Thu Oct 06 15:09:18 2016 +0200 +++ b/src/iconolab/templates/iconolab/collection_home.html Thu Oct 06 16:48:36 2016 +0200 @@ -29,15 +29,15 @@
-
+
{% include "partials/image_annotations_list.html" with annotation_list=recent_list %} {% if recent_list %}
    @@ -59,21 +59,21 @@
      {% if recent_list.has_previous %}
    • - +
    • {% endif %} {% for page in recent_list.paginator.page_range %} - {% endfor %} {% if recent_list.has_next %}
    • - +
    • @@ -84,10 +84,9 @@
-
+
{% include "partials/image_annotations_list.html" with annotation_list=revised_list %} {% if revised_list %} - {{revised_list.paginator.per_page}}
-
+
{% include "partials/image_annotations_list.html" with annotation_list=contributions_list %} {% if contributions_list %}
    @@ -179,7 +178,7 @@
-
+
    {% for item in items_list %}
  • diff -r 43aa7c589048 -r 5f16c5f1efff src/iconolab/templates/iconolab/detail_item.html --- a/src/iconolab/templates/iconolab/detail_item.html Thu Oct 06 15:09:18 2016 +0200 +++ b/src/iconolab/templates/iconolab/detail_item.html Thu Oct 06 16:48:36 2016 +0200 @@ -9,13 +9,13 @@ {% block content %}
    - {% for image in item.images.all|dictsort:"pk" %} -
    - {% thumbnail image.media "500x500" crop=False as im %} + {% for image in images|dictsort:"obj.pk" %} +
    + {% thumbnail image.obj.media "500x500" crop=False as im %} {% endthumbnail %}
    -
    Annoter cette image +
    Annoter cette image

    {% endfor %} @@ -33,27 +33,70 @@ {% if item.metadatas.inventory_number %}
    Numéro d'inventaire : {{item.metadatas.inventory_number}}
    {% endif %} {% if item.metadatas.joconde_ref %}
    Cet objet dans Joconde
    {% endif %}
    - {% if item.images.all.count > 1 %} + {% if images|length > 1 %}

    Autres images pour cet objet:

    - {% for image in item.images.all %} - {% thumbnail image.media "150x150" crop=False as im_small %} - + {% for image in images %} + {% thumbnail image.obj.media "150x150" crop=False as im_small %} + {% endthumbnail %} {% endfor %}

    {% endif %} - {% for image in item.images.all %} -
    - {% include "partials/image_stats_panel.html" with image=image label="Statistiques sur cette image :" %} + {% for image in images %} +
    + {% include "partials/image_stats_panel.html" with image=image.obj label="Statistiques sur cette image :" %}
    {% endfor %} Retour à la liste d'objets
    - {% for image in item.images.all %} -
    - {% include "partials/image_annotations_list.html" with annotation_list=image.annotations.all header="Annotation de l'image" %} + {{display_image}} + {% for image in images %} +
    + {% include "partials/image_annotations_list.html" with annotation_list=image.annotations header="Annotation de l'image" %} + {% if image.annotations %} + + {% if image.annotations.has_previous or image.annotations.has_next %} +
      + {% if image.annotations.has_previous %} +
    • + + + +
    • + {% endif %} + + {% for page in image.annotations.paginator.page_range %} + + {% endfor %} + + {% if image.annotations.has_next %} +
    • + + + +
    • + {% endif %} +
    + {% endif %} + {% endif %}
    {% endfor %}
    diff -r 43aa7c589048 -r 5f16c5f1efff src/iconolab/views/iconolab_objects.py --- a/src/iconolab/views/iconolab_objects.py Thu Oct 06 15:09:18 2016 +0200 +++ b/src/iconolab/views/iconolab_objects.py Thu Oct 06 16:48:36 2016 +0200 @@ -250,12 +250,44 @@ (collection, item) = result else: return result(request) + context = super(ShowItemView, self).get_context_data(**kwargs) + image_guid_to_display = request.GET.get("show-image", str(item.images.first().image_guid)) + if image_guid_to_display not in [str(guid) for guid in item.images.all().values_list("image_guid", flat=True)]: + image_guid_to_display = str(item.images.first().image_guid) + context['display_image'] = image_guid_to_display + try: + displayed_annotations_page = int(request.GET.get('page', '1')) + except ValueError: + displayed_annotations_page = 1 + try: + displayed_annotations_per_page = int(request.GET.get('perpage', '10')) + except ValueError: + displayed_annotations_per_page = 10 + context['collection_name'] = self.kwargs.get('collection_name', '') context['item_guid'] = self.kwargs.get('image_guid', '') context['collection'] = collection context['item'] = item + context['images'] = [] for image in item.images.all(): + if str(image.image_guid) == image_guid_to_display: + page = displayed_annotations_page + per_page = displayed_annotations_per_page + else: + page = 1 + per_page = 10 + annotations_paginator = Paginator(image.annotations.all(), per_page) + try: + annotations = annotations_paginator.page(page) + except PageNotAnInteger: + annotations = annotations_paginator.page(1) + except EmptyPage: + annotations = annotations_paginator.page(recent_paginator.num_pages) + context['images'].append({ + 'obj' : image, + 'annotations': annotations + }) image.stats.views_count += 1 image.stats.save() return render(request, 'iconolab/detail_item.html', context);