Finished work on user page annotation panels + small fixes on header and css
authordurandn
Tue, 16 Aug 2016 14:50:28 +0200
changeset 127 270d165cd0d5
parent 126 b5aa7e6f6a01
child 128 6ae78ea513e8
Finished work on user page annotation panels + small fixes on header and css
src/iconolab/static/iconolab/css/iconolab.css
src/iconolab/templates/iconolab/detail_revision.html
src/iconolab/templates/iconolab/user_home.html
src/iconolab/templates/partials/header.html
src/iconolab/templates/partials/user_page_annotation_panel.html
src/iconolab/views/iconolab.py
--- a/src/iconolab/static/iconolab/css/iconolab.css	Tue Aug 16 11:01:35 2016 +0200
+++ b/src/iconolab/static/iconolab/css/iconolab.css	Tue Aug 16 14:50:28 2016 +0200
@@ -70,6 +70,8 @@
 	cursor: pointer;	
 }
 
+/* BADGES */
+
 .badge-error {
   background-color: #b94a48;
 }
@@ -89,6 +91,30 @@
 .notif-badge{
   margin-bottom: 5px;
 }
+
+/* USER PAGE */
+
 .show-all-notifications{
   cursor: pointer;
+}
+.annotation-panel{
+	min-width: 535px;
+}
+.annotation-detail{
+	vertical-align: middle;
+	display:inline-block;
+	margin-right: 15px;
+	margin-left: 15px;
+}
+.no-user-annotation{
+	margin-left: 15px;
+}
+.dt-annotation{
+	margin-bottom: 10px;
+}
+.userpage-annotation-btn{
+	display:inline-block; 
+	vertical-align: top; 
+	margin-top: 15px; 
+	margin-right: 15px;
 }
\ No newline at end of file
--- a/src/iconolab/templates/iconolab/detail_revision.html	Tue Aug 16 11:01:35 2016 +0200
+++ b/src/iconolab/templates/iconolab/detail_revision.html	Tue Aug 16 14:50:28 2016 +0200
@@ -25,7 +25,7 @@
 					{% endthumbnail %}
 				</div>
                 <br>
-                <a href="{% url 'image_detail' collection_name image_guid %}"><i class="fa fa-picture-o" aria-hidden="true"></i> Revoir l'image </a><br>
+                <a href="{% url 'item_detail' collection_name image.item.item_guid %}"><i class="fa fa-picture-o" aria-hidden="true"></i> Voir l'objet de cette annotation </a><br>
                 <a href="{% url 'annotation_detail' collection_name image_guid annotation_guid  %}"><i class="fa fa-reply" aria-hidden="true"></i> Retour sur l'annotation</a><br>
             </div>
 			<div id="revision-detail" class='col-xs-6' style="">
--- a/src/iconolab/templates/iconolab/user_home.html	Tue Aug 16 11:01:35 2016 +0200
+++ b/src/iconolab/templates/iconolab/user_home.html	Tue Aug 16 14:50:28 2016 +0200
@@ -53,58 +53,56 @@
         <div class="row">
           <div class="col-md-6">
             <h4>{% if profile_user == request.user %}Mes annotations:{% else %}Annotations de {{profile_user.username}}{% endif %} </h4>
-            <ul class="list-inline">
+            
             {% if not user_annotations %}
-              Aucune annotation à afficher
+              <h4 class="no-user-annotation"><small>Aucune annotation à afficher</small></h4>
+            {% else %}
+              <ul class="list-inline">
+                {% for annotation in user_annotations.all %}
+                  {% include "partials/user_page_annotation_panel.html" with annotation=annotation %}
+                {% endfor %}
+              </ul>
             {% endif %}
