Improve homepage.
authorAlexandre Segura <mex.zktk@gmail.com>
Fri, 19 May 2017 16:05:10 +0200
changeset 514 accd1fded1a5
parent 513 2d9c92c0d03a
child 515 c1077e8f595d
Improve homepage. - Add best contributors - Add latest annotations - Add most accurate tags
src/iconolab/models.py
src/iconolab/templates/iconolab/collection_home.html
src/iconolab/templates/iconolab/home.html
src/iconolab/views/objects.py
src_js/iconolab-bundle/src/iconolab.scss
--- a/src/iconolab/models.py	Fri May 19 15:41:53 2017 +0200
+++ b/src/iconolab/models.py	Fri May 19 16:05:10 2017 +0200
@@ -853,7 +853,7 @@
         return self.link.startswith(settings.INTERNAL_TAGS_URL)
 
     def __str__(self):
-        return "Tag:" + self.label
+        return "Tag:" + str(self.label)
 
 
 class TaggingInfo(models.Model):
--- a/src/iconolab/templates/iconolab/collection_home.html	Fri May 19 15:41:53 2017 +0200
+++ b/src/iconolab/templates/iconolab/collection_home.html	Fri May 19 16:05:10 2017 +0200
@@ -80,7 +80,7 @@
             {% for contributor in annotation.stats.contributors %}
               {{ contributor }}
             {% endfor %}
-            <p>
+            </p>
             <p>{{ annotation.current_revision.description }}</p>
             {% for tagging_info in annotation.current_revision.tagginginfo_set.all %}
               <p>
--- a/src/iconolab/templates/iconolab/home.html	Fri May 19 15:41:53 2017 +0200
+++ b/src/iconolab/templates/iconolab/home.html	Fri May 19 16:05:10 2017 +0200
@@ -4,6 +4,7 @@
 {% load staticfiles %}
 {% load thumbnail %}
 {% load iconolab_tags %}
+{% load humanize %}
 
 {% block content %}
 <div id="homepage-main">
@@ -12,10 +13,16 @@
     est actuellement en cours de développement.</strong></p>
     <p>La première phase d'expérimentation démarrera mi-mars 2017. Pour plus d'informations, prière de contacter <a href="mailto:{{ contact }}">{{ contact }}</a>.</p>
   </div>
+  <div class="row">
+    <div class="col-xs-12">
+      <h3>Les collections</h3>
+    </div>
+  </div>
   <div id="main-panel" class="row">
+
     {% for collection in collections_primary %}
     <div class="col-md-3">
-      <div>
+      <div class="home-collection">
         {% thumbnail collection.image "450x250" crop="center" as im %}
         <div>
           <a href="{% url 'collection_home' collection.name %}">
@@ -27,12 +34,82 @@
           Contribuer
         </a>
         <hr>
-        <p>{{collection.description|safe}}</p>
+        <p class="home-collection-description" title="{{collection.description|safe}}">{{collection.description|safe}}</p>
         {% endthumbnail %}
       </div>
     </div>
     {% endfor %}
   </div>
