First step of tag management for contents.
authorcavaliet
Tue, 17 Jan 2012 17:53:21 +0100
changeset 409 e4855d669c55
parent 408 b7662f1c13da
child 410 35453efed7ed
First step of tag management for contents.
src/ldt/ldt/ldt_utils/models.py
src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html
src/ldt/ldt/ldt_utils/templates/front/front_base.html
src/ldt/ldt/ldt_utils/templates/front/front_home.html
src/ldt/ldt/ldt_utils/views/front.py
src/ldt/ldt/static/ldt/css/front_common.css
--- a/src/ldt/ldt/ldt_utils/models.py	Tue Jan 17 16:30:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py	Tue Jan 17 17:53:21 2012 +0100
@@ -18,6 +18,7 @@
 import mimetypes
 import os.path
 import tagging.fields
+from tagging.models import Tag
 import uuid
 
 
@@ -370,6 +371,10 @@
             
         assign('ldt_utils.change_content', request_user, self)
         self.save()
+    
+    # Tag management
+    def get_tags(self):
+        return Tag.objects.get_for_object(self)
 
 
     
--- a/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html	Tue Jan 17 16:30:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html	Tue Jan 17 17:53:21 2012 +0100
@@ -63,9 +63,11 @@
 {% block body %}
 {{block.super}}
 <!-- Last annotated contents -->
+{% if tag_cloud|length > 0 %}<p class="tag_link">{% trans 'Filter the medias' %} : {% for t in tag_cloud|slice:":5" %}<a href="{% url ldt.ldt_utils.views.front.all_contents %}?tag={{t.name}}">{{t.name}}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</p>{% endif %}
 <ul class="floatlist full_width" id="derniers_medias">
     <li class="li_h2">
-        <h2>{% trans 'All medias' %}</h2>
+        {% if tag_label %}<h2><a href="{% url ldt.ldt_utils.views.front.all_contents %}">{% trans 'All medias' %}</a>{% if tag_label %}<span class="pink"> &gt; {{tag_label}}</span>{% endif %}</h2>
+        {% else %}<h2>{% trans 'All medias' %}</h2>{% endif %}
     </li>
     {% for content in content_list %}
     <li class="li_media">
@@ -77,5 +79,9 @@
     </li>
     {% endfor %}
 </ul>
+{% if tag_cloud|length > 0 %}<p class="left tag_link">{% trans 'All tags' %} : {% for t in tag_cloud %}<a href="{% url ldt.ldt_utils.views.front.all_contents %}?tag={{t.name}}">
+  <span style="font-size:{{t.font_size|add:"10"}}px;">{{t.name}}</span>
+  </a>{% if not forloop.last %}, {% endif %}{% endfor %}</p>
+{% endif %}
 {% endblock %}
 
--- a/src/ldt/ldt/ldt_utils/templates/front/front_base.html	Tue Jan 17 16:30:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_base.html	Tue Jan 17 17:53:21 2012 +0100
@@ -34,10 +34,11 @@
             </form>
         <li id="li_annotation">
             <div class="fl">
-                <a href="#"><img src="{{LDT_MEDIA_PREFIX}}img/annot_icon.png" id="annot_icon" /></a>
+                <!-- a href="#"><img src="{{LDT_MEDIA_PREFIX}}img/annot_icon.png" id="annot_icon" /></a -->
+                <a href="http://www.iri.centrepompidou.fr" target="_blank">IRI</a>
             </div>
             <div class="fl">
-                <a href="{% url root-view %}">{% trans 'Annotate' %}</a>
+                <!-- a href="{% url root-view %}">{% trans 'Annotate' %}</a -->
             </div>
         </li>
         <li id="li_connexion">
--- a/src/ldt/ldt/ldt_utils/templates/front/front_home.html	Tue Jan 17 16:30:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_home.html	Tue Jan 17 17:53:21 2012 +0100
@@ -14,6 +14,7 @@
 {% block body %}
 {{block.super}}
 <!-- Last annotated contents -->
+{% if tag_cloud|length > 0 %}<p class="tag_link">{% trans 'Filter the medias' %} : {% for t in tag_cloud %}<a href="{% url ldt.ldt_utils.views.front.all_contents %}?tag={{t.name}}">{{t.name}}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</p>{% endif %}
 <ul class="floatlist full_width" id="derniers_medias">
     <li class="li_h2">
       <ul class="title_ul">