-            {% for annotation in user_annotations.all %}
-            <li>
-              <div class="panel panel-default" style="min-width: 375px;">
-                  <div class="panel-heading">{{annotation.current_revision.title}}</div>
-                  <div class="fragment-container" style="position:relative; display:inline-block">
-                    {% thumbnail annotation.image.media "150x150" crop=False as im %}
-                      <a href="{% url 'annotation_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid %}">
-                        <img v-el:small-image src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" />
-                        <svg width="{{ im.width }}" height="{{ im.height }}" version="1.1" style="position:absolute; top:0px; left: 0px">
-                          <g transform="matrix({% transform_matrix im_width=im.width im_height=im.height max_x=100 max_y=100 %})">
-                            <path d="{{ annotation.current_revision.fragment|clean_path }}" opacity="0.7" fill="orange"></path>
-                          </g>
-                        </svg>
-                      </a>
-                    {% endthumbnail %}
-                  </div>
-                  <div class="annotation-detail" style="display:inline-block; position:relative; margin-right: 15px;">
-                    <dl class="dl-horizontal">
-                      <dt>Commentaires: </dt>
-                      <dd><span class="badge">{{annotation.stats.comments_count}}</span></dd>
-                      <dt>Révisions en attente:</dt>
-                      <dd><span class="badge {% if annotation.stats.awaiting_revisions_count > 0 %}badge-warning{% endif %}">{{annotation.stats.awaiting_revisions_count}}</span></dd>
-                    </dl>
-                  </div>
-              </div>
-            </li>
-            {% endfor %}
-            </ul>
           </div>
           <div class="col-md-6">
             <h4>{% if profile_user == request.user %}Mes autres contributions:{% else %}Contributions de {{profile_user.username}}{% endif %} </h4>
             <dl>
-              <dt>
-              {% if profile_user == request.user %}
-                Annotations sur lesquelles j'ai commenté:
-              {% else %}
-                Annotations sur lesquelles {{profile_user.username}} a commenté:
-              {% endif %}
-              </dt>
-              <dd>{{user_comments_annotations.all}}</dd>
-              <dt>
+            <dt class="dt-annotation">
               {% if profile_user == request.user %}
                 Annotations sur lesquelles j'ai proposé des révisions
               {% else %}
                 Annotations sur lesquelles {{profile_user.username}} a proposé des révisions:
               {% endif %} 
               </dt>
-              <dd>{{user_revisions_annotations.all}}</dd>
+              <dd>
+              {% if not user_revisions_annotations %}
+                 <h4 class="no-user-annotation"><small>Aucune annotation à afficher</small></h4>
+              {% else %}
+                <ul class="list-inline">
+                  {% for annotation in user_revisions_annotations.all %}
+                    {% include "partials/user_page_annotation_panel.html" with annotation=annotation %}
+                  {% endfor %}
+                </ul>
+              {% endif %}
+              </dd>
+              <dt class="dt-annotation">
+              {% if profile_user == request.user %}
+                Annotations sur lesquelles j'ai commenté (sans proposer de révision):
+              {% else %}
+                Annotations sur lesquelles {{profile_user.username}} a commenté (sans proposer de révision):
+              {% endif %}
+              </dt>
+              <dd>
+              {% if not user_comments_annotations %}
+                 <h4 class="no-user-annotation"><small>Aucune annotation à afficher</small></h4>
+              {% else %}
+                <ul class="list-inline">
+                  {% for annotation in user_comments_annotations.all %}
+                    {% include "partials/user_page_annotation_panel.html" with annotation=annotation %}
+                  {% endfor %}
+                </ul>
+              {% endif %}
+              </dd>
             </dl>
           </div>
         </div>
--- a/src/iconolab/templates/partials/header.html	Tue Aug 16 11:01:35 2016 +0200
+++ b/src/iconolab/templates/partials/header.html	Tue Aug 16 14:50:28 2016 +0200
@@ -22,7 +22,7 @@
         {% if request.user.is_authenticated %}
           {% notifications_unread as unread_count %}
           <li><a href="{% url 'user_home' request.user.id %}">
-            {{user.username}}: Mon espace <span class="badge {% if unread_count %}badge-warning{% endif %}">
+            {{request.user.username}}: Mon espace <span class="badge {% if unread_count %}badge-warning{% endif %}">
             {{ unread_count }} <i class="fa fa-envelope-o" aria-hidden="true"></i> </span>
           </a></li>
           <li><a href="{% url 'account:logout' %}">Se déconnecter</a></li>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/iconolab/templates/partials/user_page_annotation_panel.html	Tue Aug 16 14:50:28 2016 +0200
