mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 08:28:15 -04:00
add tests for formatted_list
This commit is contained in:
@@ -347,24 +347,29 @@ def format_notification_status_as_url(status):
|
||||
|
||||
|
||||
def formatted_list(
|
||||
items,
|
||||
conjunction='and',
|
||||
before_each='‘',
|
||||
after_each='’',
|
||||
separator=', ',
|
||||
prefix='',
|
||||
prefix_plural=''
|
||||
items,
|
||||
conjunction='and',
|
||||
before_each='‘',
|
||||
after_each='’',
|
||||
separator=', ',
|
||||
prefix='',
|
||||
prefix_plural=''
|
||||
):
|
||||
if prefix:
|
||||
prefix += ' '
|
||||
if prefix_plural:
|
||||
prefix_plural += ' '
|
||||
|
||||
items = list(items)
|
||||
if len(items) == 1:
|
||||
return '{prefix} {before_each}{items[0]}{after_each}'.format(**locals())
|
||||
return '{prefix}{before_each}{items[0]}{after_each}'.format(**locals())
|
||||
elif items:
|
||||
formatted_items = ['{}{}{}'.format(before_each, item, after_each) for item in items]
|
||||
|
||||
first_items = separator.join(formatted_items[:-1])
|
||||
last_item = formatted_items[-1]
|
||||
return (
|
||||
'{prefix_plural} {first_items} {conjunction} {last_item}'
|
||||
'{prefix_plural}{first_items} {conjunction} {last_item}'
|
||||
).format(**locals())
|
||||
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@
|
||||
</h1>
|
||||
<p>
|
||||
Your file has {{ recipients.column_headers | formatted_list(
|
||||
prefix='one column, called',
|
||||
prefix_plural='columns called'
|
||||
prefix='one column, called ',
|
||||
prefix_plural='columns called '
|
||||
) }}.
|
||||
</p>
|
||||
{{ skip_to_file_contents() }}
|
||||
@@ -65,15 +65,15 @@
|
||||
</h1>
|
||||
<p>
|
||||
Your file has {{ recipients.column_headers | formatted_list(
|
||||
prefix='one column, called',
|
||||
prefix_plural='columns called'
|
||||
prefix='one column, called ',
|
||||
prefix_plural='columns called '
|
||||
) }}.
|
||||
</p>
|
||||
<p>
|
||||
It doesn’t have {{ recipients.column_headers | formatted_list(
|
||||
conjunction='or',
|
||||
prefix='a column called',
|
||||
prefix_plural='columns called'
|
||||
prefix='a column called ',
|
||||
prefix_plural='columns called '
|
||||
) }}.
|
||||
</p>
|
||||
{{ skip_to_file_contents() }}
|
||||
|
||||
Reference in New Issue
Block a user