diff --git a/apps/domain/utils.py b/apps/domain/utils.py index 1015f4c659..504a680cef 100644 --- a/apps/domain/utils.py +++ b/apps/domain/utils.py @@ -97,27 +97,33 @@ def import_attribute(attribute_node, nsmap, parent=None): def import_verbose_name(verbosename_node, entity): - if verbosename_node: + if verbosename_node is not None: try: - verbosename = VerboseName.objects.get(attribute_entity=entity) - except VerboseName.DoesNotExist: - verbosename = VerboseName(attribute_entity=entity) + try: + verbosename = VerboseName.objects.get(attribute_entity=entity) + except VerboseName.DoesNotExist: + verbosename = VerboseName(attribute_entity=entity) - for element in verbosename_node['name']: - setattr(verbosename, 'name_' + element.get('lang'), element.text) - for element in verbosename_node['name_plural']: - setattr(verbosename, 'name_plural_' + element.get('lang'), element.text) - verbosename.save() + for element in verbosename_node['name']: + setattr(verbosename, 'name_' + element.get('lang'), element.text) + for element in verbosename_node['name_plural']: + setattr(verbosename, 'name_plural_' + element.get('lang'), element.text) + verbosename.save() + except AttributeError: + pass def import_range(range_node, attribute): - if range_node: + if range_node is not None: try: - range = Range.objects.get(attribute=attribute) - except Range.DoesNotExist: - range = Range(attribute=attribute) - - range.minimum = range_node['minimum'] - range.maximum = range_node['maximum'] - range.step = range_node['step'] - range.save() + try: + range = Range.objects.get(attribute=attribute) + except Range.DoesNotExist: + range = Range(attribute=attribute) + + range.minimum = range_node['minimum'] + range.maximum = range_node['maximum'] + range.step = range_node['step'] + range.save() + except AttributeError: + pass diff --git a/apps/domain/views.py b/apps/domain/views.py index 202967865b..89bc195741 100644 --- a/apps/domain/views.py +++ b/apps/domain/views.py @@ -47,6 +47,12 @@ class DomainExportView(ModelPermissionMixin, ListView): context_object_name = 'entities' permission_required = 'domain.view_attributeentity' + def get_queryset(self): + if self.kwargs.get('format') == 'xml': + return AttributeEntity.objects.filter(parent=None) + else: + return AttributeEntity.objects.all() + def render_to_response(self, context, **response_kwargs): format = self.kwargs.get('format') if format == 'xml': diff --git a/apps/questions/utils.py b/apps/questions/utils.py index 82a0902f91..8655896fa0 100644 --- a/apps/questions/utils.py +++ b/apps/questions/utils.py @@ -20,7 +20,7 @@ def import_catalog(catalog_node): catalog.comment = catalog_node[get_ns_tag('dc:comment', nsmap)] catalog.order = catalog_node['order'] for element in catalog_node.title: - setattr(catalog, 'title_' + element.get('lang'), element) + setattr(catalog, 'title_' + element.get('lang'), element.text) catalog.save() @@ -43,7 +43,7 @@ def import_section(section_node, nsmap, catalog=None): section.catalog = catalog section.order = section_node['order'] for element in section_node.title: - setattr(section, 'title_' + element.get('lang'), element) + setattr(section, 'title_' + element.get('lang'), element.text) section.save() @@ -66,7 +66,7 @@ def import_subsection(subsection_node, nsmap, section=None): subsection.section = section subsection.order = subsection_node['order'] for element in subsection_node.title: - setattr(subsection, 'title_' + element.get('lang'), element) + setattr(subsection, 'title_' + element.get('lang'), element.text) subsection.save()