Skip to content

Commit

Permalink
dev: move binding_conversion dict to aliases, remove irrelevant comment
Browse files Browse the repository at this point in the history
- feedback from PR #685
  • Loading branch information
lindsay-stevens committed Feb 8, 2024
1 parent b7c496a commit 64903fd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
14 changes: 14 additions & 0 deletions pyxform/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,17 @@
"username",
]
osm = {"osm": constants.OSM_TYPE}
BINDING_CONVERSIONS = {
"yes": "true()",
"Yes": "true()",
"YES": "true()",
"true": "true()",
"True": "true()",
"TRUE": "true()",
"no": "false()",
"No": "false()",
"NO": "false()",
"false": "false()",
"False": "false()",
"FALSE": "false()",
}
2 changes: 0 additions & 2 deletions pyxform/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def copy_json_dict(json_dict):


class SurveyElementBuilder:
# we use this CLASSES dict to create questions from dictionaries

def __init__(self, **kwargs):
# I don't know why we would need an explicit none option for
# select alls
Expand Down
14 changes: 0 additions & 14 deletions pyxform/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,6 @@ class EntityColumns(StrEnum):
"becomes '_setting'."
)

BINDING_CONVERSIONS = {
"yes": "true()",
"Yes": "true()",
"YES": "true()",
"true": "true()",
"True": "true()",
"TRUE": "true()",
"no": "false()",
"No": "false()",
"NO": "false()",
"false": "false()",
"False": "false()",
"FALSE": "false()",
}
CONVERTIBLE_BIND_ATTRIBUTES = (
"readonly",
"required",
Expand Down
5 changes: 3 additions & 2 deletions pyxform/survey_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from functools import lru_cache
from typing import TYPE_CHECKING, Any, ClassVar, Dict, List

from pyxform import aliases as alias
from pyxform import constants as const
from pyxform.errors import PyXFormError
from pyxform.question_type_dictionary import QUESTION_TYPE_DICT
Expand Down Expand Up @@ -443,10 +444,10 @@ def xml_bindings(self):
# the xls2json side.
if (
hashable(v)
and v in const.BINDING_CONVERSIONS
and v in alias.BINDING_CONVERSIONS
and k in const.CONVERTIBLE_BIND_ATTRIBUTES
):
v = const.BINDING_CONVERSIONS[v]
v = alias.BINDING_CONVERSIONS[v]
if k == "jr:constraintMsg" and (
isinstance(v, dict) or re.search(BRACKETED_TAG_REGEX, v)
):
Expand Down

0 comments on commit 64903fd

Please sign in to comment.