@@ -0,0 +1,31 @@
+{% load thumbnail %}
+{% load iconolab_tags %}
+<li>
+  <div class="panel panel-default annotation-panel">
+      <div class="panel-heading">{{annotation.current_revision.title}}</div>
+      
+      <div class="fragment-container" style="position:relative; display:inline-block">
+        {% thumbnail annotation.image.media "150x150" crop=False as im %}
+          <a href="{% url 'annotation_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid %}">
+            <img v-el:small-image src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" />
+            <svg width="{{ im.width }}" height="{{ im.height }}" version="1.1" style="position:absolute; top:0px; left: 0px">
+              <g transform="matrix({% transform_matrix im_width=im.width im_height=im.height max_x=100 max_y=100 %})">
+                <path d="{{ annotation.current_revision.fragment|clean_path }}" opacity="0.7" fill="orange"></path>
+              </g>
+            </svg>
+          </a>
+        {% endthumbnail %}
+      </div>
+      <div class="annotation-detail">
+        <dl class="dl-horizontal">
+          <dt>Commentaires: </dt>
+          <dd><span class="badge">{{annotation.stats.comments_count}}</span></dd>
+          <dt>Révisions en attente:</dt>
+          <dd><span class="badge {% if annotation.stats.awaiting_revisions_count > 0 %}badge-warning{% endif %}">{{annotation.stats.awaiting_revisions_count}}</span></dd>
+          <dt>Révisions acceptée:</dt>
+          <dd><span class="badge">{{annotation.stats.accepted_revisions_count}}</span></dd>
+        </dl>
+      </div>
+      <a class="btn btn-default btn-sm userpage-annotation-btn pull-right" href="{% url 'annotation_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid %}">Voir annotation</a>
+  </div>
+</li>
\ No newline at end of file
--- a/src/iconolab/views/iconolab.py	Tue Aug 16 11:01:35 2016 +0200
+++ b/src/iconolab/views/iconolab.py	Tue Aug 16 14:50:28 2016 +0200
@@ -51,7 +51,13 @@
         ).distinct()
         comments_annotations_str_id = IconolabComment.objects.filter(user=profile_user, content_type__app_label="iconolab", content_type__model="annotation").values_list("object_pk", flat=True)
         comments_annotations_id = [int(str_id) for str_id in comments_annotations_str_id]
-        context["user_comments_annotations"] = Annotation.objects.filter(id__in=comments_annotations_id).exclude(author=profile_user).distinct()
+        context["user_comments_annotations"] = Annotation.objects.filter(id__in=comments_annotations_id).exclude(author=profile_user).exclude(annotation_guid__in=context["user_revisions_annotations"].values_list("annotation_guid", flat=True)).prefetch_related(
+            "current_revision", 
+            "revisions", 
+            "image", 
+            "image__item", 
+            "image__item__collection"
+        ).distinct()
         if request.user.is_authenticated() and self.object == request.user:
             if request.GET.get("clear_notifications", False):
                 Notification.objects.filter(recipient=request.user).mark_all_as_read()
@@ -406,7 +412,7 @@
         context['tags_data'] = revision.get_tags_json()
         context['comment'] = revision.creation_comment.first()
         if request.user.is_authenticated() and annotation.author == request.user:
-            notified_revision = Notification.objects.filter(
+            ann_author_notified = Notification.objects.filter(
                     recipient=request.user, 
                     action_object_content_type__app_label="iconolab", 
                     action_object_content_type__model="annotationrevision",
@@ -415,8 +421,21 @@
                     target_content_type__model="annotation",
                     target_object_id=annotation.id
                 ).unread()
-            if notified_revision:
-                notified_revision.first().mark_as_read()
+            if ann_author_notified:
+                ann_author_notified.first().mark_as_read()
+                context["notified_revision"] = True
+        if request.user.is_authenticated() and revision.author == request.user:
+            rev_author_notified = Notification.objects.filter(
+                    recipient=request.user, 
+                    action_object_content_type__app_label="iconolab", 
+                    action_object_content_type__model="annotationrevision",
+                    action_object_object_id=revision.id,
+                    target_content_type__app_label="iconolab",
+                    target_content_type__model="annotation",
+                    target_object_id=annotation.id
+                ).unread()
+            if rev_author_notified:
+                rev_author_notified.first().mark_as_read()
                 context["notified_revision"] = True
         return render(request, 'iconolab/detail_revision.html', context)