diff -r 9927a619d2b5 -r 9bae869b2146 web/ldt/ldt_utils/projectserializer.py --- a/web/ldt/ldt_utils/projectserializer.py Fri Oct 15 12:36:43 2010 +0200 +++ b/web/ldt/ldt_utils/projectserializer.py Fri Oct 15 12:38:52 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 @@ -278,6 +324,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")