# HG changeset patch # User ymh # Date 1305808529 -7200 # Node ID 279f1782c184b1c93fb4552353565870e390b997 # Parent cf3bdb2a4216e645f3d25bfabb58b9bc9f78baaa correct generate ldt diff -r cf3bdb2a4216 -r 279f1782c184 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")