--- a/src/ldt/ldt/ldt_utils/projectserializer.py Thu Jan 12 16:03:43 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/projectserializer.py Thu Jan 12 16:05:40 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):
--- a/src/ldt/ldt/ldt_utils/urls.py Thu Jan 12 16:03:43 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/urls.py Thu Jan 12 16:05:40 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",),
--- a/src/ldt/ldt/ldt_utils/views/json.py Thu Jan 12 16:03:43 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/json.py Thu Jan 12 16:05:40 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)