correct generate ldt
authorymh <ymh.work@gmail.com>
Thu, 19 May 2011 14:35:29 +0200
changeset 114 279f1782c184
parent 113 cf3bdb2a4216
child 115 d2cbc4c647dc
correct generate ldt
src/ldt/ldt/ldt_utils/utils.py
--- a/src/ldt/ldt/ldt_utils/utils.py	Thu May 19 10:38:36 2011 +0200
+++ b/src/ldt/ldt/ldt_utils/utils.py	Thu May 19 14:35:29 2011 +0200
@@ -1,3 +1,4 @@
+from copy import deepcopy
 from django.conf import settings
 from ldt.indexation import get_searcher, get_query_parser
 import datetime
@@ -77,37 +78,39 @@
             media.set(u"pict", u"")
             media.set(u"extra", u"")
     
-            if projects is None:
-                projects = []
-            annotations_nodes = {}
-            for project in project:
-                ldtdoc = lxml.etree.fromstring(project.ldt.encode("utf-8"))
-                res = ldtdoc.xpath("/iri/annotations/content")
-    
-                for content in res:
-                    contentid = content.get("id")
-                    if annotations_nodes.has_key(contentid):
-                        contentnode = annotations_nodes[contentid]
-                    else:
-                        contentnode = {"id":contentid, "ensembles":[]}
-                        annotations_nodes[contentid] = contentnode
-                    for ens in content.childNodes:
-                        if ens.tag.endswith("ensemble"):
-                            contentnode["ensembles"].append(ens.tag)
-    
-            annotations = lxml.etree.SubElement(iri, "annotations")
-            if len(annotations_nodes) > 0:                
-                for content in contentList:
-                    if content.content_base.iri_id in annotations_nodes:
-                        contentnode = annotations_nodes[content.content_base.iri_id]
-                        if contentnode is not None:
-                            if len(contentnode["ensembles"]) > 0:
-                                content = lxml.etree.SubElement(annotations, "content")
-                                content.set("id", contentnode["id"])
-                                content.text = u""
-                            else:
-                                content = lxml.etree.SubElement(annotations, "content")
-                                content.set("id", contentnode["id"])
+        if projects is None:
+            projects = []
+        annotations_nodes = {}
+        for project in project:
+            ldtdoc = lxml.etree.fromstring(project.ldt.encode("utf-8"))
+            res = ldtdoc.xpath("/iri/annotations/content")
+
+            for content in res:
+                contentid = content.get("id")
+                if annotations_nodes.has_key(contentid):
+                    contentnode = annotations_nodes[contentid]
+                else:
+                    contentnode = {"id":contentid, "ensembles":[]}
+                    annotations_nodes[contentid] = contentnode
+                for ens in content:
+                    if ens.tag.endswith("ensemble"):
+                        contentnode["ensembles"].append(deepcopy(ens))
+
+        annotations = lxml.etree.SubElement(iri, "annotations")
+        if len(annotations_nodes) > 0:
+            for content in contentList:
+                if content.iri_id in annotations_nodes:
+                    contentnode = annotations_nodes[content.content_base.iri_id]
+                    if contentnode is not None:
+                        if len(contentnode["ensembles"]) > 0:
+                            content_node = lxml.etree.SubElement(annotations, "content")
+                            content_node.set("id", contentnode["id"])
+                            content_node.text = u""
+                            for ens in contentnode["ensembles"]:
+                                content_node.append(ens)
+                        else:
+                            content_node = lxml.etree.SubElement(annotations, "content")
+                            content_node.set("id", contentnode["id"])
     
     
         displays = lxml.etree.SubElement(iri, "displays")