# HG changeset patch # User durandn # Date 1476271813 -7200 # Node ID 6b304e2c6af4dc6922ac78f55ee0b5d2cc43d0f1 # Parent cb79037eaa0c80131e9caa4c5f4c4c1c12071e44 reworked search design and search pagination #39 diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/models.py --- a/src/iconolab/models.py Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/models.py Wed Oct 12 13:30:13 2016 +0200 @@ -162,8 +162,6 @@ for annotation in self.annotations.all(): revision_tags = json.loads(annotation.current_revision.get_tags_json()) tag_list += [tag_infos['tag_label'] for tag_infos in revision_tags if tag_infos.get('tag_label') is not None] #deal with - print("tag_list") - print(tag_list) return tag_list class AnnotationManager(models.Manager): diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/search_indexes/__init__.py --- a/src/iconolab/search_indexes/__init__.py Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/search_indexes/__init__.py Wed Oct 12 13:30:13 2016 +0200 @@ -1,2 +1,2 @@ -from .indexes import AnnotationIndex, ImageIndex -__all__ = ['AnnotationIndex', 'ImageIndex', 'RevisionSignalProcessor'] \ No newline at end of file +from .indexes import AnnotationIndex, ItemIndex +__all__ = ['AnnotationIndex', 'ItemIndex', 'RevisionSignalProcessor'] \ No newline at end of file diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/search_indexes/forms.py --- a/src/iconolab/search_indexes/forms.py Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/search_indexes/forms.py Wed Oct 12 13:30:13 2016 +0200 @@ -1,6 +1,6 @@ from django import forms from haystack.forms import SearchForm -from iconolab.models import Image, Annotation +from iconolab.models import Item, Annotation @@ -31,9 +31,9 @@ def get_model_type_queryset(self, qs, model_type): if model_type == 'images': - qs = qs.models(Image).load_all_queryset(Image, Image.objects.select_related('item', 'item__metadatas')) + qs = qs.models(Item).load_all_queryset(Item, Item.objects.select_related('collection', 'metadatas')) if model_type == 'annotations': - qs = qs.models(Annotation).load_all_queryset(Annotation, Annotation.objects.select_related('image', 'stats', 'current_revision', 'author')) + qs = qs.models(Annotation).load_all_queryset(Annotation, Annotation.objects.select_related('image', 'image__item', 'image__item__collection', 'stats', 'current_revision', 'author')) if self.collection_name is not None: qs = qs.filter(collection = self.collection_name) diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/search_indexes/indexes.py --- a/src/iconolab/search_indexes/indexes.py Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/search_indexes/indexes.py Wed Oct 12 13:30:13 2016 +0200 @@ -1,39 +1,37 @@ from django.utils import timezone from haystack import indexes -from iconolab.models import Annotation, Image +from iconolab.models import Annotation, Item -class ImageIndex(indexes.SearchIndex, indexes.Indexable): +class ItemIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) collection = indexes.CharField(model_attr="collection") - authors = indexes.CharField(model_attr="authors") - school = indexes.CharField(model_attr="school") - designation = indexes.CharField(model_attr="designation") - datation = indexes.CharField(model_attr="datation") - technics = indexes.CharField(model_attr="technics") - measurements = indexes.CharField(model_attr="measurements") - - create_or_usage_location = indexes.CharField(model_attr="item__metadatas__create_or_usage_location") - discovery_context = indexes.CharField(model_attr="item__metadatas__discovery_context") - conservation_location = indexes.CharField(model_attr="item__metadatas__conservation_location") + authors = indexes.CharField(model_attr="metadatas__authors") + school = indexes.CharField(model_attr="metadatas__school") + designation = indexes.CharField(model_attr="metadatas__designation") + datation = indexes.CharField(model_attr="metadatas__datation") + technics = indexes.CharField(model_attr="metadatas__technics") + measurements = indexes.CharField(model_attr="metadatas__measurements") + create_or_usage_location = indexes.CharField(model_attr="metadatas__create_or_usage_location") + discovery_context = indexes.CharField(model_attr="metadatas__discovery_context") + conservation_location = indexes.CharField(model_attr="metadatas__conservation_location") - tags = indexes.MultiValueField(model_attr="tag_labels") + #tags = indexes.MultiValueField(model_attr="tag_labels") def get_model(self): - return Image + return Item def index_queryset(self, using=None): - return self.get_model().objects.filter(created__lte=timezone.now()) + return self.get_model().objects.filter() class AnnotationIndex(indexes.SearchIndex, indexes.Indexable): ##indexed field text = indexes.CharField(document=True, use_template=True) - title = indexes.CharField(model_attr="current_revision__title") description = indexes.CharField(model_attr="current_revision__description") - collection = indexes.CharField(model_attr="collection") + collection = indexes.CharField(model_attr="image__item__collection") tags = indexes.MultiValueField(model_attr="tag_labels") ## tags diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/search_indexes/query.py --- a/src/iconolab/search_indexes/query.py Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/search_indexes/query.py Wed Oct 12 13:30:13 2016 +0200 @@ -1,5 +1,5 @@ from haystack.query import RelatedSearchQuerySet -from iconolab.models import Annotation, Image +from iconolab.models import Annotation, Item from pprint import pprint class IconolabRelatedQuerySet(RelatedSearchQuerySet): diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/search_indexes/views.py --- a/src/iconolab/search_indexes/views.py Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/search_indexes/views.py Wed Oct 12 13:30:13 2016 +0200 @@ -11,7 +11,6 @@ form_class = IconolabSearchForm queryset = RelatedSearchQuerySet() template_name = "search/default_search.html" - paginate_by = 10 load_all = True templates_map = { @@ -41,6 +40,7 @@ def get(self, request, *args, **kwargs): self.model_type = request.GET.get('model_type', None) + self.paginate_by = request.GET.get('perpage', 10) collection_name = self.kwargs.get('collection_name', None) if self.model_type is not None: diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/templates/search/annotation_search.html --- a/src/iconolab/templates/search/annotation_search.html Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/templates/search/annotation_search.html Wed Oct 12 13:30:13 2016 +0200 @@ -7,7 +7,7 @@

