Skip to content

Commit

Permalink
Merge pull request #758 from SuffolkLITLab/name-and-contact-fields
Browse files Browse the repository at this point in the history
Minor enhancements to contact fields, name field
  • Loading branch information
nonprofittechy authored Sep 14, 2023
2 parents 08b22f7 + 4d35464 commit b4488d4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
49 changes: 45 additions & 4 deletions docassemble/AssemblyLine/al_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,15 +843,17 @@ def contact_methods(self) -> str:
"""
methods = []
if self.phone_numbers():
methods.append({self.phone_numbers(): word("by phone at ")})
methods.append({self.phone_numbers(): str(self.phone_number_contact_label)})
if hasattr(self, "email") and self.email:
methods.append({self.email: word("by email at ")})
methods.append({self.email: str(self.email_contact_label)})
if hasattr(self, "other_contact_method") and self.other_contact_method:
methods.append({self.other_contact_method: "by "})
methods.append(
{self.other_contact_method: str(self.other_contact_method_label)}
)

return comma_and_list(
[
list(method.values())[0] + list(method.keys())[0]
list(method.values())[0] + " " + list(method.keys())[0]
for method in methods
if len(method)
],
Expand Down Expand Up @@ -900,6 +902,8 @@ def name_fields(
self,
person_or_business: str = "person",
show_suffix: bool = True,
show_title: bool = False,
title_options: Optional[List[str]] = None,
show_if: Union[str, Dict[str, str], None] = None,
) -> List[Dict[str, str]]:
"""
Expand All @@ -911,6 +915,10 @@ def name_fields(
Default is "person".
show_suffix (bool, optional): Determines if the name's suffix (e.g., Jr., Sr.) should be included in the prompts.
Default is True.
show_title: (bool, optional): Determines if the name's title (e.g., Mr., Ms.) should be included in the prompts.
Default is False.
title_options (List[str], optional): A list of title options to use in the prompts. Default is defined as a list
of common titles in English-speaking countries.
show_if (Union[str, Dict[str, str], None], optional): Condition to determine which fields to show.
It can be a string, a dictionary with conditions, or None. Default is None.
Expand All @@ -921,6 +929,29 @@ def name_fields(
If `person_or_business` is set to None, the method will offer the end user a choice
and will set appropriate "show ifs" conditions for each type.
"""
if not title_options:
title_options = [
"Mr.",
"Mrs.",
"Miss",
"Ms.",
"Mx.",
"Dr.",
"Prof.",
"Hon.",
"Rev.",
"Sir",
"Lord",
"Lady",
"Dame",
"Maj.",
"Gen.",
"Capt.",
"Lt.",
"Sgt.",
"Fr.",
"Sr.",
]
if person_or_business == "person":
fields = [
{
Expand All @@ -946,6 +977,16 @@ def name_fields(
"required": False,
}
)
if show_title:
fields.insert(
0,
{
"label": str(self.name_title_label),
"field": self.attr_name("name.title"),
"choices": title_options,
"required": False,
},
)
if show_if:
for field in fields:
field["show if"] = show_if
Expand Down
26 changes: 24 additions & 2 deletions docassemble/AssemblyLine/data/questions/ql_baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ code: |
# This helps us keep questions consistent and translated just once
---
generic object: ALIndividual
template: x.name_title_label
content: |
Title (optional)
---
generic object: ALIndividual
template: x.first_name_label
content: |
First name
Expand Down Expand Up @@ -462,7 +467,7 @@ fields:
choices:
- users[0].address if defined("users[0].address.address") else None
object labeler: |
lambda y: y.on_one_line()
lambda y: y.on_one_line()
none of the above: |
Somewhere else
disable others: True
Expand Down Expand Up @@ -2309,4 +2314,21 @@ content: |
generic object: ALIndividual
template: x.pronoun_self_described_label
content: |
Self described pronouns
Self described pronouns
---
############# Contact method strings ################
---
generic object: ALIndividual
template: x.phone_number_contact_label
content: >-
by phone at
---
generic object: ALIndividual
template: x.email_contact_label
content: >-
by email at
---
generic object: ALIndividual
template: x.other_contact_method_label
content: >-
by

0 comments on commit b4488d4

Please sign in to comment.