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

Make address fields dynamic, based on the selected country for the address field, handle international addresses #281

Closed
nonprofittechy opened this issue Aug 28, 2021 · 4 comments
Assignees
Milestone

Comments

@nonprofittechy
Copy link
Member

nonprofittechy commented Aug 28, 2021

MVP: update the "states list" if someone selects a country outside of the US. Also update the label of "zip code" to "postal code"

Beyond MVP: figure out which countries we can have country-specific address fields for, and which countries might benefit instead from just an open text input. We could probably just hardcode a small list of fields for countries that our client population frequently encounters, such as Canada and Mexico, although we might also consider using all of the fields that Google knows about and using a Python library that helps figure out which fields are relevant in a particular country. See https://docassemble.org/docs/objects.html#Address

    myaddress.street_number - the street number (e.g., 123).
    myaddress.street - the street name (e.g., Main St).
    myaddress.city - the city (known as (locality).
    myaddress.county - the county (known as administrative_area_level_2).
    myaddress.state - the state (known as administrative_area_level_1).
    myaddress.zip - the Zip code (known as postal_code).
    myaddress.country - the country (e.g., US) in ISO 3166-1 alpha-2 format.
    myaddress.administrative_area_level_1
    myaddress.administrative_area_level_2
    myaddress.administrative_area_level_3
    myaddress.administrative_area_level_4
    myaddress.administrative_area_level_5
    myaddress.colloquial_area
    myaddress.floor
    myaddress.intersection
    myaddress.locality
    myaddress.neighborhood
    myaddress.post_box
    myaddress.postal_code
    myaddress.postal_code_prefix
    myaddress.postal_code_suffix
    myaddress.postal_town
    myaddress.premise
    myaddress.room
    myaddress.route
    myaddress.sublocality
    myaddress.sublocality_level_1
    myaddress.sublocality_level_2
    myaddress.sublocality_level_3
    myaddress.sublocality_level_4
    myaddress.sublocality_level_5
    myaddress.subpremise

See #127, and also the way that the "state" field is made dynamic when someone selects a country in https://github.com/SuffolkLITLab/docassemble-ALWeaver/pull/478/files

@nonprofittechy
Copy link
Member Author

Some code related to this that I'm removing from its original branch for now:

        # if show_country:
        #     state_field = {
        #         "label": (f"% if not defined('{ self.attr_name('country') }'):\n" +
        #                   str(self.state_label) + "\n" +
        #                   f"% elif safe_subdivision_type({ self.attr_name('country')}):\n" +
        #                   f"${{ safe_subdivision_type({ self.attr_name('country')}) }}\n" +
        #                   "% else:\n" +
        #                   str(self.state_label) + "\n" +
        #                   "% endif"),
        #         "field": self.attr_name("state"),
        #         "default": default_state if default_state else ''
        #     }
        #     # TODO: futureproofing for dynamic state list
        #     # state_field["code"] = f"safe_states_list(country_code={self.attr_name('country')}) if pycountry.subdivisions.get(country_code={self.attr_name('country')}) else ()"

        #     fields.append(state_field)

plocket added a commit that referenced this issue Jan 18, 2023
* Fix #296

* Provide some placeholders to allow dynamically updating state list - #281

* Format phone numbers

* 🎨 Format Python code with psf/black

* Check if the `suffix_to_append` attribute exists

On older objects, the attribute might not exist, so make sure it's
updated to the standard default.

* 🎨 Format Python code with psf/black

* Bump version: 2.15.0 → 2.16.0

* Bump version: 2.16.0 → 2.17.0

* Update CHANGELOG.md

Remove accidental 2.16

* Fix #585 - improve usability of signature question

* Fix #578 fix #571 - let author filter irrelevant sessions and remove sessions at step 1 by default

* Incorporate feedback from PR

* Fix  #573 Fix #572

* reformat with black

* Improve #571 - add to global config

* Fix #592 - redirect if user logged out

* language changes from @CaroRob

* User user_role, not users

* more using user_role

* Use `user_started_case`, not `user_role`

The latter isn't actually used in AL core much, so even though it is the
better variable name, changing the logic of other variables is more likely
to break others interviews.

* Fix #598

* 🎨 Format Python code with psf/black

* Added black hook + black opts to pyproject.toml

Also moved mypy configs to the same pyproject.toml instead of a separate mypy.ini

* Add note about `exclude_newly_started_sessions`

* Decrease the size of images in tables

Commonly in review tables.

* Added a max size feature to the ExhibitDocument (#604)

* Added a max size feature to the ExhibitDocument

Also give suggested remaining upload size in human readable file sizes in
errors and in between upload screens.

* Teams bump hook, in a github action (#602)

* Teams bump hook, in a github action

Fixes #547

* Don't check if the ref equals the version on branches, only tags
* Use `|` instead of `/`, otherwise sed can't use repo names and URLs.

* If address is empty, `on_one_line()` will be empty (#605)

* If address is empty, `on_one_line()` will be empty

Originally, was ", ", which is def a bug

* Mypy changed defaults about implicit optionals

* No more implicit optionals in function signatures

Apparently not allowed by PEP-484. Personally, I've gotten used to it, but
I remember being confused by it, and the change isn't too bad.

* Fix #243, don't cut off words for addendum in mid-sentence

* 🎨 Format Python code with psf/black

* Multi-line return value

* Bump version to v2.18.0

* failure was in a name, not an if

* Tag URL had extra https://

* Improve calculation of max lines, better test cases, consistent overflow and safe_value handling of whitespace

* 🎨 Format Python code with psf/black

* Test case

* Some correctness fixes for whitespace, working tests without 'define()'

* Update docassemble/AssemblyLine/al_document.py

* Add preserve_words option to alternate API

* Remove words 'the' and 'project' from opening screen - Fix #611

* Bump version

* Update CHANGELOG.md

* Change OCR to use ocrmypdf in the background

Triggers an event in `al_document.yml`, which calls back into a module.

* Add config option for OCRMyPDF

* Added OCRmyPDF to changelog

* Add visible trigger variable to the developer-only heads up display (#617)

* Fix #616

* Update docassemble/AssemblyLine/data/questions/al_visual.yml

Co-authored-by: Bryce Willey <Bryce.Steven.Willey@gmail.com>

Co-authored-by: Bryce Willey <Bryce.Steven.Willey@gmail.com>

* First version of DACatchAll, #618

* Add css to all catchall qs

* Progress on #620

* WIP

* Fix #615, additional refinement of #620

* Cleanup error page a bit

* Add focus shadow for back button

Before this change, you aren't able to see that you are keyboard tabbing
over the back button, as the value bootstrap uses to color the shadow
doesn't have a value for the `daquestionbackbutton` class, only
the `btn-primary` class.

TBH, I'm not a huge fan of the default focus indicators in bootstrap,
they don't have enough contrast. But that will likely have to wait
for a different PR, as it's a much larger change.

* Put 'download work in progress' behind a config option- anyone w/ a paywall won't want this turned on

* `will_send_to_real_court` false if debug == True

Necessary to safely test on any new server being spun up.

Debug: true shouldn't be on in production servers.

* Fix #625 - make answer sets unencrypted to match interview state

* Put actions behind config + individual interview option

* Try to cache python deps when running unittests

Also bump to python 3.9: closer to still working with python
3.8 for older docassemble versions, but still on by default
in ubuntu 22.04, the new test runners on github.

* Quick remove old blank step

* Trying for easier unittest workflow

* Add wheel package

* Start using --use-pep517?

* Can't actually use `--use-pep517` yet

One of the packages fails with an obscure error
message, so I'll just have to turn it off now.

```
Collecting guess-language-spirit==0.5.3
  Using cached guess_language-spirit-0.5.3.tar.bz2 (81 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
ERROR: Could not install packages due to an OSError: [Errno 2] No such
file or directory: '/tmp/tmpdpiv1dse/output.json'
```

* Move everything to a different action

* Address SuffolkLITLab/docassemble-MassAccess#8

* Remove unnecessary 'logo' from alt text

* Fix #636

* Add simple service of process questions, Fix #597, fix #597

* Add marriage questions, fix #630

* Update docassemble/AssemblyLine/data/questions/ql_baseline.yml

Co-authored-by: Bryce Willey <Bryce.Steven.Willey@gmail.com>

* Update docassemble/AssemblyLine/data/questions/ql_baseline.yml

Co-authored-by: Bryce Willey <Bryce.Steven.Willey@gmail.com>

* PR feedback

* Fix #637 - better API for how a lot of states organize courts, by county. Added some useful features like searching by keyword too.

* Reformat with black

* Fix #296

* A little extra safety for existing sessions that might be in the wild

* Fix #260

* set country at a better point in interview; remove commented out section for now

* Readd newlines between each step on intro screen

2 or more trailing whitespaces in markdown will add a line break (<br>) to
the line. The trailing whitespaces that were separating out the 3 introduction
steps for each AL interview were mistakenly removed in
57df4ab#diff-55dff7108dded7bbc3ce8459dd669a79baec6674c1558af86f66dbc878268288L44.

This PR replaces those trailing whitespaces with a more explicit `<br>`.

* Address some linting feedback

* Bump version

* Update CHANGELOG.md

* Fix issue where al_sessions_to_exclude kept growing

* Update docassemble/AssemblyLine/al_general.py

Co-authored-by: Bryce Willey <Bryce.Steven.Willey@gmail.com>

* Adjust comments per review + add docstring

* 🎨 Format Python code with psf/black

* Cleanup appearance of error action page, make technical information optional

* Split if statement for trace and history

Co-authored-by: Quinten Steenhuis <qsteenhuis@gmail.com>
Co-authored-by: nonprofittechy <nonprofittechy@users.noreply.github.com>
Co-authored-by: Bryce Willey <bryce.steven.willey@gmail.com>
Co-authored-by: BryceStevenWilley <BryceStevenWilley@users.noreply.github.com>
Co-authored-by: Quinten Steenhuis <qsteenhuis@suffolk.edu>
@nonprofittechy
Copy link
Member Author

There is a recipe for this now, albeit in a weird place: https://docassemble.org/docs/background.html#background_response_choices

@nonprofittechy nonprofittechy removed their assignment Aug 22, 2023
@nonprofittechy nonprofittechy changed the title Make address fields dynamic, based on the selected country for the address field Make address fields dynamic, based on the selected country for the address field, handle international addresses Oct 30, 2023
@BryceStevenWilley BryceStevenWilley self-assigned this Nov 1, 2023
@BryceStevenWilley
Copy link
Contributor

BryceStevenWilley commented Nov 2, 2023

Started working on this, got some initial experiments working in international_addresses.

Notes on what I still need to work on:

  • We should default to showing the full state/province name for countries that aren't the US. I don't think that the state codes from pycountry are commonly used in addresses. For example, in Mozambique, example addresses that I can find include the full state name: (this already exists as long_state. IMO it should be always on for countries that aren't the US, but that's a separate issue probably)
  • There's something wrong with the recipe, specifically with showifdef(..., prior=True) for objects / attributes. I have a patch, When prior=true, keep looking for old_user_dict jhpyle/docassemble#707, that still needs to be merged upstream.
  • Google Autocomplete doesn't work for the state select; I can't properly set breakpoints in docassemble's JS code, but from what I can tell, it won't work when it auto-completes an address from a different country, as the browser has to make the background call to the server to get the states for the new country, which happens after DA's code autocompletes the fields on the page. It might work when auto-completing something from the default / same country on the screen, but that's inconsistent as well, and needs the values of the state drop down to not be the state code (it needs to be the full name, sometimes Google's "short name" is actually just the long name).

@BryceStevenWilley
Copy link
Contributor

Worked on this some more today, updates in the comment above; I'm still a bit skeptical that the approach of the state dropdown for every country is the best UI, as fancy as it is. I'm leaning towards just making an optional text field state input for countries that aren't the US, which avoids the remaining two problems mentioned, and depending on the country, should be enough information. Google autocomplete should still fill in the state's name if present, and if it's not present, I'm not sure that it's necessary for a physical or mailing address, and would prefer to let users who know their country better than us fill it in.

BryceStevenWilley added a commit that referenced this issue Nov 24, 2023
Minor changes that address #281. More details in that issue, but I don't think it's possible to get the full state dropdown for each country without messing up Google autocomplete, so when the country is an input, we turn the state list into a text box (I tried swapping out a dropdown for just the US and text input for other countries, but Google autocomplete also has a problem with that).

Only other changes were to change the "State" label to "State / Province" when the country is an input, and a few comments / docs, for accuracy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants