Lot of bugfixes
authorverrierj
Mon, 30 Jan 2012 15:55:54 +0100
changeset 482 c802e00c7131
parent 481 cba0c297bc88
child 484 5a64128bfe55
Lot of bugfixes
src/ldt/ldt/api/ldt/handlers.py
src/ldt/ldt/api/ldt/urls.py
src/ldt/ldt/ldt_utils/models.py
src/ldt/ldt/ldt_utils/projectserializer.py
src/ldt/ldt/ldt_utils/segmentserializer.py
src/ldt/ldt/ldt_utils/stat.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/templates/ldt/ldt_utils/partial/ldt_div.html
src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/search_results.html
src/ldt/ldt/ldt_utils/utils.py
src/ldt/ldt/ldt_utils/views/front.py
src/ldt/ldt/ldt_utils/views/json.py
src/ldt/ldt/ldt_utils/views/lignesdetemps.py
src/ldt/ldt/security/utils.py
--- a/src/ldt/ldt/api/ldt/handlers.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/api/ldt/handlers.py	Mon Jan 30 15:55:54 2012 +0100
@@ -244,6 +244,6 @@
                     Q(start_ts__lt=begin, start_ts__gt=end-F('duration'))                # period [begin:end] is included in the segment
                     )
         
-        a = SegmentSerializer(content, segments, viewable_contents=[content])
+        a = SegmentSerializer(content, segments)
         return a.serialize_to_cinelab()
     
--- a/src/ldt/ldt/api/ldt/urls.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/api/ldt/urls.py	Mon Jan 30 15:55:54 2012 +0100
@@ -9,7 +9,7 @@
 urlpatterns = patterns('',
     url(r'projects/(?P<project_id>[^/.]+)\.?(?P<emitter_format>.*)$', project_handler, name='project_api'),
     url(r'contents/(?P<iri_id>[^/.]+)\.?(?P<emitter_format>.*)$', content_handler, name='content_api'),
-    url(r'segments/(?P<iri_id>.*)/(?P<begin>\d+)/(?P<end>\d+)$', segment_handler),
+    url(r'segments/(?P<iri_id>.*)/(?P<begin>\d+)/(?P<end>\d+)$', segment_handler, name='segment_api'),
 )
 
 
--- a/src/ldt/ldt/ldt_utils/models.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py	Mon Jan 30 15:55:54 2012 +0100
@@ -384,7 +384,7 @@
         return Tag.objects.get_for_object(self)
     
     
