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

1528 author gets listed twice when included for two roles #1532

46 changes: 41 additions & 5 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,11 +1040,21 @@ def format_author(article_author):
return article_author.author.full_name

if not authors_list:
authors = list(map(format_author, self.article_authors.all()))
else:
authors = list(map(format_author, authors_list))

authors_list = self.article_authors.all()

# Create a set to track unique author names and filter duplicates
seen_authors = set()
unique_authors = []

# Ensuring duplicate authors are not added to the author list
for article_author in authors_list:
author_name = article_author.author.id
if author_name not in seen_authors:
seen_authors.add(author_name)
unique_authors.append(article_author)

authors = list(map(format_author, unique_authors))

if not authors:
return ""
elif len(authors) == 1:
Expand Down Expand Up @@ -1075,7 +1085,33 @@ def get_authors_in_order(self):

return authors_list
authors_in_order = property(fget=get_authors_in_order)


def get_authors_in_order_for_author_cards(self):
AUTHOR_TYPES = ["org_role", "author", "photographer", "illustrator", "videographer"]
authors = self.article_authors.all()

authors_dict = {}

for author_type in AUTHOR_TYPES:
for author in authors:
author_id = author.author.id
author_role = author.author_role

if author_role == author_type:
if author_id not in authors_dict:
# Create the author dictionary containing author object and authors multiple roles
authors_dict[author_id] = {
'author': author,
'roles': [author_role]
}
else:
# If the author is already in the dict, just append the role
if author_role not in authors_dict[author_id]['roles']:
authors_dict[author_id]['roles'].append(author_role)

return authors_dict

authors_in_order_for_cards = property(fget=get_authors_in_order_for_author_cards)

def get_authors_with_roles(self) -> str:
"""Returns list of authors as a comma-separated string
Expand Down
4 changes: 2 additions & 2 deletions article/templates/article/article_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ <h1 class="o-headline o-headline--article">

{% include 'article/objects/share_bar.html' %}

{% for author in self.authors_in_order %}
{% include "article/objects/author_card.html" with author=author %}
{% for author_id, author_data in self.authors_in_order_for_cards.items %}
{% include "article/objects/author_card.html" with author=author_data.author author_roles=author_data.roles %}
{% endfor %}

{% endblock %}
Expand Down
23 changes: 12 additions & 11 deletions article/templates/article/objects/author_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
{% load wagtailimages_tags %}
{% load article_authors %}

<div class="author_card">
<div class="author_card">
<div class="author_title {% if author.author.image and author.author.display_image %}with_image{%endif%}">
{% if author.author.image and author.author.display_image %}
{% image author.author.image width-200 format-webp class="author_image" alt=author.author.full_name %}
{% endif %}
{% if author.author.image and author.author.display_image %}
{% image author.author.image width-200 format-webp class="author_image" alt=author.author.full_name %}
{% endif %}
<p>
<span class="author_name">
<a href="{{ author.author.full_url }}"> {{ author.author.full_name|safe }}</a>
</span>
<span class="author_role">
{% if author.author_role == "org_role" %}
{{author.author.ubyssey_role}}
{% else %}
{{author.author_role}}
{% endif %}
{% for role in author_roles %}
{% if role == "org_role" %}
{{ author.author.ubyssey_role }}{% if not forloop.last %},{% endif %}
{% else %}
{{ role }}{% if not forloop.last %},{% endif %}
{% endif %}
{% endfor %}
</span>
</p>
</div>
<!-- if forloop.first and no image then 0 padding for the authors_info left, author_info and author title-->
<div class="author_info">
{% if author.author.short_bio_description != "" %}
<p>{{ author.author.short_bio_description }}</p>
{% endif %}
<li><a href="{{ author.author.full_url }}">See more from {{ author.author.full_name|safe }}</a></li>
</div>
</div>
</div>
Loading