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

Introduce Address answer type #261

Merged
merged 25 commits into from
Sep 3, 2020
Merged

Introduce Address answer type #261

merged 25 commits into from
Sep 3, 2020

Conversation

MebinAbraham
Copy link
Contributor

@MebinAbraham MebinAbraham commented Aug 27, 2020

What is the context of this PR?

For context see: #241

Introduced a new answer type to support address answers in runner.
This introduces a new data model for storing address answers:

{
  "answer_id": "address",
  "value": {
    "line1": "7 Evelyn Street",
    "town": "Barry",
    "postcode": "CF63 4EN"
  }
}

How to review

  • Ensure the feature is as expected.

Note:

  • Support for lookups will be done in a future card.
  • Support for piping address answers using placeholder will be done in a future card.

Checklist

  • New static content marked up for translation
  • Newly defined schema content included in eq-translations repo

Comment on lines +9 to +13
"autosuggest":{
"label": {
"text": _("Enter address or postcode and select from results")
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added because the DS component requires this at the moment. This bug will be fixed in the DS soon.

app/data_model/answer.py Outdated Show resolved Hide resolved
app/forms/field_handlers/address_handler.py Outdated Show resolved Hide resolved
app/forms/field_handlers/address_handler.py Outdated Show resolved Hide resolved
app/forms/field_handlers/address_handler.py Outdated Show resolved Hide resolved
app/forms/field_handlers/address_handler.py Outdated Show resolved Hide resolved
tests/app/forms/field_handlers/test_address_handler.py Outdated Show resolved Hide resolved
tests/app/forms/field_handlers/test_address_handler.py Outdated Show resolved Hide resolved
tests/app/forms/field_handlers/test_address_handler.py Outdated Show resolved Hide resolved
tests/app/forms/field_handlers/test_address_handler.py Outdated Show resolved Hide resolved
@@ -17,6 +17,7 @@
map_list_collector_config,
RadioConfig,
CheckboxConfig,
get_formatted_address,
Copy link
Contributor

Choose a reason for hiding this comment

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

These imports should be sorted

Copy link
Contributor Author

@MebinAbraham MebinAbraham Sep 1, 2020

Choose a reason for hiding this comment

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

Again we need to add a linter for things like this (if possible) if we are to enforce. But I have updated anyway 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks - I am in the process of adding a card to integrate isort to our linting and make it compatible with Black

@MebinAbraham
Copy link
Contributor Author

MebinAbraham commented Sep 1, 2020

@JamesGardiner All comments should now be addressed.

Copy link
Contributor

@LJBabbage LJBabbage left a comment

Choose a reason for hiding this comment

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

Works as expected, a few minor comments

app/forms/field_handlers/address_handler.py Outdated Show resolved Hide resolved

return validate_with

def get_field(self) -> AddressField:
Copy link
Contributor

Choose a reason for hiding this comment

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

get_address_field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get_field because it is overriding the abstract base class method.


from wtforms import Form, FormField, StringField

logger = logging.getLogger(__name__)
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't see where this is used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not used explicitly but defined to ensure the logger logs errors with the correct module name. This is a common pattern across runner.

app/forms/fields/address_field.py Outdated Show resolved Hide resolved
app/forms/validators.py Outdated Show resolved Hide resolved
@@ -216,13 +216,23 @@ def update_answers(self, form_data, list_item_id=None):
for answer_id, answer_value in form_data.items():

if answer_id in answer_ids_for_question:
if answer_value not in self.EMPTY_ANSWER_VALUES:
answer_value_to_store = (
Copy link
Contributor

@LJBabbage LJBabbage Sep 1, 2020

Choose a reason for hiding this comment

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

Not 100% sure what this is doing, looks to me if answer_value is a dict make another dict with all the empties removed. Then check it's not completely empty at a later stage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just filtering out any EMPTY_ANSWER_VALUES when the answer is a dict i.e address since we don't store any answers that match EMPTY_ANSWER_VALUES.

tests/functional/spec/components/address/address.spec.js Outdated Show resolved Hide resolved
tests/functional/spec/components/address/address.spec.js Outdated Show resolved Hide resolved
tests/functional/spec/components/address/address.spec.js Outdated Show resolved Hide resolved
tests/functional/spec/components/address/address.spec.js Outdated Show resolved Hide resolved
app/forms/validators.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ajmaddaford ajmaddaford left a comment

Choose a reason for hiding this comment

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

As discussed, we should be testing the summary output for no address answer (optional address), and I've asked Andy about whether address line 1 should be mandatory for optional addresses (if they fill in at least one address field).

@MebinAbraham
Copy link
Contributor Author

As discussed, we should be testing the summary output for no address answer (optional address), and I've asked Andy about whether address line 1 should be mandatory for optional addresses (if they fill in at least one address field).

Have updated schema/tests for optional version.

@MebinAbraham MebinAbraham merged commit 783f102 into master Sep 3, 2020
@MebinAbraham MebinAbraham deleted the address-answer-type branch September 3, 2020 15:52
@pricem14pc pricem14pc added this to the v3.48.0 milestone Sep 11, 2020
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.

5 participants