-    pol_indices = {
+    __pol_indices = {
                'annotation_volume_begin' : 0,
                'annotation_volume_end' : settings.DIVISIONS_FOR_STAT_ANNOTATION,
                'pol_positive' : settings.DIVISIONS_FOR_STAT_ANNOTATION,
@@ -395,7 +395,7 @@
 
     # add polemic attributes and polemic attribute rates to class Content
     def __add_polemic_attributes(self):
-        for element in self.pol_indices.keys():
+        for element in self.__pol_indices.keys():
             if element.startswith('pol_'):                    
                 Content.add_to_class(element, property(self.__make_getter(element), self.__make_setter(element)))
                 Content.add_to_class("%s_rate" % element, property(self.__make_rate(element)))  
@@ -403,13 +403,13 @@
     def __make_getter(self, i):
         def inner_getter(self):
             l = self.__str2list(self.stat_annotation)
-            return l[Content.pol_indices[i]]
+            return l[Content.__pol_indices[i]]
         return inner_getter
     
     def __make_setter(self, i):
         def inner_setter(self, value):
             l = self.__str2list(self.stat_annotation)
-            l[Content.pol_indices[i]] = value
+            l[Content.__pol_indices[i]] = value
             self.stat_annotation = self.__list2str(l)
         return inner_setter
     
@@ -430,18 +430,16 @@
         
         def fget(self):
             l = self.__str2list(self.stat_annotation)
-            return l[Content.pol_indices['annotation_volume_begin']:Content.pol_indices['annotation_volume_end']]
+            return l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']]
         
         def fset(self, value): # value is a list
             l = self.__str2list(self.stat_annotation)
-            l[Content.pol_indices['annotation_volume_begin']:Content.pol_indices['annotation_volume_end']] = value
+            l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']] = value
             self.stat_annotation = self.__list2str(l)
             
         return locals()
     
-    annotation_volume = property(**annotation_volume())    
-    
- 
+    annotation_volume = property(**annotation_volume())
 
 
     
--- a/src/ldt/ldt/ldt_utils/projectserializer.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/projectserializer.py	Mon Jan 30 15:55:54 2012 +0100
@@ -5,6 +5,7 @@
 from ldt.ldt_utils.utils import reduce_text_node
 from ldt.ldt_utils.models import User, Project
 from ldt.ldt_utils.stat import get_string_from_buckets
+from ldt.security.utils import use_forbidden_url
 import logging
 import lxml.etree
 import uuid
@@ -17,11 +18,7 @@
 """
 class ProjectSerializer:
     
-    def __init__(self, project, from_contents=True, from_display=True, first_cutting=None, viewable_contents=[], only_one_cutting=False):
-        """
-        viewable_contents should contain all contents from project that a user is allowed to see. The settings.FORBIDDDEN_STREAM_URL
-        will be displayed if a content is not found in viewable_contents, and the real stream will be displayed if it is. 
-        """
+    def __init__(self, project, from_contents=True, from_display=True, first_cutting=None, only_one_cutting=False):
         self.project = project
         self.parsed = False
         self.ldt_doc = None
@@ -38,7 +35,6 @@
         self.display_contents_list = []
         self.display_cuttings_list = []
         self.display_ensemble_list = []
-        self.viewable_contents = viewable_contents
         self.first_cutting = first_cutting
         self.only_one_cutting = only_one_cutting
         
@@ -357,7 +353,8 @@
 
         href = ""
         meta_item_value = ""
-        if "Content" in settings.USE_GROUP_PERMISSIONS and content not in self.viewable_contents:
+        
+        if use_forbidden_url(content):   
             href = settings.FORBIDDEN_STREAM_URL
         elif content.videopath:
             href = content.videopath.rstrip('/') + "/" + content.src
--- a/src/ldt/ldt/ldt_utils/segmentserializer.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/segmentserializer.py	Mon Jan 30 15:55:54 2012 +0100
@@ -1,6 +1,7 @@
 from django.conf import settings
 from ldt.ldt_utils.models import Project
 from ldt.ldt_utils.stat import get_string_from_buckets
+from ldt.security.utils import use_forbidden_url
 import lxml.etree
 import uuid
 
@@ -94,9 +95,8 @@
         href = ""
         meta_item_value = ""
             
-        if "Content" in settings.USE_GROUP_PERMISSIONS and self.content:
-            if self.content not in self.viewable_contents:
-                href = settings.FORBIDDEN_STREAM_URL
+        if use_forbidden_url(self.content):
+            href = settings.FORBIDDEN_STREAM_URL
         elif self.content.videopath:
             href = self.content.videopath.rstrip('/') + "/" + self.content.src
             meta_item_value = self.content.videopath.rstrip('/') + "/"
--- a/src/ldt/ldt/ldt_utils/stat.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/stat.py	Mon Jan 30 15:55:54 2012 +0100
@@ -12,6 +12,11 @@
     size_division = content.duration / nb_division
     limits = [x * size_division for x in range(nb_division+1)]
     nb_annotation = len(segments)
+    
+    content.pol_positive = 0
+    content.pol_negative = 0
+    content.pol_question = 0
+    content.pol_reference = 0
 
     for segment in segments:
         
--- a/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html	Mon Jan 30 15:55:54 2012 +0100
@@ -36,8 +36,8 @@
                 <ul class="polemics">
                     <li class="pol-negative" style="width:{{content.pol_negative_rate}}%"><span>{{content.pol_negative_rate}}%</span></li>
                     <li class="pol-positive" style="width:{{content.pol_positive_rate}}%"><span>{{content.pol_positive_rate}}%</span></li>
-                    <li class="pol-reference" style="width:{{content.pol_reference_rate}}%"><span>{{content.pol_reference_rate}}%</span></li>
-                    <li class="pol-question" style="width:{{content.pol_question_rate}}%"><span>{{content.pol_question_rate}}%</span></li>
+                    <!-- <li class="pol-reference" style="width:{{content.pol_reference_rate}}%"><span>{{content.pol_reference_rate}}%</span></li>
+                    <li class="pol-question" style="width:{{content.pol_question_rate}}%"><span>{{content.pol_question_rate}}%</span></li> -->
                 </ul>
                 <span class="graph_annotation" id="sp_{{ content.iri_id }}">{{ content.annotation_volume|list2str }}</span>
             </div>
--- a/src/ldt/ldt/ldt_utils/templates/front/front_base.html	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_base.html	Mon Jan 30 15:55:54 2012 +0100
@@ -43,7 +43,7 @@
             </div>
         </li>
         <li id="li_connexion">
-            <a href="#" title="{% trans 'connection' %}">{% trans "connection" %}</a>
+            <a href="{% url ldt.user.views.logout_view %}" title="{% trans "Log out" %}">{% trans "Log out" %}</a>
         </li>
     </ul>
 {% block body %}
--- a/src/ldt/ldt/ldt_utils/templates/front/front_home.html	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/front/front_home.html	Mon Jan 30 15:55:54 2012 +0100
@@ -41,8 +41,6 @@
                 <ul class="polemics">
                     <li class="pol-negative" style="width:{{content.pol_negative_rate}}%"><span>{{content.pol_negative_rate}}%</span></li>
                     <li class="pol-positive" style="width:{{content.pol_positive_rate}}%"><span>{{content.pol_positive_rate}}%</span></li>
-                    <li class="pol-reference" style="width:{{content.pol_reference_rate}}%"><span>{{content.pol_reference_rate}}%</span></li>
-                    <li class="pol-question" style="width:{{content.pol_question_rate}}%"><span>{{content.pol_question_rate}}%</span></li>
                 </ul>
                 <span class="graph_annotation" id="sp_{{ content.iri_id }}">{{ content.annotation_volume|list2str }}</span>
             </div>
@@ -73,8 +71,6 @@
                 <ul class="polemics">
                     <li class="pol-negative" style="width:{{content.pol_negative_rate}}%"><span>{{content.pol_negative_rate}}%</span></li>
                     <li class="pol-positive" style="width:{{content.pol_positive_rate}}%"><span>{{content.pol_positive_rate}}%</span></li>
-                    <li class="pol-reference" style="width:{{content.pol_reference_rate}}%"><span>{{content.pol_reference_rate}}%</span></li>
-                    <li class="pol-question" style="width:{{content.pol_question_rate}}%"><span>{{content.pol_question_rate}}%</span></li>
                 </ul>
             </div>
         </div>
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/ldt_div.html	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/ldt_div.html	Mon Jan 30 15:55:54 2012 +0100
@@ -28,7 +28,7 @@
 		readOnly:'true',
 		{% endifequal %}
 		segmentPassMask:"{{WEB_URL}}{% url ldt.ldt_utils.views.lignesdetemps.index_segment '{4}' '{0}' '{1}' '{2}' '{3}' %}",
-		simplePlayerPassMask:"{{WEB_URL}}{% url ldt.ldt_utils.views.front.annot_content '{0}' '{4}' '{2}' %}"
+		simplePlayerPassMask:"{{WEB_URL}}{% url ldt.ldt_utils.views.front.annot_content '{0}' '{4}' '{2}' %}#id={3}"
 		
 	};
 
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/search_results.html	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/search_results.html	Mon Jan 30 15:55:54 2012 +0100
@@ -38,10 +38,9 @@
 
 {% block js_declaration %}
 	{{ block.super }}
-
 	<script type="text/javascript">   
 	$(document).ready(function(){
-		init_events_all(document, "/pf/ldtplatform/ldt/embedpopup", '', '', '', '');
+		init_events_all(document, "{% url ldt.ldt_utils.views.workspace.popup_embed %}", '', '', '', '');
 	});    
     </script>
 {% endblock %}
--- a/src/ldt/ldt/ldt_utils/utils.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/utils.py	Mon Jan 30 15:55:54 2012 +0100
@@ -266,7 +266,7 @@
         tags = lxml.etree.SubElement(element, 'tags')
                                 
         polemics = self.get_polemic_syntax(title)
-        print "polemics : %s" % polemics
+        
         if polemics:
             meta = lxml.etree.SubElement(element, 'meta')
             polemics_node = lxml.etree.SubElement(meta, 'polemics')
--- a/src/ldt/ldt/ldt_utils/views/front.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/front.py	Mon Jan 30 15:55:54 2012 +0100
@@ -2,10 +2,8 @@
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import Group, User
 from django.core.urlresolvers import reverse
-from django.http import HttpResponse, HttpResponseServerError
-from django.shortcuts import render_to_response, get_object_or_404
+from django.shortcuts import render_to_response
 from django.template import RequestContext
-from django.utils import simplejson
 from guardian.shortcuts import get_objects_for_group
 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
@@ -89,7 +87,7 @@
             proj = front_proj
         else:
             # The main project for the content
-            proj = Project.safe_objects.filter(contents__in=[content])[0]
+            proj = Project.safe_objects.filter(contents__in=[content], state=2)[0]
     else:
         proj = Project.safe_objects.get(ldt_id=project_id)
     
--- a/src/ldt/ldt/ldt_utils/views/json.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/json.py	Mon Jan 30 15:55:54 2012 +0100
@@ -5,7 +5,6 @@
 from django.utils.html import escape
 from ldt.ldt_utils.models import Project
 from ldt.ldt_utils.projectserializer import ProjectSerializer
-from guardian.shortcuts import get_objects_for_user
 
 
 def project_json_id(request, id): 
@@ -58,9 +57,8 @@
     if escape_str:
         escape_bool = {'true': True, 'false': False, "0": False, "1": True}.get(escape_str.lower())
         
-    viewable_contents = get_objects_for_user(request.user, 'ldt_utils.view_content', klass=project.contents.all())
         
-    ps = ProjectSerializer(project, serialize_contents, viewable_contents=viewable_contents, first_cutting=first_cutting)
+    ps = ProjectSerializer(project, serialize_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/ldt_utils/views/lignesdetemps.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/lignesdetemps.py	Mon Jan 30 15:55:54 2012 +0100
@@ -170,8 +170,8 @@
         id_node = active_segment_node.find(u"id")
         if id_node:
             active_segment_node.remove(id_node)
-        lxml.etree.SubElement(active_segment_node, u"id", attrib={u"idctt":unicode(content_id), u"idens": unicode(ensemble_id), "idcut":unicode(cutting_id), u"idseg":unicode(segment_id)})
-                                    
+        lxml.etree.SubElement(active_segment_node, u"id", attrib={u"idctt":unicode(content_id), u"idens": unicode(ensemble_id), "idcut":unicode(cutting_id), u"idseg":unicode(segment_id)})                     
+        ldtdoc = set_forbidden_stream(ldtdoc, request.user)
         resp.write(lxml.etree.tostring(ldtdoc, xml_declaration=True, encoding='utf-8', pretty_print=True))
     else:
         # generate ldt from 
--- a/src/ldt/ldt/security/utils.py	Mon Jan 30 11:14:08 2012 +0100
+++ b/src/ldt/ldt/security/utils.py	Mon Jan 30 15:55:54 2012 +0100
@@ -2,7 +2,7 @@
 from django.contrib.contenttypes.models import ContentType
 from guardian.shortcuts import assign, remove_perm, get_users_with_perms, get_groups_with_perms, get_objects_for_user
 from cache import get_cached_userlist
-from ldt.security import change_security 
+from ldt.security import change_security, get_current_user
 import types
   
 def unprotect_instance(instance):
@@ -26,17 +26,26 @@
     cls = ContentType.objects.get(model='content')
     cls = cls.model_class()
     
-    old_user = cls.safe_objects.user
-    obj_list = cls.safe_objects.all()
-    
     for elem in xml.xpath('/iri/medias/media'):
-        if not obj_list.filter(iri_id=elem.get('id')):
+        if not user.is_authenticated():
             elem.set('video', settings.FORBIDDEN_STREAM_URL)
-    
-    cls.safe_objects.user = old_user 
-    
+        else:
+            content = cls.safe_objects.filter(iri_id=elem.get('id'))
+            if not content:
+                elem.set('video', settings.FORBIDDEN_STREAM_URL)
+        
     return xml
 
+def use_forbidden_url(content):
+    user = get_current_user()
+
+    if not user.is_authenticated():
+        return True
+    elif "Content" in settings.USE_GROUP_PERMISSIONS and user.has_perm('ldt_utils.view_content', content):
+        return False
+
+    return True
+
 def add_change_attr(user, obj_list):
     """ 
      Add a change attribute set to True to objects of obj_list