web/ldt/ldt_utils/projectserializer.py
changeset 97 66f6aff5c382
parent 89 30c6e597a7de
child 98 c9460033138f
equal deleted inserted replaced
90:0325a0a8b997 97:66f6aff5c382
     1 import lxml.etree
     1 import lxml.etree
     2 import uuid
     2 import uuid
     3 from datetime import datetime
     3 from datetime import datetime
       
     4 from django.utils.datastructures import SortedDict
     4 from ldt.ldt_utils.models import Content, Project
     5 from ldt.ldt_utils.models import Content, Project
     5 
     6 
     6 DATE_FORMATS = ["%d/%m/%Y","%Y-%m-%d"]
     7 DATE_FORMATS = ["%d/%m/%Y","%Y-%m-%d"]
     7 
     8 
     8 """
     9 """
    14         self.project = project
    15         self.project = project
    15         self.parsed = False
    16         self.parsed = False
    16         self.ldt_doc = None
    17         self.ldt_doc = None
    17         self.medias = []
    18         self.medias = []
    18         self.medias_by_id = {}
    19         self.medias_by_id = {}
       
    20         self.medias_dict = SortedDict()
    19         self.annotations = []
    21         self.annotations = []
    20         self.annotations_by_annotation_type = {}
    22         self.annotations_by_annotation_type = {}
       
    23         self.annotations_dict = SortedDict()
    21         self.tags = {}
    24         self.tags = {}
    22         self.tags_by_id = {}
    25         self.tags_by_id = {}
    23         self.annotation_types = []
    26         self.annotation_types = []
    24         self.annotation_types_by_id = {}
    27         self.annotation_types_by_id = {}
       
    28         self.annotation_types_dict = SortedDict()
    25         self.views = []
    29         self.views = []
    26         self.lists = []
    30         self.lists = []
    27         self.lists_by_id = {}
    31         self.lists_by_id = {}
       
    32         self.lists_dict = SortedDict()
    28         self.serialize_contents = from_contents
    33         self.serialize_contents = from_contents
    29         self.from_display = from_display
    34         self.from_display = from_display
    30         
    35         
    31     
    36     
    32     def __parse_ensemble(self, ensemble_node, content):
    37     def __parse_ensemble(self, ensemble_node, content):
   318              }
   323              }
   319         }
   324         }
   320         
   325         
   321         self.medias.append(new_media)
   326         self.medias.append(new_media)
   322         self.medias_by_id[content.iri_id] = new_media
   327         self.medias_by_id[content.iri_id] = new_media
       
   328         self.medias_dict[content.iri_id] = new_media
   323         
   329         
   324         if self.serialize_contents:        
   330         if self.serialize_contents:        
   325             res = doc.xpath("/iri/body/ensembles/ensemble")
   331             res = doc.xpath("/iri/body/ensembles/ensemble")
   326             for ensemble_node in res:
   332             for ensemble_node in res:
   327                 self.__parse_ensemble(ensemble_node, content)
   333                 self.__parse_ensemble(ensemble_node, content)