Recherche

-
+ @@ -20,42 +20,93 @@
-

{{ page_obj.paginator.count }} annotation(s)

- +

{{ page_obj.paginator.count }} annotation(s)

+ + + {% if page_obj.has_previous or page_obj.has_next %} + + {% endif %}
{% endblock %} \ No newline at end of file diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/templates/search/default_search.html --- a/src/iconolab/templates/search/default_search.html Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/templates/search/default_search.html Wed Oct 12 13:30:13 2016 +0200 @@ -7,7 +7,7 @@

Recherche

-
+ diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/templates/search/image_search.html --- a/src/iconolab/templates/search/image_search.html Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/templates/search/image_search.html Wed Oct 12 13:30:13 2016 +0200 @@ -7,7 +7,7 @@

Recherche

- +
@@ -18,33 +18,135 @@
- -

{{ page_obj.paginator.count }} image(s)

- - {% for result in page_obj.object_list %} - - {% thumbnail result.object.media "400x400" crop=False as im %} -
- - - + +

{{ page_obj.paginator.count }} image(s)

+
+
+
    + {% for item in page_obj.object_list %} +
  • +
    + {% if item.object.images.count > 1 %} + {% with item.object.images.first as main_image %} + {% if main_image.height > main_image.width %} + + {% else %} + + {% endif %} + {% endwith %} + {% else %} + {% with item.images.first as main_image %} + + {% endwith %} + {% endif %} +
    + +

    Métadonnées de l'objet

    + {% if item.object.metadatas.designation %}

    Désignation : {{item.object.metadatas.designation}}

    {% endif %} + {% if item.object.metadatas.authors %}

    Auteur(s) : {{item.object.metadatas.designation}}

    {% endif %} + {% if item.object.metadatas.conservation_location %}

    Conservé à : {{item.object.metadatas.conservation_location}}

    {% endif %} + {% if item.object.metadatas.datation %}

    Datation : {{item.object.metadatas.datation}}

    {% endif %} + {% if item.object.metadatas.technics %}
    Techniques : {{item.object.metadatas.technics}}
    {% endif %} + {% if item.object.metadatas.measurements %}
    Mesures : {{item.object.metadatas.measurements}}
    {% endif %} + {% if item.object.metadatas.create_or_usage_location %}
    Lieu de création/utilisation : {{item.object.metadatas.create_or_usage_location}}
    {% endif %} + {% if item.object.metadatas.discovery_context %}
    Contexte de découverte : {{item.object.metadatas.discovery_context}}
    {% endif %} + {% if item.object.metadatas.photo_credits %}
    Crédits photographiques : {{item.object.metadatas.photo_credits}}
    {% endif %} + {% if item.object.metadatas.inventory_number %}
    Numéro d'inventaire : {{item.object.metadatas.inventory_number}}
    {% endif %}
    - {% endthumbnail %} - -

    - {{ result.object.title }} - collection {{result.object.collection}} -

    - {% empty %} -

    Aucune image n'a été trouvée.

    - {% endfor %} - - {% if page_obj.has_previous or page_obj.has_next %} -
    - {% if page_obj.has_previous %}{% endif %}« Previous{% if page_obj.has_previous %}{% endif %} - | - {% if page_obj.has_next %}{% endif %}Next »{% if page_obj.has_next %}{% endif %} -
    - {% endif %} - +
    +
  • + {% endfor %} +
+ + {% if page_obj.has_previous or page_obj.has_next %} +
    + {% if page_obj.has_previous %} +
  • + + + +
  • + {% endif %} + + {% for page in page_obj.paginator.page_range %} + + {% endfor %} + + {% if page_obj.has_next %} +
  • + + + +
  • + {% endif %} +
+ {% endif %} +
+
{% endblock %} \ No newline at end of file diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/templates/search/indexes/iconolab/annotation_text.txt --- a/src/iconolab/templates/search/indexes/iconolab/annotation_text.txt Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/templates/search/indexes/iconolab/annotation_text.txt Wed Oct 12 13:30:13 2016 +0200 @@ -1,5 +1,3 @@ {{ object.current_revision.title }} - {{ object.current_revision.description }} - {{ object.tag_labels }} diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/templates/search/indexes/iconolab/image_text.txt --- a/src/iconolab/templates/search/indexes/iconolab/image_text.txt Tue Oct 11 12:18:52 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -{{ object.school }} -{{ object.authors }} -{{ object.designation }} -{{ object.datation }} -{{ object.technics }} -{{ object.measurements }} - -{{ object.item.metadatas.create_or_usage_location }} -{{ object.item.metadatas.discovery_context }} -{{ object.item.metadatas.conservation_location }} - -{{ object.tag_labels }} \ No newline at end of file diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/templates/search/indexes/iconolab/item_text.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/iconolab/templates/search/indexes/iconolab/item_text.txt Wed Oct 12 13:30:13 2016 +0200 @@ -0,0 +1,9 @@ +{{ object.metadatas.school }} +{{ object.metadatas.authors }} +{{ object.metadatas.designation }} +{{ object.metadatas.datation }} +{{ object.metadatas.technics }} +{{ object.metadatas.measurements }} +{{ object.metadatas.create_or_usage_location }} +{{ object.metadatas.discovery_context }} +{{ object.metadatas.conservation_location }} \ No newline at end of file diff -r cb79037eaa0c -r 6b304e2c6af4 src/iconolab/views/iconolab_objects.py --- a/src/iconolab/views/iconolab_objects.py Tue Oct 11 12:18:52 2016 +0200 +++ b/src/iconolab/views/iconolab_objects.py Wed Oct 12 13:30:13 2016 +0200 @@ -252,7 +252,7 @@ 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)) + image_guid_to_display = request.GET.get("show", 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