Display bookmarked images.
authorAlexandre Segura <mex.zktk@gmail.com>
Wed, 17 May 2017 17:06:07 +0200
changeset 507 1bae3da99830
parent 506 4e18e1f69db9
child 508 3d920e27a465
Display bookmarked images.
src/iconolab/models.py
src/iconolab/templates/iconolab/collection_home.html
src/iconolab/templates/partials/item_images_preview.html
src/iconolab/templatetags/iconolab_tags.py
src_js/iconolab-bundle/src/iconolab.scss
--- a/src/iconolab/models.py	Wed May 17 16:38:08 2017 +0200
+++ b/src/iconolab/models.py	Wed May 17 17:06:07 2017 +0200
@@ -192,6 +192,9 @@
                          for tag_infos in revision_tags if tag_infos.get('tag_label') is not None]  # deal with
         return tag_list
 
+    def is_bookmarked_by(self, user):
+        return Bookmark.objects.filter(image=self, category__user=user).count() > 0
+
 
 class ImageStats(models.Model):
     """
--- a/src/iconolab/templates/iconolab/collection_home.html	Wed May 17 16:38:08 2017 +0200
+++ b/src/iconolab/templates/iconolab/collection_home.html	Wed May 17 17:06:07 2017 +0200
@@ -208,6 +208,10 @@
 
   var $target = $(e.currentTarget);
 
+  if ($target.hasClass('active')) {
+    return;
+  }
+
   $modal.find('.bookmark-title').val($target.data('item'));
   $modal.find('.bookmark-image').val($target.data('image-id'));
 
--- a/src/iconolab/templates/partials/item_images_preview.html	Wed May 17 16:38:08 2017 +0200
+++ b/src/iconolab/templates/partials/item_images_preview.html	Wed May 17 17:06:07 2017 +0200
@@ -1,4 +1,5 @@
 {% load thumbnail %}
+{% load iconolab_tags %}
 
 <div class="item-image-container">
 
@@ -10,11 +11,16 @@
           <img v-el:small-image src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" />
         </a>
       {% endthumbnail %}
-      <a href="#" class="bookmark"
-        title="Ajouter à mes favoris"
+
+      {% is_bookmarked first_image as is_bookmarked %}
+
+      {% if request.user.is_authenticated %}
+      <a href="#" class="bookmark {% if is_bookmarked %}active{% endif %}"
+        title="{% if is_bookmarked %}Ajouté à vos favoris{% else %}Ajouter à mes favoris{% endif %}"
         data-item="{{ item.metadatas.joconde_ref }}"
         data-image-id="{{ first_image.id }}"
         data-image-guid="{{ first_image.image_guid }}"><i class="fa fa-lg fa-star"></i></a>
+      {% endif %}
     </div>
 
     {% if item.images.count > 1 %}
--- a/src/iconolab/templatetags/iconolab_tags.py	Wed May 17 16:38:08 2017 +0200
+++ b/src/iconolab/templatetags/iconolab_tags.py	Wed May 17 17:06:07 2017 +0200
@@ -73,3 +73,8 @@
     if request.resolver_match.url_name in routes:
         return 'container-fluid'
     return 'container'
+
+@register.assignment_tag(takes_context=True)
+def is_bookmarked(context, image):
+    request = context['request']
+    return image.is_bookmarked_by(request.user)
--- a/src_js/iconolab-bundle/src/iconolab.scss	Wed May 17 16:38:08 2017 +0200
+++ b/src_js/iconolab-bundle/src/iconolab.scss	Wed May 17 17:06:07 2017 +0200
@@ -53,6 +53,9 @@
                 &:active {
                     color: darken(#E67E22, 10%);
                 }
+                &.active {
+                    color: #3498DB;
+                }
             }
         }
         .item-image-stats {