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

Shorter way to specify name.full(middle='full') #834

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docassemble/AssemblyLine/al_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,36 @@ def pronoun_subjective(self, **kwargs) -> str:
return capitalize(output)
return output

def name_full(self) -> str:
"""Returns the individual's full name.

Returns:
str: The individual's full name.
"""
return self.name.full(middle="full")

def name_initials(self) -> str:
"""
Returns the individual's name with the middle name as an initial.
Equivalent to `name.full(middle="initial")`, which is also the default.
Defined only to make it possible to be explicit about the name form.

Returns:
str: The individual's name with the middle name as an initial.
"""
return self.name.full(middle="initial")

def name_short(self) -> str:
"""
Returns the individual's name without any middle name.

Equivalent to self.name.firstlast()

Returns:
str: The individual'
"""
return self.name.firstlast()


# (DANav isn't in public DA API, but currently in functions.py)
def section_links(nav) -> List[str]: # type: ignore
Expand Down
9 changes: 9 additions & 0 deletions docassemble/AssemblyLine/test_al_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,15 @@ def test_custom_pronouns(self):
with self.assertRaises(DAAttributeError):
self.individual.pronoun_objective()

def test_name_methods(self):
self.individual.name.first = "John"
self.individual.name.middle = "Jacob"
self.individual.name.last = "Jingleheimer"

self.assertEqual(self.individual.name_full(), "John Jacob Jingleheimer")
self.assertEqual(self.individual.name_initials(), "John J. Jingleheimer")
self.assertEqual(self.individual.name_short(), "John Jingleheimer")


class test_get_visible_al_nav_items(unittest.TestCase):
def test_case_1(self):
Expand Down
Loading