correct project serializer and take into account the display + new version V00.22
authorymh <ymh.work@gmail.com>
Fri, 15 Oct 2010 11:58:18 +0200
changeset 89 30c6e597a7de
parent 88 7f2c2d9adf58
child 90 0325a0a8b997
correct project serializer and take into account the display + new version
web/franceculture/__init__.py
web/franceculture/locale/fr/LC_MESSAGES/django.mo
web/franceculture/locale/fr/LC_MESSAGES/django.po
web/ldt/ldt_utils/fileimport.py
web/ldt/ldt_utils/projectserializer.py
web/ldt/ldt_utils/views.py
--- a/web/franceculture/__init__.py	Thu Oct 14 11:36:12 2010 +0200
+++ b/web/franceculture/__init__.py	Fri Oct 15 11:58:18 2010 +0200
@@ -1,4 +1,4 @@
-VERSION = (0, 21, 0, "final", 0)
+VERSION = (0, 22, 0, "final", 0)
 
 VERSION_STR = unicode(".".join(map(lambda i:"%02d" % (i,), VERSION[:2])))
 
Binary file web/franceculture/locale/fr/LC_MESSAGES/django.mo has changed
--- a/web/franceculture/locale/fr/LC_MESSAGES/django.po	Thu Oct 14 11:36:12 2010 +0200
+++ b/web/franceculture/locale/fr/LC_MESSAGES/django.po	Fri Oct 15 11:58:18 2010 +0200
@@ -58,11 +58,11 @@
 
 #: templates/franceculture/embed_popup.html:42
 msgid "popup_seo_body"
-msgstr "Code lecteur et seo"
+msgstr "Code SEO"
 
 #: templates/franceculture/embed_popup.html:42
 msgid "popup_seo_meta"
-msgstr "Code lecteur et seo balise meta"
+msgstr "Code balise meta header"
 
 #: templates/franceculture/embed_popup.html:42
 msgid "popup_links"
--- a/web/ldt/ldt_utils/fileimport.py	Thu Oct 14 11:36:12 2010 +0200
+++ b/web/ldt/ldt_utils/fileimport.py	Fri Oct 15 11:58:18 2010 +0200
@@ -138,10 +138,7 @@
 
 
     def saveContent(self):
-        #if 'http' in self.src:
-        #    url = self.src
-        #else:
-        #    url = self.id + u"/" + os.path.basename(self.src)
+
         defaults_media = {'src':unicode(self.videourl), 'title':unicode(self.title), 'description':unicode(self.desc), 'videopath': unicode(self.videopath.rstrip("/") + "/")}
         media, media_created = Media.objects.get_or_create(src=unicode(self.videourl), defaults = defaults_media)
         if not media_created:
--- a/web/ldt/ldt_utils/projectserializer.py	Thu Oct 14 11:36:12 2010 +0200
+++ b/web/ldt/ldt_utils/projectserializer.py	Fri Oct 15 11:58:18 2010 +0200
@@ -15,12 +15,16 @@
         self.parsed = False
         self.ldt_doc = None
         self.medias = []
+        self.medias_by_id = {}
         self.annotations = []
+        self.annotations_by_annotation_type = {}
         self.tags = {}
         self.tags_by_id = {}
         self.annotation_types = []
+        self.annotation_types_by_id = {}
         self.views = []
         self.lists = []
+        self.lists_by_id = {}
         self.serialize_contents = from_contents
         self.from_display = from_display
         
@@ -95,7 +99,11 @@
                 "dc:description":decoupage_description
             }
             
-            self.annotation_types.append(new_annotation_types)            
+            self.annotation_types.append(new_annotation_types)
+            self.annotation_types_by_id[decoupage_id] = new_annotation_types
+            annotations_list = []
+            
+            self.annotations_by_annotation_type[decoupage_id] = annotations_list
                         
             res = decoupage_node.xpath("elements/element")
             for element_node in res:
@@ -188,10 +196,12 @@
                 }
                 
                 self.annotations.append(new_annotation)
+                annotations_list.append(new_annotation)
         
         if not list_items:
             new_list["items"] = None
         self.lists.append(new_list)
+        self.lists_by_id[ensemble_id] = new_list
 
 
     def __parse_ldt(self):
@@ -212,10 +222,46 @@
                 if ensemble_node.tag != "ensemble" :
                     continue
                 self.__parse_ensemble(ensemble_node, content)            
-    
-#        res = self.ldt_doc.xpath("/iri/displays/display")
-#        for display_node in res:
-#            pass
+
+        if self.from_display :
+            annotations = []
+            annotation_types = []
+            ensembles = []
+            medias = []
+            tags = []
+            xpath_str = "/iri/displays/display[position()=1]/content"
+            if isinstance(self.from_display, basestring):
+                xpath_str = "/iri/displays/display[id='%s']/content" % self.from_display
+                
+            for content_node in self.ldt_doc.xpath(xpath_str):
+                content_id = content_node.get("id")
+                if content_id not in medias:
+                    medias.append(content_id)
+                for node in content_node.xpath("decoupage"):
+                    annotation_type_id = node.get('id')
+                    ensemble_id = node.get('idens')
+                    if annotation_type_id in self.annotations_by_annotation_type:
+                        annot_list = self.annotations_by_annotation_type[annotation_type_id]                    
+                        annotations.extend(annot_list)
+                        for annot in annot_list:
+                            if annot['tags']:
+                                for tag in annot['tags']:
+                                    tag_id = tag['id-ref']
+                                    if tag_id not in tags:
+                                        tags.append(tag_id)                    
+                        if annotation_type_id not in annotation_types:
+                            annotation_types.append(annotation_type_id)
+                        if ensemble_id not in ensembles:
+                            ensembles.append(ensemble_id)
+            
+            self.annotations = annotations
+            self.annotation_types = map(lambda id: self.annotation_types_by_id[id], annotation_types)
+            self.lists = map(lambda id: self.lists_by_id[id], ensembles)
+            self.medias = map(lambda id: self.medias_by_id[id], medias)
+            self.tags = {}
+            for tag_id in tags:
+                tag_inst = self.tags_by_id[tag_id]
+                self.tags[tag_inst['meta']['dc:title']] = tag_inst
         
         self.parsed = True
     
@@ -273,6 +319,7 @@
         }
         
         self.medias.append(new_media)
+        self.medias_by_id[content.iri_id] = new_media
         
         if self.serialize_contents:        
             res = doc.xpath("/iri/body/ensembles/ensemble")
--- a/web/ldt/ldt_utils/views.py	Thu Oct 14 11:36:12 2010 +0200
+++ b/web/ldt/ldt_utils/views.py	Fri Oct 15 11:58:18 2010 +0200
@@ -290,7 +290,7 @@
     resp['Cache-Control']='no-cache, must-revalidate'
     resp['Pragma']='no-cache'
 
-    ps = ProjectSerializer(project, from_content=False, from_display=True) 
+    ps = ProjectSerializer(project, from_contents=False, from_display=True) 
     annotations = project.getAnnotations(first_cutting=True)
     
     rdf_ns = u"http://www.w3.org/1999/02/22-rdf-syntax-ns#"