Skip to content

Commit

Permalink
Merge pull request #80 from SuffolkLITLab/nice_county_name
Browse files Browse the repository at this point in the history
Add nice_county_name method
  • Loading branch information
nonprofittechy authored Jul 14, 2022
2 parents f074c7d + 7b928a8 commit 7f1c623
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
29 changes: 29 additions & 0 deletions docassemble/ALToolbox/data/questions/nice_county_name_demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
metadata:
Title: Nice county name demo
---
modules:
- .misc
---
objects:
- address: Address
---
mandatory: True
code: |
address.county
print_county
---
question: |
Address
subquestion: |
`nice_county_name`: If the county name contains the word "County", which Google Address Autocomplete does by default, remove it.
fields:
- Address: address.address
address autocomplete: True
- County: address.county
---
event: print_county
question: |
County
subquestion: |
${ nice_county_name( address ) }
---
22 changes: 21 additions & 1 deletion docassemble/ALToolbox/misc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import docassemble.base.functions
from docassemble.base.util import defined, value, showifdef, space_to_underscore
from docassemble.base.util import (
defined,
value,
showifdef,
space_to_underscore,
Address,
)
import re

__all__ = [
Expand All @@ -15,6 +21,7 @@
"sum_if_defined",
"add_records",
"output_checkbox",
"nice_county_name",
]


Expand Down Expand Up @@ -201,3 +208,16 @@ def output_checkbox(
return checked_value
else:
return unchecked_value


def nice_county_name(address: Address) -> str:
"""
If the county name contains the word "County", which Google Address
Autocomplete does by default, remove it.
"""
if not hasattr(address, "county"):
return ""
if address.county.endswith(" County"):
return address.county[: -len(" County")]
else:
return address.county

0 comments on commit 7f1c623

Please sign in to comment.