Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pyxform/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pyxform.errors import ErrorCode, PyXFormError
from pyxform.external_instance import ExternalInstance
from pyxform.question import (
GeoQuestion,
InputQuestion,
MultipleChoiceQuestion,
Option,
Expand All @@ -39,6 +40,11 @@
"select1": MultipleChoiceQuestion,
"trigger": TriggerQuestion,
"upload": UploadQuestion,
"__by_type__": {
"geopoint": GeoQuestion,
"geoshape": GeoQuestion,
"geotrace": GeoQuestion,
},
}
SECTION_CLASSES = {
const.GROUP: GroupedSection,
Expand Down Expand Up @@ -104,7 +110,7 @@ def create_survey_element_from_dict(
d = self._sections[section_name]
full_survey = self.create_survey_element_from_dict(d=d, choices=choices)
return full_survey.children
elif d[const.TYPE] in {"xml-external", "csv-external"}:
elif d[const.TYPE] in const.EXTERNAL_INSTANCE_TYPES:
return ExternalInstance(**d)
elif d[const.TYPE] == "entity":
return EntityDeclaration(**d)
Expand Down Expand Up @@ -157,7 +163,9 @@ def _create_question_from_dict(

if question_class:
if choices:
d_choices = d.get(const.CHOICES, d.get(const.CHILDREN))
d_choices = choices.get(
d.get(const.ITEMSET), d.get(const.CHOICES, d.get(const.CHILDREN))
)
if d_choices:
return question_class(
question_type_dictionary=question_type_dictionary,
Expand All @@ -166,7 +174,7 @@ def _create_question_from_dict(
for k, v in d.items()
if k not in {const.CHOICES, const.CHILDREN}
},
choices=choices.get(d[const.ITEMSET], d_choices),
choices=d_choices,
)

return question_class(question_type_dictionary=question_type_dictionary, **d)
Expand Down Expand Up @@ -196,6 +204,10 @@ def _get_question_class(question_type_str, question_type_dictionary):
and find what class it maps to going through
type_dictionary -> QUESTION_CLASSES
"""
by_type = QUESTION_CLASSES["__by_type__"].get(question_type_str, None)
if by_type is not None:
return by_type

control_tag = ""
question_type = question_type_dictionary.get(question_type_str)
if question_type:
Expand Down
3 changes: 3 additions & 0 deletions pyxform/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class EntityColumns(StrEnum):
AUDIO_QUALITY_EXTERNAL = "external"

EXTERNAL_INSTANCE_EXTENSIONS = {".xml", ".csv", ".geojson"}
EXTERNAL_INSTANCE_TYPES = {"csv-external", "xml-external"}

DEFAULT_ITEMSET_LABEL_REF = "label"
DEFAULT_ITEMSET_VALUE_REF = "name"
Expand Down Expand Up @@ -194,11 +195,13 @@ class ParametersAudit(StrEnum):
class ParametersGeo(StrEnum):
ALLOW_MOCK_ACCURACY = "allow-mock-accuracy"
INCREMENTAL = "incremental"
REFERENCE_GEOMETRY = "reference-geometry"


class ParametersGeoPoint(StrEnum):
ALLOW_MOCK_ACCURACY = "allow-mock-accuracy"
CAPTURE_ACCURACY = "capture-accuracy"
REFERENCE_GEOMETRY = "reference-geometry"
WARNING_ACCURACY = "warning-accuracy"


Expand Down
9 changes: 9 additions & 0 deletions pyxform/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,15 @@ class ErrorCode(Enum):
"The following are invalid parameter key(s): '{rejected}'."
),
)
SURVEY_006: Detail = Detail(
name="Survey sheet - invalid geo parameter 'reference-geometry'",
msg=(
"[row : {row}] On the 'survey' sheet, the 'parameters' value is invalid. "
"The 'reference-geometry' parameter must either match a secondary instance "
"name (a choices list_name, an entities list_name, or the base name of an "
"attached file), or be a reference variable containing the name of a repeat."
),
)


class PyXFormError(Exception):
Expand Down
Loading
Loading