Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/external instance #107 #169

Merged
Merged
3 changes: 3 additions & 0 deletions pyxform/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from pyxform import file_utils, utils
from pyxform.errors import PyXFormError
from pyxform.external_instance import ExternalInstance
from pyxform.question import (InputQuestion, MultipleChoiceQuestion,
OsmUploadQuestion, Question, RangeQuestion,
TriggerQuestion, UploadQuestion)
Expand Down Expand Up @@ -92,6 +93,8 @@ def create_survey_element_from_dict(self, d):
d = self._sections[section_name]
full_survey = self.create_survey_element_from_dict(d)
return full_survey.children
elif d[u"type"] == u"xml-external":
return ExternalInstance(**d)
else:
return self._create_question_from_dict(
d, copy_json_dict(QUESTION_TYPE_DICT), self._add_none_option)
Expand Down
13 changes: 13 additions & 0 deletions pyxform/external_instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pyxform.survey_element import SurveyElement
from pyxform.utils import node


class ExternalInstance(SurveyElement):

def xml_control(self):
"""
No-op since there is no associated form control to place under <body/>.

Exists here because there's a soft abstractmethod in SurveyElement.
"""
pass
11 changes: 11 additions & 0 deletions pyxform/instance_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


class InstanceInfo(object):
"""Standardise Instance details relevant during XML generation."""

def __init__(self, type, context, name, src, instance):
self.type = type
self.context = context
self.name = name
self.src = src
self.instance = instance
3 changes: 3 additions & 0 deletions pyxform/question_type_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,8 @@ def generate_new_dict():
"bind": {
"type": "binary"
}
},
"xml-external": {
# Only effect is to add an external instance.
}
}
3 changes: 3 additions & 0 deletions pyxform/section.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pyxform.external_instance import ExternalInstance
from pyxform.question import SurveyElement
from pyxform.utils import node
from pyxform.errors import PyXFormError
Expand Down Expand Up @@ -38,6 +39,8 @@ def xml_instance(self, **kwargs):
if child.get(u"flat"):
for grandchild in child.xml_instance_array():
result.appendChild(grandchild)
elif isinstance(child, ExternalInstance):
continue
else:
result.appendChild(child.xml_instance())
return result
Expand Down
Loading