--- a/src/ldt/ldt/ldt_utils/views/front.py	Tue Jan 17 16:30:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/front.py	Tue Jan 17 17:53:21 2012 +0100
@@ -9,6 +9,7 @@
 from ldt.ldt_utils.models import Content, Project
 from ldt.ldt_utils.views.workspace import search_index as ws_search_index, search_listing as ws_search_listing
 from ldt.security.utils import add_change_attr
+from tagging.models import Tag, TaggedItem
 
 
 @login_required
@@ -19,12 +20,13 @@
     most_contents = Content.objects.order_by('-nb_annotation')[:8]
     # Get the active groups
     active_groups = Group.objects.exclude(name=settings.PUBLIC_GROUP_NAME)[:5]
-    
+    # Get the main tag list
+    tag_cloud = get_content_tags(5)
     
     is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1);
 
     return render_to_response("front/front_home.html",
-                              {'last_contents': last_contents, 'most_contents':most_contents, 'active_groups':active_groups,
+                              {'last_contents': last_contents, 'most_contents':most_contents, 'active_groups':active_groups, 'tag_cloud':tag_cloud,
                                'is_gecko': is_gecko},
                               context_instance=RequestContext(request))
 
@@ -49,13 +51,20 @@
 
 @login_required
 def all_contents(request):
+    # Get the tag parameter if possible
+    tag_label = request.GET.get("tag")
     # Get all the public contents group
-    content_list = add_change_attr(request.user, Content.safe_objects.all())
+    if tag_label is None :
+        content_list = add_change_attr(request.user, Content.safe_objects.all())
+    else :
+        content_list = TaggedItem.objects.get_by_model(add_change_attr(request.user, Content.safe_objects.all()), '"'+tag_label+'"')
+    # Get the main tag list
+    tag_cloud = get_content_tags()
     
     is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1);
 
     return render_to_response("front/front_all_contents.html",
-                              {'content_list':content_list, 
+                              {'content_list':content_list, 'tag_label':tag_label, 'tag_cloud':tag_cloud,
                                'is_gecko': is_gecko},
                               context_instance=RequestContext(request))
 
@@ -79,7 +88,7 @@
             proj = Project.safe_objects.filter(contents__in=[content])[0]
     else :
         proj = Project.safe_objects.get(ldt_id=project_id)
-        
+    
     # Vars for player
     player_id = "player_project_" + proj.ldt_id
     
@@ -111,3 +120,13 @@
 @login_required
 def search_listing(request):
     return ws_search_listing(request, front_template=True)
+
+
+def get_content_tags(limit=None, steps=10):
+    if limit is None:
+        return Tag.objects.cloud_for_model(Content, steps=steps)
+    else :
+        return Tag.objects.cloud_for_model(Content, steps=steps)[:limit]
+
+
+    
--- a/src/ldt/ldt/static/ldt/css/front_common.css	Tue Jan 17 16:30:40 2012 +0100
+++ b/src/ldt/ldt/static/ldt/css/front_common.css	Tue Jan 17 17:53:21 2012 +0100
@@ -55,7 +55,7 @@
     font-family: "DIN-Bold", Helvetica, Arial, sans-serif;
 }
 
-h2 {
+h2, h2 a {
     font-family: "DIN-Light", Helvetica, Arial, sans-serif; font-size: 21px; color: #0068c4; margin: 4px 2px;
 }
 
@@ -182,7 +182,7 @@
 /* Barre de titre */
 
 #title_bar {
-    font-family: "DIN-Light", Helvetica, Arial, sans-serif; height: 50px; font-size: 22px; margin: 0 0 1px 0;
+    font-family: "DIN-Light", Helvetica, Arial, sans-serif; height: 50px; font-size: 22px; margin: 0 0 1px 0; width: 980px;
 }
 
 #title_bar a {
@@ -213,6 +213,18 @@
     margin: 3px 10px 0 0;
 }
 
+/* Link for media tag/filter */
+.tag_link {
+    float:right;
+}
+.tag_link a {
+    color: #ff3b77;
+}
+.left {
+    float: left;
+}
+
+
 
 /* Footer */