def _save_section(self, source_section, parent): # create new section document s = LatestSection() # set parent for that section # None means that it is section at the top of the hierarchy s.parent = parent # rewrite section related fields s.name = source_section.name s.type_name = source_section.type s.reference = source_section.reference s.definition = source_section.definition s.repository = source_section.repository s.mapping = source_section.mapping s.link = source_section.link s.include = source_section.include s.isLatest = True # use external method for rewriting properties # COMMENTED PROPERTIES SAVE ! ! ! self._rewrite_properties(source_section, s) # recursively add subsections for section in source_section.sections: s.subsections.append(self._save_section(section, None)) # initialize identity hash for that section s.sid() # parent hash changed after subsections were added # so parent hash need to be updated for every subsection for section in s.subsections: temp = LatestSection.objects(object_id=section)[0] temp.parent = s.sid() temp.save() # save section in database s.save() # return section hash - id return s.sid()
def save_section(self, section, section_type): #create new section if (section_type == "latest"): s = LatestSection() print "[[[LATEST]]]" elif (section_type == "old"): s = OldSection() print "{{{OLD}}}" else: s = TempSection() print "(((TEMP)))" s.object_id = section.object_id # print "OBJECT_ID: " + str(s.object_id) s.name = section.name # print "NAME: " + str(s.name) s.type_name = section.type_name s.reference = section.reference s.definition = section.definition s.repository = section.repository s.mapping = section.mapping s.link = section.link s.include = section.include s.parent = section.parent # PROPERTIES SAVE self.rewrite_properties(section, s) # recursively add subsections # print "add subsections" for sec in section.subsections: # print "subsection_id => " + sec if (section_type == "latest"): section = TempSection.objects(object_id = sec)[0] # print "subsection_name : " + str(section) s.subsections.append(self.save_section(section, "latest")) elif (section_type == "old"): # print "subsection_name" + str(LatestSection.objects(object_id = sec)[0].name) s.subsections.append(self.save_section(LatestSection.objects(object_id = sec)[0], "old")) else: # print "subsection_name" + str(OldSection.objects(object_id = sec)[0].name) s.subsections.append(self.save_section(OldSection.objects(object_id = sec)[0], "temp")) # print "end. (" + str(s.sid()) + ") { " + str(s.name) + " }\n" s.sid() # parent hash changed after subsections were added # so parent hash need to be updated for every subsection for subsection in s.subsections: # print "[[ " + str(LatestSection.objects(object_id=section)) + " ]]" if (section_type == "latest"): temp = LatestSection.objects(object_id=subsection)[0] elif (section_type == "old"): temp = OldSection.objects(object_id=subsection)[0] else: temp = TempSection.objects(object_id=subsection)[0] temp.parent = s.sid() temp.save() # save section in database # print "SID! for: " + str(s.name) # print s.sid() # print "END!\n\n" s.save() #return id self.to_delete.append(section) print s.name + " --> DEL" return s.sid()