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

Allowing xml-internal question type. #383

Closed
wants to merge 1 commit into from

Conversation

nribeka
Copy link
Contributor

@nribeka nribeka commented Oct 3, 2019

Fix #176.

This would allow question of type xml-internal.

@nribeka
Copy link
Contributor Author

nribeka commented Oct 3, 2019

@lognaturel see also my comment in #176. Is this the expected behavior?

@nribeka nribeka marked this pull request as ready for review October 3, 2019 16:02
@lognaturel
Copy link
Contributor

@nribeka is this behavior on master or just on this branch? What happens if you actually include a select on the fruits list, is it inlined or added as an instance?

@nribeka
Copy link
Contributor Author

nribeka commented Oct 3, 2019

@lognaturel, this is in master.

As long as you add choice_filter it will add everything from the choices sheet as separate instance even though it's not being used by any question.

If you add select on fruits, then it will add it to the body and also create an instance of it.

      <instance id="fruits">
        <root>
          <item>
            <label>Apple</label>
            <name>apple</name>
          </item>
          <item>
            <label>Banana</label>
            <name>banana</name>
          </item>
        </root>
      </instance>
    <select1 ref="/data/fruit">
      <label>The Fruit</label>
      <item>
        <label>Apple</label>
        <value>apple</value>
      </item>
      <item>
        <label>Banana</label>
        <value>banana</value>
      </item>
    </select1>

@nribeka
Copy link
Contributor Author

nribeka commented Oct 3, 2019

I think it's coming from this line: https://github.com/XLSForm/pyxform/blame/master/pyxform/xls2json.py#L1119

                if row.get("choice_filter"):
                    if select_type == "select one external":
                        new_json_dict["query"] = list_name
                    else:
                        new_json_dict["itemset"] = list_name
                        json_dict["choices"] = choices
                        if choices.get(list_name):
                            new_json_dict["list_name"] = list_name
                            new_json_dict[constants.CHOICES] = choices[list_name]

This assignment: json_dict["choices"] = choices is adding the whole choices sheet to the json.

@yanokwa yanokwa added this to the v1.0.0 milestone Nov 18, 2019
Copy link
Contributor

@lognaturel lognaturel left a comment

Choose a reason for hiding this comment

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

There should not be primary instance nodes created for xml-internal questions. I think that ideally when a list name that doesn't exist in the choices tab is specified, that should lead to an error.

It would be helpful to add a test that verifies that extra columns' values are added to the secondary instance. Luckily, it looks like that behavior already works.

For this form:

            | survey  |                    |            |           |            |                   |
            |         | type               | name       | label     | hint       |appearance         |
            |         | xml-internal       | states     | The state |            |                   |
            |         | xml-internal       | yes_no     |           |            |                   |
            | choices |                    |            |           |            |                   |
            |         | list_name          | name       | label     | capital    | color             |
            |         | states             | VA         | Virginia  | Richmond   | orange            |
            |         | states             | IN         | Indiana   | Indianapolis|                  |
            |         | fruits             | apple      | Apple     |            | red               |
            |         | fruits             | banana     | Banana    |            | yellow            |

we expect to see capital and color nodes in the secondary instances where those have values in the form definition.


self.assertContains(survey_xml, '<instance id="yes_no">', 1)
self.assertContains(survey_xml, '<instance id="states">', 1)
self.assertContains(survey_xml, '<instance id="fruits">', 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

fruits isn't used anywhere so I wouldn't expect it be generated. I think this is existing behavior so maybe we don't need to change it here?

self.assertPyxformXform(
md=md,
model__contains=[
'<instance id="yes_no">',
Copy link
Contributor

Choose a reason for hiding this comment

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

The two assertion blocks seem redundant to me. Perhaps it's best to go with the first variant so the count can be verified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add type=xml-internal and generate instance XML from choices sheet
3 participants