Merging with the latest version from upstream
authorhamidouk
Fri, 13 Jan 2012 10:09:18 +0100
changeset 379 4af2a8d56916
parent 378 5f6012d0a7ac (current diff)
parent 374 81a8dbb23809 (diff)
child 380 ae8ab8763cfd
Merging with the latest version from upstream
--- a/src/ldt/ldt/ldt_utils/projectserializer.py	Fri Jan 13 10:07:16 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/projectserializer.py	Fri Jan 13 10:09:18 2012 +0100
@@ -1,3 +1,4 @@
+from django.conf import settings
 from datetime import datetime
 from django.utils.datastructures import SortedDict
 from ldt.ldt_utils.models import Content
@@ -15,7 +16,7 @@
 """
 class ProjectSerializer:
     
-    def __init__(self, project, from_contents=True, from_display=True):
+    def __init__(self, project, from_contents=True, from_display=True, first_cutting=None, viewable_contents=[]):
         self.project = project
         self.parsed = False
         self.ldt_doc = None
@@ -32,6 +33,8 @@
         self.display_contents_list = []
         self.display_cuttings_list = []
         self.display_ensemble_list = []
+        self.viewable_contents = viewable_contents
+        self.first_cutting = first_cutting
         
         
     def __parse_views(self, display_node_list):
@@ -41,6 +44,7 @@
                 continue
             content_list = []
             cuttings_list = []
+            
             new_display = {
                 "id": display_id,
                 "contents": content_list,
@@ -62,9 +66,23 @@
                     ensemble_id = cutting_node.get("idens")
                     if ensemble_id not in self.display_ensemble_list:
                         self.display_ensemble_list.append(ensemble_id)
+            
+            # sets cutting to display in first position for the metadataplayer
+            if self.first_cutting:
+                first_cutting = "c_%s" % self.first_cutting.upper()
+                
+                annotation_types = new_display['annotation_types']
+                if len(annotation_types) > 1:
+                    index = -1
+                    for i, s in enumerate(annotation_types):
+                        if s == first_cutting: 
+                            index = i
+                            break
+                    if index >= 0:
+                        annotation_types[0], annotation_types[index] = annotation_types[index], annotation_types[0]
+                
             self.views_dict[display_id] = new_display
-                    
-        
+            
     
     def __parse_ensemble(self, ensemble_node, content):
         
@@ -329,7 +347,9 @@
 
         href = ""
         meta_item_value = ""
-        if content.videopath:
+        if content.iri_id not in self.viewable_contents:
+            href = settings.FORBIDDEN_STREAM_URL
+        elif content.videopath:
             href = content.videopath.rstrip('/') + "/" + content.src
             meta_item_value = content.videopath.rstrip('/') + "/"
 
@@ -396,8 +416,19 @@
         res['annotation-types'] = self.annotation_types_dict.values() if len(self.annotation_types_dict) > 0 else None
         res['annotations'] = self.annotations_dict.values() if len(self.annotations_dict) > 0 else None 
 
+
+        if self.first_cutting:
+            first_cutting = "c_%s" % self.first_cutting.upper()
+            
+            index = -1
+            for i, ann in enumerate(res['annotation-types']):
+                if ann['id'] == first_cutting:
+                    index = i
+                    break
+                 
+            if index > 0:
+                res['annotation-types'][0],  res['annotation-types'][1] = res['annotation-types'][1],  res['annotation-types'][0]
         
-
         return res
     
     def get_annotations(self, first_cutting=True):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html	Fri Jan 13 10:09:18 2012 +0100
@@ -0,0 +1,57 @@
+{% extends "front/front_base.html" %}
+{% load i18n %}
+{% load thumbnail %}
+{% load front_tags %}
+
+{% block title %}Lignes de temps : groupe "{{group.name}}"{% endblock %}
+
+{% block js_import %}
+{{block.super}}
+<script src="{{LDT_MEDIA_PREFIX}}js/jquery.min.js" type="text/javascript"/></script>
+<script src="{{LDT_MEDIA_PREFIX}}js/jquery.sparkline.min.js" type="text/javascript"/></script>
+{% endblock %}
+
+{% block css_import %}
+{{block.super}}
+<link rel="stylesheet" href="{{LDT_MEDIA_PREFIX}}css/front_home.css" type="text/css"/>
+{% endblock %}
+
+{% block js_declaration %}
+{{block.super}}
+<script type="text/javascript">
+    $(document).ready(function () {
+        // We draw the annotation volume for each content
+        /* Use 'html' instead of an array of values to pass options 
+        to a sparkline with data in the tag */
+        $('.graph_annotation').sparkline('html', {width: '293px',
+                                                  height:'20px',
+                                                  minSpotColor: false,
+                                                  maxSpotColor: false,
+                                                  spotColor: false,
+                                                  lineWidth: '0px',
+                                                  fillColor: '#adadad',
+                                                  lineColor: '#adadad'});
+    });
+</script>
+
+{% endblock %}
+
+{% block body %}
+{{block.super}}
+<!-- Last annotated contents -->
+<ul class="floatlist full_width" id="derniers_medias">
+    <li class="li_h2">
+        <h2>{% trans 'All medias' %}</h2>
+    </li>
+    {% for content in content_list %}
+    <li class="li_media">
+        <a href="{% url ldt.ldt_utils.views.front.annot_content content.iri_id %}">{% thumbnail content.image "294x165" format="PNG" crop="center" as im %}<img src="{{ im.url }}" class="img_media" width="{{ im.width }}" height="{{ im.height }}">{% endthumbnail %}
+        <span class="graph_annotation">{{ content.stat_annotation }}</span></a>
+        <div class="bulle_annot">{{ content.nb_annotation }}</div>
+        <p><a href="{% url ldt.ldt_utils.views.front.annot_content content.iri_id %}"><b>{% if content.title|length > 69 %}{{content.title|slice:":69"}}...{% else %}{{content.title}}{% endif %}</b></a></p>
+        <p>{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}</p>
+    </li>
+    {% endfor %}
+</ul>
+{% endblock %}
+
--- a/src/ldt/ldt/ldt_utils/templates/front/front_home.html	Fri Jan 13 10:07:16 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_home.html	Fri Jan 13 10:09:18 2012 +0100
@@ -16,7 +16,12 @@
 <!-- Last annotated contents -->
 <ul class="floatlist full_width" id="derniers_medias">
     <li class="li_h2">
-        <h2>{% trans 'Last annotated medias' %}</h2>
+      <ul class="title_ul">
+        <li><h2>{% trans 'Last annotated medias' %}</h2></li>
+	    <li class="li_right">
+	        <a class="blue" href="{% url ldt.ldt_utils.views.front.all_contents %}"><img src="{{LDT_MEDIA_PREFIX}}img/little_plus.png" alt="" />&nbsp;{% trans 'All medias' %}</a>
+	    </li>
+      </ul>
     </li>
     {% for content in last_contents %}
     <li class="li_media">
@@ -30,7 +35,12 @@
 <!-- Most annotated contents -->
 <ul class="floatlist" id="plus_annotes">
     <li class="li_h2">
-        <h2>{% trans 'Most annotated medias' %}</h2>
+      <ul class="title_ul">
+        <li><h2>{% trans 'Most annotated medias' %}</h2></li>
+        <li class="li_right">
+            <a class="blue" href="{% url ldt.ldt_utils.views.front.all_contents %}"><img src="{{LDT_MEDIA_PREFIX}}img/little_plus.png" alt="" />&nbsp;{% trans 'All medias' %}</a>
+        </li>
+      </ul>
     </li>
     {% for content in most_contents %}
     <li class="li_media">
--- a/src/ldt/ldt/ldt_utils/templates/front/front_search_results.html	Fri Jan 13 10:07:16 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_search_results.html	Fri Jan 13 10:09:18 2012 +0100
@@ -8,7 +8,7 @@
 {% block js_import %}
 {{block.super}}
 <script src="{{LDT_MEDIA_PREFIX}}js/jquery.min.js" type="text/javascript"/></script>
-<script src="{{LDT_MEDIA_PREFIX}}js/jquery.sparkline.min.js" type="text/javascript"/></script>
+<script src="{{LDT_MEDIA_PREFIX}}js/raphael.js" type="text/javascript"/></script>
 {% endblock %}
 
 {% block css_import %}
@@ -18,25 +18,77 @@
 
 {% block body %}
 {{block.super}}
-
-
 <script type="text/javascript">
+    var _medias = [ {% for res in results.object_list %}
+        {
+            "iri_id" : '{{ res.content.iri_id }}',
+            "duration" : {{ res.content.duration }},
+            "segments" : [ {% for segment in res.list %}
+                {
+                    "id" : '{{segment.element_id}}',
+                    "begin" : {{segment.begin}},
+                    "duration" : {{segment.duration}},
+                },{% endfor %}
+            ],
+            "stats" : [{{ res.content.stat_annotation }}],
+        },{% endfor %}
+    ];
+    function getRect(_el) {
+        var _sid = _el.id.substr(3);
+        for (var _i = 0; _i < _medias.length; _i++) {
+            for (var _j = 0; _j < _medias[_i].segments.length; _j++) {
+                if (_medias[_i].segments[_j].id == _sid) {
+                    return _medias[_i].segments[_j].rect;
+                }
+            }
+        }
+    }
     $(document).ready(function () {
-    	
-        $('.graph_annotation').sparkline('html', {width: '340px',
-        										  height:'25px',
-        										  minSpotColor: false,
-        										  maxSpotColor: false,
-        										  spotColor: false,
-        										  lineWidth: '0px',
-        										  fillColor: '#adadad',
-        										  lineColor: '#adadad'}); 
-
-        /* Use 'html' instead of an array of values to pass options 
-        to a sparkline with data in the tag */
+        $('.graph_annotation').each(function(_i) {
+            var _values = _medias[_i].stats,
+                _nb = _values.length,
+                _max = _values.reduce(function(_a,_b) {
+                    return Math.max(_a,_b);
+                }, 0),
+                _x = function(_p) {
+                    return _p * 340 / _nb;
+                },
+                _y = function(_p) {
+                    return 25 * ( 1 - _p / _max );
+                },
+                _d = _values.map(function(_v,_k) {
+                    return ( _k == 0 ?
+                        "M" + _x(_k) + " " + _y(_v) :
+                        "C" + _x(_k-.5) + " " + _y(_values[_k - 1])
+                        + " " + + _x(_k-.5) + " " + _y(_v)
+                        + " " + + _x(_k) + " " + _y(_v)
+                        ) ;
+                }).join("") + "L340 25L0 25";
+            this.innerHTML = '';
+            var _paper = new Raphael(this,340,25);
+            _paper.path(_d).attr({
+                "fill" : "#adadad",
+                "stroke" : "none"
+            });
+            var _x = function(_p) {
+                return _p * 340 / _medias[_i].duration;
+            };
+            for (var _j = 0; _j < _medias[_i].segments.length; _j++) {
+                var _s = _medias[_i].segments[_j];
+                _s.rect = _paper.rect(_x(_s.begin),0,_x(_s.duration),25).attr({
+                    "fill" : "rgb(255,120,255)",
+                    "opacity" : .5,
+                    "stroke" : "none"
+                });
+            }
+        });
+        $("li.li_segment").mouseover(function() {
+            getRect(this).attr("fill","rgb(255,0,255)");
+        }).mouseout(function() {
+            getRect(this).attr("fill","rgb(255,120,2255)");
+        });
     });
-</script>	
-
+</script>
 
 {% if msg %}
 {{ msg }}
@@ -76,17 +128,16 @@
                         <p>{{res.content.duration|str_duration:"::"}}</p>
                     </div>
                     <div class="graphe_result_media">
-                    	<span class="graph_annotation">
+                    	<span id="{{ res.content.iri_id }}" class="graph_annotation">
                     	{{ res.content.stat_annotation }}
                     	</span>
-                        <!--  <img src="img/placeholder_media_graph.png" width="340" height="25" alt="graph de volume" />-->
                     </div>
                 </div>
         
             <!-- Segments du média -->
                 <ul class="floatlist list_segments">
                 {% for segment in res.list %}
-                    <li class="li_segment">
+                    <li class="li_segment" id="li_{{segment.element_id}}">
                         <div class="left_segment">
                             <div class="color_zone" style="background: #f49af5;"></div>
                             <a href="{% url ldt.ldt_utils.views.lignesdetemps.index_segment segment.project_id segment.iri_id segment.ensemble_id segment.decoupage_id segment.element_id %}"><img src="{{LDT_MEDIA_PREFIX}}img/annot_icon_80x45.png" width="80" height="45" /></a>
--- a/src/ldt/ldt/ldt_utils/urls.py	Fri Jan 13 10:07:16 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/urls.py	Fri Jan 13 10:09:18 2012 +0100
@@ -26,6 +26,7 @@
     url(r'^update/(?P<ldt_id>.*)$', 'views.project.update_project'),
     url(r'^cljson/id/(?P<id>.*)$', 'views.json.project_json_id'),
     url(r'^cljson/externalid/(?P<id>.*)$', 'views.json.project_json_externalid'),
+    url(r'cljson/idcutting/(?P<id>.*)/(?P<cutting_id>.*)$', 'views.json.project_json_cutting_id'),
     url(r'^rdf/id/(?P<ldt_id>.*)$', 'views.rdf.project_annotations_rdf'),
     url(r'^/?$', "views.workspace.home", name="root-view"),
     url(r'^filterprojects/_(?P<filter>[\w\%\_\-\+]*?)/(?P<is_owner>true|false)/(?P<status>\d)$', "views.project.projects_filter",),
@@ -45,6 +46,7 @@
     url(r'^front/player/(?P<content_iri_id>.*)$', 'views.front.annot_content'),
     url(r'^front/search/$', 'views.front.search_index'),
     url(r'^front/searchListing', 'views.front.search_listing'),
+    url(r'^front/medias', 'views.front.all_contents'),
 )
 
 urlpatterns += patterns('',
--- a/src/ldt/ldt/ldt_utils/views/front.py	Fri Jan 13 10:07:16 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/front.py	Fri Jan 13 10:09:18 2012 +0100
@@ -48,6 +48,19 @@
 
 
 @login_required
+def all_contents(request):
+    # Get all the public contents group
+    content_list = add_change_attr(request.user, Content.safe_objects.all())
+    
+    is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1);
+
+    return render_to_response("front/front_all_contents.html",
+                              {'content_list':content_list, 
+                               'is_gecko': is_gecko},
+                              context_instance=RequestContext(request))
+
+
+@login_required
 def annot_content(request, content_iri_id):
     # Get the wanted content
     content = Content.objects.get(iri_id=content_iri_id)
--- a/src/ldt/ldt/ldt_utils/views/json.py	Fri Jan 13 10:07:16 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/json.py	Fri Jan 13 10:09:18 2012 +0100
@@ -7,6 +7,7 @@
 from ldt.ldt_utils.models import Project
 from ldt.ldt_utils.projectserializer import ProjectSerializer
 import ldt.auth as ldt_auth
+from guardian.shortcuts import get_objects_for_user
 
 def project_json_id(request, id): 
     
@@ -14,6 +15,11 @@
 
     return project_json(request, project, False)
 
+def project_json_cutting_id(request, id, cutting_id):
+
+    project = get_object_or_404(Project.safe_objects, ldt_id=id)
+
+    return project_json(request, project, first_cutting=cutting_id)
 
 def project_json_externalid(request, id): 
         
@@ -23,7 +29,7 @@
 
 
 
-def project_json(request, project, serialize_contents=True): # Not checked
+def project_json(request, project, serialize_contents=True, first_cutting=None): # Not checked
     
     if not ldt_auth.check_access(request.user, project):
         return HttpResponseForbidden(_("You can not access this project"))
@@ -51,8 +57,9 @@
     if escape_str:
         escape_bool = {'true': True, 'false': False, "0": False, "1": True}.get(escape_str.lower())
         
-        
-    ps = ProjectSerializer(project, serialize_contents)
+    viewable_contents = get_objects_for_user(request.user, 'ldt_utils.view_content', klass=project.contents.all())
+    viewable_contents = [c.iri_id for c in viewable_contents]    
+    ps = ProjectSerializer(project, serialize_contents, viewable_contents=viewable_contents, first_cutting=first_cutting)
     project_dict = ps.serialize_to_cinelab()
     
     json_str = simplejson.dumps(project_dict, ensure_ascii=False, indent=indent)
--- a/src/ldt/ldt/static/ldt/css/front_home.css	Fri Jan 13 10:07:16 2012 +0100
+++ b/src/ldt/ldt/static/ldt/css/front_home.css	Fri Jan 13 10:09:18 2012 +0100
@@ -8,10 +8,23 @@
     width: 960px;
 }
 
+#derniers_medias .li_right {
+    float: right; margin-top:10px;
+}
+
 #derniers_medias .li_media {
+    height: 225px;
     width: 300px;
 }
 
+/* Communs */
+.title_ul {
+    list-style: none;
+}
+.graph_annotation {
+    background: url(./imgs/whitealpha.png); margin:148px -297px; position:absolute;
+}
+
 /* Plus annotés */
 
 #plus_annotes {
@@ -22,6 +35,10 @@
     width: 630px; margin-right: 10px;
 }
 
+#plus_annotes .li_right {
+    float: right; margin-top:10px;
+}
+
 #plus_annotes .li_media {
     width:  140px;
     height: 140px;
Binary file src/ldt/ldt/static/ldt/css/imgs/whitealpha.png has changed
Binary file src/ldt/ldt/static/ldt/img/little_plus.png has changed