# HG changeset patch # User hamidouk # Date 1327397144 -3600 # Node ID b068bc945c2df0054afac69c42ee83017fe3aac9 # Parent 5e7ec99d4f1e588da3952351e4c45df20ca52ddc# Parent 8c33427e558b2ff3b9dd090117692efb523c9c6f Merge with upstream. diff -r 5e7ec99d4f1e -r b068bc945c2d crea/.DS_Store Binary file crea/.DS_Store has changed diff -r 5e7ec99d4f1e -r b068bc945c2d src/ldt/ldt/api/ldt/handlers.py --- a/src/ldt/ldt/api/ldt/handlers.py Tue Jan 24 10:25:28 2012 +0100 +++ b/src/ldt/ldt/api/ldt/handlers.py Tue Jan 24 10:25:44 2012 +0100 @@ -4,7 +4,7 @@ from piston.utils import rc, require_extended from ldt.ldt_utils.utils import LdtAnnotation from ldt.ldt_utils.stat import add_annotation_to_stat -from ldt.security.utils import protect_instance, unprotect_instance +from ldt.security import protect_models, unprotect_models from ldt.ldt_utils.segmentserializer import SegmentSerializer import logging #@UnresolvedImport @@ -157,7 +157,8 @@ adder = LdtAnnotation(project) logging.debug("request json " + repr(request.data)) - unprotect_instance(project) # allows anonymous user to save project + + unprotect_models() # Allows anonymous user to modify models in this request only meta = request.data['meta'] author = meta['creator'] @@ -169,14 +170,12 @@ begin = str(a['begin']) type_id, new_id = adder.add(a['media'], a['type'], a['type_title'], a['content']['data'], '', a['tags'], begin, dur, author, date) if not new_id: - protect_instance(project) + protect_models() return rc.BAD_REQUEST content = project.contents.get(iri_id=a['media']) - unprotect_instance(content) add_annotation_to_stat(content, project, a['begin'], a['end']) - protect_instance(content) # We update the ids a['type'] = type_id @@ -186,7 +185,7 @@ if len(new_annotations)>0 : adder.save() - protect_instance(project) + protect_models() return request.data @@ -204,9 +203,9 @@ project.ldt = ldt_str - unprotect_instance(project) + unprotect_models() project.save() - protect_instance(project) + protect_models() return rc.ALL_OK @@ -235,12 +234,12 @@ def read(self, request, iri_id, begin, end): """ - returns a single Segment + returns segments about content iri_id between timecodes begin and end """ content = Content.objects.get(iri_id=iri_id) segments = Segment.objects.filter(content=content).filter( - Q(start_ts__gt=begin, start_ts__lt=end) | # segment start between begin and end + Q(start_ts__gt=begin, start_ts__lt=end) | # segment starts between begin and end Q(start_ts__gt=begin-F('duration'), start_ts__lt=end-F('duration')) |# segment ends between begin and end Q(start_ts__lt=begin, start_ts__gt=end-F('duration')) # period [begin:end] is included in the segment ) diff -r 5e7ec99d4f1e -r b068bc945c2d src/ldt/ldt/ldt_utils/models.py --- a/src/ldt/ldt/ldt_utils/models.py Tue Jan 24 10:25:28 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/models.py Tue Jan 24 10:25:44 2012 +0100 @@ -219,7 +219,7 @@ if not self.nb_annotation: self.nb_annotation = 0 if not self.stat_annotation: - self.stat_annotation = '0,0' + self.stat_annotation = ('0,' * settings.DIVISIONS_FOR_STAT_ANNOTATION)[:-1] super(Content, self).save(*args, **kwargs) diff -r 5e7ec99d4f1e -r b068bc945c2d src/ldt/ldt/ldt_utils/projectserializer.py --- a/src/ldt/ldt/ldt_utils/projectserializer.py Tue Jan 24 10:25:28 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/projectserializer.py Tue Jan 24 10:25:44 2012 +0100 @@ -228,6 +228,8 @@ } self.tags[tag_title] = new_tag self.tags_dict[tag_id] = new_tag + else: + tag_id = self.tags[tag_title]["id"] element_tags.append({"id-ref":tag_id}) if not element_tags: @@ -354,7 +356,7 @@ href = "" meta_item_value = "" - if content not in self.viewable_contents: + if "Content" in settings.USE_GROUP_PERMISSIONS and content not in self.viewable_contents: href = settings.FORBIDDEN_STREAM_URL elif content.videopath: href = content.videopath.rstrip('/') + "/" + content.src diff -r 5e7ec99d4f1e -r b068bc945c2d src/ldt/ldt/ldt_utils/segmentserializer.py --- a/src/ldt/ldt/ldt_utils/segmentserializer.py Tue Jan 24 10:25:28 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/segmentserializer.py Tue Jan 24 10:25:44 2012 +0100 @@ -23,7 +23,9 @@ self.views = None self.annotation_types = None self.medias = None - self.annotations = None + self.annotations = None + self.tags = {} + self.xml_docs = {} def __get_cutting_title(self, project_id, content_id, ensemble_id, cutting_id): @@ -35,7 +37,11 @@ else: doc = self.xml_docs[project_id] - cutting = doc.xpath('/iri/annotations/content[@id=\'%s\']/ensemble[@id=\'%s\']/decoupage[@id=\'%s\']/title' % (content_id, ensemble_id, cutting_id))[0] + cutting = doc.xpath('/iri/annotations/content[@id=\'%s\']/ensemble[@id=\'%s\']/decoupage[@id=\'%s\']/title' % (content_id, ensemble_id, cutting_id)) + if not cutting: + return None + + cutting = cutting[0] return cutting.text @@ -49,6 +55,16 @@ "annotation_types": [ ], } + stat = { + "id": "stat", + "contents": [ + self.content.iri_id + ], + "meta": { + "stat": self.content.stat_annotation + } + } + self.annotation_types = [] annotation_types = [] @@ -57,6 +73,7 @@ annotation_types.append({'id': seg.cutting_id, 'title': title}) for a in annotation_types: + view['annotation_types'].append(a['id']) self.annotation_types.append({ "dc:contributor": "undefined", @@ -69,16 +86,17 @@ }) - self.views = [view] + self.views = [view, stat] def __parse_content(self): href = "" meta_item_value = "" - - if self.content not in self.viewable_contents: - href = settings.FORBIDDEN_STREAM_URL + + if "Content" in settings.USE_GROUP_PERMISSIONS and self.content: + if self.content not in self.viewable_contents: + href = settings.FORBIDDEN_STREAM_URL elif self.content.videopath: href = self.content.videopath.rstrip('/') + "/" + self.content.src meta_item_value = self.content.videopath.rstrip('/') + "/" @@ -116,11 +134,27 @@ for seg in self.segments: + segment_tags = [] + for tag in seg.tags.split(';'): + if not self.tags.has_key(tag): + new_tag = { + "meta": { + "dc:contributor": "IRI", + "dc:created": seg.date, + "dc:title": tag, + "dc:modified": seg.date, + "dc:creator": "IRI" + }, + "id": unicode(uuid.uuid1()) + } + self.tags[tag] = new_tag + segment_tags.append({'id-ref': self.tags[tag]['id']}) + segment = { 'begin': seg.start_ts, 'end': seg.start_ts + seg.duration, 'tags': seg.tags, - 'id': "s_%s" % unicode(uuid.uuid1()), + 'id': seg.element_id, 'color': "%s" % self.default_color, 'media': self.content.iri_id, 'content': { @@ -130,7 +164,7 @@ 'src': '' }, 'title': seg.title, - 'color': '2194379', + 'color': self.default_color, 'polemics': [ ], 'audio': { 'mimetype': 'audio/mp3', @@ -144,22 +178,26 @@ "dc:contributor": seg.author, "dc:created": seg.date, "dc:modified": seg.date, - "id-ref": seg.iri_id, + "id-ref": seg.cutting_id, "project": seg.project_id - } + }, + 'tags': segment_tags } self.annotations.append(segment) def serialize_to_cinelab(self): + if not self.segments: + return None + self.__parse_content() self.__parse_segments() self.__parse_views() res = {} res['views'] = self.views - res['tags'] = None + res['tags'] = self.tags.values() if len(self.tags) > 0 else None res['lists'] = None res['medias'] = self.medias res['annotations'] = self.annotations diff -r 5e7ec99d4f1e -r b068bc945c2d src/ldt/ldt/ldt_utils/stat.py --- a/src/ldt/ldt/ldt_utils/stat.py Tue Jan 24 10:25:28 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/stat.py Tue Jan 24 10:25:44 2012 +0100 @@ -1,5 +1,5 @@ from django.conf import settings -from ldt.ldt_utils.models import AnnotationStat, Project, Segment +from ldt.ldt_utils.models import AnnotationStat, Project from django.db.models.signals import pre_delete import lxml.etree import datetime @@ -19,7 +19,7 @@ for content_node in doc.xpath('/iri/annotations/content'): content_name = content_node.get('id') content = filter_list(contents, 'iri_id', content_name) - print content_name + # if the content referenced in the xml belongs to the # fields contents of the project if len(content) != 0: @@ -35,6 +35,10 @@ for ann in content_node.xpath('ensemble/decoupage/elements/element'): begin = int(ann.get('begin')) end = int(ann.get('dur')) + begin + + text = ann.xpath('abstract')[0].text + if is_polemic(text): + pass buckets = find_buckets(buckets, limits, begin, end) nb_annotation += 1 @@ -80,7 +84,25 @@ buckets[i] += 1 return buckets - + +def is_polemic(text): + if text: + polemic_tags = ['++', '--', '==', '??'] + for tag in polemic_tags: + if tag in text: + return True + return False + + + +def filter_list(list, criteria, value): + new_list = [] + for l in list: + if getattr(l, criteria) == value: + new_list.append(l) + + return new_list + def delete_stat_project(sender, instance, **kwargs): @@ -149,10 +171,3 @@ contribution_project.save() -def filter_list(list, criteria, value): - new_list = [] - for l in list: - if getattr(l, criteria) == value: - new_list.append(l) - - return new_list \ No newline at end of file diff -r 5e7ec99d4f1e -r b068bc945c2d src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html --- a/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html Tue Jan 24 10:25:28 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/front/front_all_contents.html Tue Jan 24 10:25:44 2012 +0100 @@ -71,9 +71,9 @@ {% for content in content_list %}
{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}
{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}
- {{group.profile.description|safe}} + {{group.get_profile.description|safe}}
- {% thumbnail group.profile.image "54x40" format="PNG" crop="center" as im %}
{{user.username}}
{% trans 'active since' %} {{user.date_joined|date:"Y/m/d"}}
{% trans 'All medias' %}
+
{% trans 'All medias' %}
{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}
+
{% trans 'All medias' %}
+
{% trans 'All medias' %}
{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}
{% if group.profile.description|length > 69 %}{{group.profile.description|safe|slice:":69"}}...{% else %}{{group.profile.description|safe}}{% endif %}
+{% if group.get_profile.description|length > 69 %}{{group.get_profile.description|safe|slice:":69"}}...{% else %}{{group.get_profile.description|safe}}{% endif %}
{{ nb_results }} {% trans "Result" %}{{ nb_results|pluralize }}
{{res.content.duration|str_duration:"::"}}
{% if segment.context %}{{ segment.context }}{% endif %}
{% trans "Begin" %} : {{ segment.begin|str_duration:"::" }} - {% trans "duration" %} : {{ segment.duration|str_duration:"::" }}
{% if results.has_previous %} - {% trans "previous" %} + {% trans "previous" %} . {% endif %} {% if results.paginator.num_pages > 1 %} @@ -180,7 +180,7 @@ {% endif %} {% if results.has_next %} . - {% trans "next" %} + {% trans "next" %} {% endif %}