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

Add support for big-image #635

Merged
merged 3 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion pyxform/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"tag": constants.NAME,
"value": constants.NAME,
"image": "media::image",
"big-image": "media::big-image",
"audio": "media::audio",
"video": "media::video",
"count": "control::jr:count",
Expand All @@ -114,7 +115,7 @@
constants.HINT: constants.HINT,
"guidance_hint": "guidance_hint",
"image": survey_header["image"],
# Per ODK Spec, could include "big-image" once pyxform supports it.
"big-image": survey_header["big-image"],
"audio": survey_header["audio"],
"video": survey_header["video"],
"jr:constraintMsg": "constraint_message",
Expand All @@ -123,6 +124,7 @@
TRANSLATABLE_CHOICES_COLUMNS = {
"label": constants.LABEL,
"image": "media::image",
"big-image": "media::big-image",
"audio": "media::audio",
"video": "media::video",
}
Expand All @@ -131,6 +133,7 @@
"list_name": constants.LIST_NAME,
"value": constants.NAME,
"image": "media::image",
"big-image": "media::big-image",
"audio": "media::audio",
"video": "media::video",
}
Expand Down
9 changes: 9 additions & 0 deletions pyxform/json_form_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@
"description" : "A key value pair where the key is a language, and the value is the content uri in that language."
}
},
"big-image" :
{
"type" : ["object", "string"],
"additionalProperties":
{
"type" : "string",
"description" : "A key value pair where the key is a language, and the value is the content uri in that language."
}
},
"audio" :
{
"type" : ["object", "string"],
Expand Down
2 changes: 1 addition & 1 deletion pyxform/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def itext(self):
itext_nodes.append(
node("value", value, toParseString=output_inserted)
)
elif media_type == "image":
elif media_type == "image" or media_type == "big-image":
if value != "-":
itext_nodes.append(
node(
Expand Down
7 changes: 6 additions & 1 deletion pyxform/survey_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def add_children(self, children):
)

# Supported media types for attaching to questions
SUPPORTED_MEDIA = ("image", "audio", "video")
SUPPORTED_MEDIA = ("image", "big-image", "audio", "video")

def validate(self):
if not is_valid_xml_tag(self.name):
Expand Down Expand Up @@ -428,10 +428,15 @@ def xml_label_and_hint(self) -> "List[DetachableElement]":
msg = "The survey element named '%s' " "has no label or hint." % self.name
if len(result) == 0:
raise PyXFormError(msg)

# Guidance hint alone is not OK since they may be hidden by default.
if not any((self.label, self.media, self.hint)) and self.guidance_hint:
raise PyXFormError(msg)

# big-image must combine with image
if not ("image" in self.media) and "big-image" in self.media:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest if "image" not in self.media and "big-image" in self.media

raise PyXFormError("You must specify an image in order to use big-image.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest raise PyXFormError(f"In order to use big-image, you must specify an image for the survey element named {self.name}


return result

def xml_bindings(self):
Expand Down
14 changes: 13 additions & 1 deletion tests/test_sheet_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_missing_name_but_has_alias_of_name(self):
errored=False,
)

def test_missing_label(self):
def test_label_or_hint__must_be_provided(self):
self.assertPyxformXform(
name="invalidcols",
ss_structure={"survey": [{"type": "text", "name": "q1"}]},
Expand Down Expand Up @@ -63,6 +63,18 @@ def test_label_node_added_when_hint_given_but_no_label_value(self):
xml__contains=prep_for_xml_contains(expected),
)

def test_big_image_invalid_if_no_image(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | media::big-image |
| | text | c | m.png |
""",
errored=True,
error__contains=["must specify an image"],
)

def test_column_case(self):
"""
Ensure that column name is case insensitive
Expand Down
Loading