web/ldt/ldt_utils/projectserializer.py
changeset 100 c5514a2bfdcd
parent 99 0fb4b009c6eb
child 137 d363fa6232b2
--- a/web/ldt/ldt_utils/projectserializer.py	Tue Oct 19 15:21:07 2010 +0200
+++ b/web/ldt/ldt_utils/projectserializer.py	Wed Oct 20 11:19:38 2010 +0200
@@ -18,6 +18,7 @@
         self.ldt_doc = None
         self.medias_dict = SortedDict()
         self.annotations_dict = SortedDict()
+        self.annotations_by_annotation_types = {}
         self.tags = {}
         self.tags_dict = SortedDict()
         self.annotation_types_dict = SortedDict()
@@ -134,6 +135,7 @@
             }
             
             self.annotation_types_dict[decoupage_id] = new_annotation_types
+            self.annotations_by_annotation_types[decoupage_id] = []
                         
             res = decoupage_node.xpath("elements/element")
             for element_node in res:
@@ -226,6 +228,7 @@
                 }
                 
                 self.annotations_dict[element_id] = new_annotation
+                self.annotations_by_annotation_types[decoupage_id].append(new_annotation)
         
         if not list_items:
             new_list["items"] = None
@@ -241,9 +244,7 @@
             if isinstance(self.from_display, basestring):
                 xpath_str = "/iri/displays/display[@id='%s']" % self.from_display
             
-            logging.debug("xpath_str " + xpath_str)
             self.__parse_views(self.ldt_doc.xpath(xpath_str))
-            logging.debug("xpath_str " + repr(self.views_dict))
         
         res = self.ldt_doc.xpath("/iri/medias/media")
         for mediaNode in res:
@@ -267,6 +268,19 @@
                     continue
                 self.__parse_ensemble(ensemble_node, content)            
         
+        #reorder annotations and annotation type from view
+        if self.from_display and len(self.views_dict) > 0:
+            new_annotation_types_dict = SortedDict()
+            new_annotations_dict = SortedDict()
+            for annotation_type in self.display_cuttings_list:
+                if annotation_type in self.annotation_types_dict:
+                    new_annotation_types_dict[annotation_type] = self.annotation_types_dict[annotation_type]
+                    for annot in self.annotations_by_annotation_types[annotation_type]:
+                        new_annotations_dict[annot['id']] = annot
+                    
+            self.annotations_dict = new_annotations_dict
+            self.annotation_types_dict = new_annotation_types_dict
+        
         self.parsed = True
     
     def __parse_content(self, content):
@@ -360,12 +374,14 @@
                 
                     
         res['medias'] =  self.medias_dict.values() if len(self.medias_dict) > 0 else None
-        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 
         res['lists'] = self.lists_dict.values() if len(self.lists_dict) > 0 else None
         res['tags'] = self.tags.values() if len(self.tags) > 0 else None
         res['views'] = self.views_dict.values() if len(self.views_dict) > 0 else None
         
+        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 
+
+        
 
         return res
     
@@ -379,9 +395,10 @@
         current_cutting = None
         uri = None
         for annot in self.annotations_dict.values():
-            if first_cutting and current_cutting and current_cuttings != annot['meta']['id-ref'] :
+            logging.debug("current cutting" + repr(current_cutting) + " : annot " + annot['meta']['id-ref'])
+            if first_cutting and current_cutting and current_cutting != annot['meta']['id-ref'] :
                 break
-            current_cuttings = annot['meta']['id-ref']
+            current_cutting = annot['meta']['id-ref']
             content_id = annot['media']
             content = Content.objects.get(iri_id=content_id)
             if annot['tags']: