def check(self): file_type, encoding = mimetypes.guess_type(self.file_name) if file_type == 'application/xml': self.root = read_xml_file(self.file_name) if self.root and self.root.tag == 'project': self.ns_map = get_ns_map(self.root) return True
def check(self): file_type, encoding = mimetypes.guess_type(self.file_name) if file_type == 'application/xml': self.root = read_xml_file(self.file_name) if self.root: self.ns_map = get_ns_map(self.root) if self.root.tag == '{{{ns0}}}resource'.format(**self.ns_map): return True
def import_project(user, root): ns_map = get_ns_map(root) project = Project() project.title = root.find('title').text or '' project.description = root.find('description').text or '' project.created = root.find('created').text catalog = get_uri(root.find('catalog'), ns_map) try: project.catalog = Catalog.objects.get(uri=catalog) except Catalog.DoesNotExist: log.info('Catalog not in db. Created with uri %s', catalog) project.catalog = Catalog.objects.first() project.save() # add user to project membership = Membership(project=project, user=user, role='owner') membership.save() snapshots_node = root.find('snapshots') if snapshots_node is not None: for snapshot_node in snapshots_node.findall('snapshot'): if snapshot_node is not None: snapshot = Snapshot() snapshot.project = project snapshot.title = snapshot_node.find('title').text or '' snapshot.description = snapshot_node.find( 'description').text or '' snapshot.created = snapshot_node.find('created').text snapshot.save() snapshot_values_node = snapshot_node.find('values') if snapshot_values_node is not None: for snapshot_value_node in snapshot_values_node.findall( 'value'): import_value(snapshot_value_node, ns_map, project, snapshot) values_node = root.find('values') if values_node is not None: for value_node in values_node.findall('value'): import_value(value_node, ns_map, project)