Skip to content

Commit

Permalink
Merge pull request #8478 from cfpb/fix-authors
Browse files Browse the repository at this point in the history
Fix index bug in author sorting method and display bug in item introduction
  • Loading branch information
wpears committed Jun 15, 2024
2 parents 48562da + 01fff6d commit 7cebc54
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cfgov/v1/jinja2/v1/includes/organisms/item-introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
value.show_category: Whether to show the category or not.
value.heading: Heading text.
value.paragraph.source: Body introduction text.
value.authors: Array of author names and associated URLs.
value.authors: Array of author names

value.date: A datetime for the post.
value.has_social: Whether to show the share icons or not.
Expand Down Expand Up @@ -59,7 +59,7 @@ <h1>{{ value.heading | safe }}</h1>
<span class="byline">
{%- for author in page.get_authors() -%}
{% if loop.first %}By {% elif loop.last %}and {% endif %}
{{ author.name }}
{{ author }}
{%- if loop.length > 2 and loop.index < loop.length %}, {% endif %}
{% endfor %}
&ndash;
Expand Down
2 changes: 1 addition & 1 deletion cfgov/v1/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def get_authors(self):

def sorting(name):
parts = name.rsplit(" ", 1)
return parts[1], parts[0]
return parts[0] if len(parts) == 1 else parts[1], parts[0]

return sorted(
[author.name for author in self.authors.all()], key=sorting
Expand Down
5 changes: 5 additions & 0 deletions cfgov/v1/tests/models/test_author_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def check_authors(self, authors, expected):
page.authors.add(*authors)
self.assertEqual(page.get_authors(), expected)

def test_author_names_with_no_space(self):
self.check_authors(
["Wyatt Pearsall", "CFPB"], ["CFPB", "Wyatt Pearsall"]
)

def test_alphabetize_authors_by_last_name(self):
self.check_authors(
["Ross Karchner", "Richa Agarwal", "Andy Chosak", "Will Barton"],
Expand Down

0 comments on commit 7cebc54

Please sign in to comment.