Skip to content

Commit

Permalink
Remove author_item and use author instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbiggs committed Aug 15, 2023
1 parent ce17d21 commit 3cb6c8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
27 changes: 8 additions & 19 deletions etna/authors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,21 @@ def get_authors_inlinepanel(cls, max_num=1):
return InlinePanel(
"author_tags",
heading="Page author",
help_text="Select the author for this page.",
help_text="Select the author of this page.",
max_num=max_num,
)

@cached_property
def authors(self):
return tuple(
item.author
for item in self.author_tags.select_related("author").filter(
author__live=True
)
)

@cached_property
def author_item(self):
try:
return self.authors[0]
except IndexError:
return None
def author(self):
if author_item := self.author_tags.select_related("author").filter(author__live=True):
return author_item[0].author
return None

@property
def author_name(self):
"""
Returns the title of the author to be used for indexing
"""
if self.author_item:
return self.author_item.title
else:
return None
if self.author:
return self.author.title
return None
10 changes: 5 additions & 5 deletions templates/articles/focused_article_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="generic-intro__meta">
<ul class="generic-intro__meta-list container">
{% if page.author_name %}
<li class="generic-intro__meta-item">By <a href="{% pageurl page.author_item %}">{{ page.author_name }}</a></li>
<li class="generic-intro__meta-item">By <a href="{% pageurl page.author %}">{{ page.author_name }}</a></li>
{% endif %}
</ul>
</div>
Expand Down Expand Up @@ -47,14 +47,14 @@
<div class="author-info">
<div class="author-info__label row">About the author</div>
<div class="author-info__image row">
{% image page.author_item.image fill-500x500 as author_img %}
{% image page.author.image fill-500x500 as author_img %}
<img src="{{ author_img.url }}" alt="{{ author_img.alt }}" class="author-info__image">
</div>
<div class="author-info__text row">
<h2 class="author-info__title"><a href="{% pageurl page.author_item %}">{{ page.author_name }}</a></h2>
{% if page.author_item.role %}
<h2 class="author-info__title"><a href="{% pageurl page.author %}">{{ page.author_name }}</a></h2>
{% if page.author.role %}
<div class="author-info__paragraph">
{{ page.author_item.role|richtext }}
{{ page.author.role|richtext }}
</div>
{% endif %}
</div>
Expand Down

0 comments on commit 3cb6c8d

Please sign in to comment.