+  <div class="row">
+    <div class="col-md-6">
+      <h3>Les dernières annotations</h3>
+      {% for annotation in latest_annotations %}
+      <div class="panel panel-default">
+        <div class="panel-body">
+
+          <div class="row">
+            <div class="col-md-4">
+              <div class="fragment-container" style="position: relative">
+                {% thumbnail annotation.image.media "100x100" 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>
+            <div class="col-md-8">
+
+              <h4>
+                {{ annotation.current_revision.title }}
+                <small class="pull-right">{{ annotation.current_revision.created|naturaltime }}</small>
+              </h4>
+              <p>
+                {% for contributor in annotation.stats.contributors %}
+                <a href="{% url 'user_home' contributor.username %}">{{ contributor.username }}</a>
+                {% endfor %}
+              </p>
+              <p>{{ annotation.current_revision.description }}</p>
+              <p>
+                {% for tagging_info in annotation.current_revision.tagginginfo_set.all %}
+                <span class="label label-default"><i class="fa fa-tag"></i> {{ tagging_info.tag.label }}</span>
+                {% endfor %}
+              </p>
+            </div>
+          </div>
+        </div>
+      </div>
+      {% endfor %}
+    </div>
+    <div class="col-md-6">
+      <h3>Les meilleurs contributeurs</h3>
+      <ul class="list-group">
+      {% for best_contributor in best_contributors %}
+        <li class="list-group-item">
+          <span class="badge">{{ best_contributor.contributions }}</span>
+          <a href="{% url 'user_home' best_contributor.author.username %}">{{ best_contributor.author.username }}</a>
+        </li>
+      {% endfor %}
+      </ul>
+
+      <h3>Les mots-clé les plus pertinents</h3>
+      <ul class="list-group">
+        {% for most_accurate_tag in most_accurate_tags %}
+        <li class="list-group-item">
+          <span class="badge">{{ most_accurate_tag.annotation_count }}</span>
+          <a href="{% url 'search_indexes:model_search' 'annotations' %}?q={{ most_accurate_tag.tag.label }}">
+            {{ most_accurate_tag.tag.label }}
+          </a>
+        </li>
+        {% endfor %}
+      </ul>
+
+    </div>
+  </div>
   {% for collection in collections_secondary %}
   <div id="collection-panel-{{collection.name}}" class="container collection-container panel panel-default">
     <div class="row">
--- a/src/iconolab/views/objects.py	Fri May 19 15:41:53 2017 +0200
+++ b/src/iconolab/views/objects.py	Fri May 19 16:05:10 2017 +0200
@@ -13,7 +13,7 @@
 from django.contrib.sites.models import Site
 from django.conf import settings
 from notifications.models import Notification
-from iconolab.models import Annotation, AnnotationRevision, Collection, Folder, Item, Image, IconolabComment, MetaCategory, MetaCategoryInfo, BookmarkCategory, Bookmark
+from iconolab.models import Annotation, AnnotationRevision, Collection, Folder, Item, Image, IconolabComment, MetaCategory, MetaCategoryInfo, BookmarkCategory, Bookmark, Tag, TaggingInfo
 from iconolab.forms.annotations import AnnotationRevisionForm
 from iconolab.forms.bookmarks import BookmarkForm
 from iconolab.serializers import AnnotationRevisionSerializer
@@ -38,6 +38,38 @@
         context = {}
         context['collections_primary'] = Collection.objects.filter(show_image_on_home=True).all()
         context['collections_secondary'] = Collection.objects.filter(show_image_on_home=False).all()
+        context['latest_annotations'] = Annotation.objects.order_by("-created").all()[:5]
+
+        # Best contributors
+        count_contributions = Annotation.objects.all()\
+            .values('author').annotate(contributions=Count('author')).order_by('-contributions')[:10]
+        best_contributors = []
+        for count_contribution in count_contributions:
+            author = User.objects.get(id=count_contribution['author'])
+            best_contributors.append({
+                'author': author,
+                'contributions': count_contribution['contributions']
+            })
+        context['best_contributors'] = best_contributors
+
+        # Most accurate tags (tags with accuracy >= 4)
+        rows = TaggingInfo.objects\
+            .prefetch_related('revision', 'revision__annotation')\
+            .filter(accuracy__gte=4)\
+            .values('tag')\
+            .annotate(annotation_count=Count('revision__annotation', distinct=True))\
+            .order_by('-annotation_count')\
+            .all()[:10]
+
+        most_accurate_tags = []
+        for row in rows:
+            tag = Tag.objects.get(id=row['tag'])
+            most_accurate_tags.append({
+                'tag': tag,
+                'annotation_count': row['annotation_count']
+            })
+        context['most_accurate_tags'] = most_accurate_tags
+
         context['contact'] = settings.CONTACT_EMAIL
         context['homepage'] = True
         return render(request, 'iconolab/home.html', context)
--- a/src_js/iconolab-bundle/src/iconolab.scss	Fri May 19 15:41:53 2017 +0200
+++ b/src_js/iconolab-bundle/src/iconolab.scss	Fri May 19 16:05:10 2017 +0200
@@ -338,6 +338,18 @@
 	margin-top:0px;
 }
 
+.home-collection-description {
+    $max-lines: 5;
+    display: block; /* Fallback for non-webkit */
+    display: -webkit-box;
+    line-height: $line-height-computed;
+    max-height: ($line-height-computed * $max-lines);
+    -webkit-line-clamp: $max-lines;
+    -webkit-box-orient: vertical;
+    overflow: hidden;
+    text-overflow: ellipsis;
+}
+
 /* COLLECTION HOME PAGE */
 
 .collection-summary{