Skip to content

Commit

Permalink
fix export and import
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Mar 14, 2017
1 parent 110f10d commit 534063a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
42 changes: 24 additions & 18 deletions apps/domain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions apps/domain/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 3 additions & 3 deletions apps/questions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down

0 comments on commit 534063a

Please sign in to comment.