def __restore_metadata_v1(self, metadata): self.title = metadata.get("title") self.description = metadata.get("description") self.is_template = metadata.get("is_template") self.projects.clear() self.child_elements.all().delete() section_elements = {} for child_metadata in metadata.get("child_elements"): try: element, section_child_elements = LabBookChildElement.create_from_metadata(child_metadata) element.save() if section_child_elements: section_elements[element] = section_child_elements except EntityMissingError: pass # ignore hard-deleted entities for section, child_element_pks in section_elements.items(): elements = LabBookChildElement.objects.filter( child_object_id__in=child_element_pks ) section.child_object.child_elements.add(*elements) project_pks = metadata.get("projects") if project_pks is not None and len(project_pks) > 0: projects = Project.objects.filter(pk__in=project_pks).viewable() self.projects.add(*projects) Metadata.restore_all_from_entity(self, metadata.get("metadata"))
def __restore_metadata_v1(self, metadata): self.title = metadata.get("title") picture_entry_pk = metadata.get("uploaded_picture_entry") if picture_entry_pk is not None and picture_entry_pk != '': self.restore_from_picture_entry(picture_entry_pk) self.projects.clear() project_pks = metadata.get("projects") if project_pks is not None and len(project_pks) > 0: projects = Project.objects.filter(pk__in=project_pks).viewable() self.projects.add(*projects) Metadata.restore_all_from_entity(self, metadata.get("metadata"))
def __export_metadata_v1(self): return { METADATA_VERSION_KEY: 1, "title": self.title, "uploaded_picture_entry": pk_or_none(self.uploaded_picture_entry), "projects": [p.pk for p in self.projects.all()], "metadata": Metadata.export_all_from_entity(self), }
def __export_metadata_v1(self): return { METADATA_VERSION_KEY: 1, "title": self.title, "description": self.description, "is_template": self.is_template, "child_elements": [c.export_metadata() for c in self.child_elements.all()], "projects": [p.pk for p in self.projects.all()], "metadata": Metadata.export_all_from_entity(self), }
def __restore_metadata_v1(self, metadata): self.title = metadata.get("title") self.status = metadata.get("status") self.projects.clear() project_pks = metadata.get("projects") if project_pks is not None and len(project_pks) > 0: projects = Project.objects.filter(pk__in=project_pks).viewable() self.projects.add(*projects) form_pk = metadata.get("form_pk") if form_pk is not None: self.dmp_form_id = form_pk with disable_permission_checks(DmpFormData): self.dmp_form_data.all().delete() for field_data_metadata in metadata.get("field_data"): data = DmpFormData.create_from_metadata(field_data_metadata) data.save() Metadata.restore_all_from_entity(self, metadata.get("metadata"))
def __export_metadata_v1(self): # the DMP form can not change, therefore we just have to store the values return { METADATA_VERSION_KEY: 1, "title": self.title, "status": self.status, "field_data": [data.export_metadata() for data in self.dmp_form_data.all()], "projects": [project.pk for project in self.projects.all()], "metadata": Metadata.export_all_from_entity(self), }