# HG changeset patch # User hamidouk # Date 1326901372 -3600 # Node ID b5a19e9329e03b25bf52970f8b7ff75b6cbb5a8b # Parent 324f5fab9eca8e569d6d0f4f5c41757513af11fb# Parent b512f69a474a85661fe0c947336c7da741c6318b Merge with upstream diff -r 324f5fab9eca -r b5a19e9329e0 src/ldt/ldt/ldt_utils/segmentserializer.py --- a/src/ldt/ldt/ldt_utils/segmentserializer.py Wed Jan 18 16:42:28 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/segmentserializer.py Wed Jan 18 16:42:52 2012 +0100 @@ -1,9 +1,12 @@ from django.conf import settings from django.utils.datastructures import SortedDict +from ldt.ldt_utils.models import Project +import lxml.etree import uuid DATE_FORMATS = ["%d/%m/%Y", "%Y-%m-%d"] +import pdb class SegmentSerializer(object): """ Serialize a set of annotations to a cinelab compatible array @@ -19,6 +22,20 @@ self.medias = None self.annotations = None + self.xml_docs = {} + + def __get_cutting_title(self, project_id, content_id, ensemble_id, cutting_id): + + if not self.xml_docs.has_key(project_id): + project = Project.objects.get(ldt_id=project_id) + doc = lxml.etree.fromstring(project.ldt) + self.xml_docs[project_id] = doc + 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] + + return cutting.text def __parse_views(self): @@ -31,18 +48,24 @@ } self.annotation_types = [] - annotation_types = [seg.cutting_id for seg in self.segments] + + annotation_types = [] + for seg in self.segments: + title = self.__get_cutting_title(seg.project_id, seg.iri_id, seg.ensemble_id, seg.cutting_id) + annotation_types.append({'id': seg.cutting_id, 'title': title}) + for a in annotation_types: - view['annotation_types'].append(a) + view['annotation_types'].append(a['id']) self.annotation_types.append({ "dc:contributor": "undefined", "dc:creator": "undefined", - "dc:title": "cutting %s" % a, - "id": "%s" % a, + "dc:title": a['title'], + "id": a['id'], "dc:created": "", "dc:description": "", "dc:modified": "" }) + self.views = [view] diff -r 324f5fab9eca -r b5a19e9329e0 src/ldt/ldt/ldt_utils/stat.py --- a/src/ldt/ldt/ldt_utils/stat.py Wed Jan 18 16:42:28 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/stat.py Wed Jan 18 16:42:52 2012 +0100 @@ -121,7 +121,7 @@ content.last_annotated = datetime.datetime.now() content.save() -import uuid + def add_annotation_to_stat(content, project, begin, end): contribution_project = AnnotationStat.objects.get(project=project, content=content) @@ -130,21 +130,7 @@ else: contribution_project.nb_annotation += 1 content.nb_annotation += 1 - -# print "before segment creation" -# s = Segment(project_obj=project, -# content=content, -# project_id=project.ldt_id, -# iri_id=content.iri_id, -# ensemble_id='%s' % unicode(uuid.uuid1()), -# cutting_id='t', -# element_id='a', -# duration=end-begin, -# start_ts=begin) -# s.save() -# print s.id -# print "segment created" - + if contribution_project.stat: number_division = settings.DIVISIONS_FOR_STAT_ANNOTATION