Skip to content

Commit

Permalink
New author string option (get_authors_split_out_visual_bylines) that …
Browse files Browse the repository at this point in the history
…separates out visuals roles if there is a visuals only author. Remove duplicate articles from author page
  • Loading branch information
SamuelmdLow committed Oct 22, 2024
1 parent 5d65ab7 commit f1cb635
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 14 deletions.
6 changes: 5 additions & 1 deletion archive/templates/archive/objects/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ <h3 class="o-archive__header__title">
<div class="o-archive__main__list">
{% for object in page_obj %}
{% if video_section == False or video_section == None %}
{% include 'archive/objects/article_list.html' with article=object %}
{% if is_orderable %}
{% include 'archive/objects/article_list.html' with article=object.article_page %}
{% else %}
{% include 'archive/objects/article_list.html' with article=object %}
{% endif %}
{% else %}
{% include 'videos/stream_blocks/video.html' with video=object %}
{% endif %}
Expand Down
46 changes: 45 additions & 1 deletion article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dbtemplates.models import Template as DBTemplate

from django.db import models
from django.db.models import fields
from django.db.models import fields, Q
from django.db.models.fields import CharField
from django.shortcuts import render
from django.db.models.query import QuerySet
Expand Down Expand Up @@ -1150,6 +1150,50 @@ def get_authors_with_roles(self) -> str:
return ', '.join(map(lambda a: a[1], authors_with_roles))
authors_with_roles = property(fget=get_authors_with_roles)

def get_authors_split_out_visual_bylines(self) -> str:
"""Returns list of authors as a comma-separated string
sorted by author type (with 'and' before last author)."""

role_types_words = {
'author': 'Words by ',
'photographer': 'Photos by ',
'illustrator': 'Illustrations by ',
'videographer': 'Videos by ',
'designer': 'Design by ',
}
role_types = ['author', 'photographer', 'illustrator', 'videographer', 'designer', 'org_role']
writers = []
visuals = []
word_authors = []
visual_authors = []
for k, v in groupby(self.article_authors.all(), lambda a: a.author_role):
v = list(v)
if k=='org_role' or k=='author':
for author in v:
word_authors.append(author.author)
writers = writers + v
else:
for author in v:
visual_authors.append(author.author)
visuals.append([k, role_types_words[k] + self.get_authors_string(links=True, authors_list=v)])
visuals.sort(key=lambda s: role_types.index(s[0]))

visual_only_author = False
for visual_author in visual_authors:
if not visual_author in word_authors:
visual_only_author = True
break

writers = self.get_authors_string(links=True, authors_list=list(writers))

if len(visuals) > 0 and visual_only_author:
visuals = ', ' + ', '.join(map(lambda a: a[1], visuals))
else:
visuals = ''

return writers + visuals
authors_split_out_visual_bylines = property(fget=get_authors_split_out_visual_bylines)

def get_category_articles(self, order='-first_published_at') -> QuerySet:
"""
Returns a list of articles within the Article's category
Expand Down
2 changes: 1 addition & 1 deletion article/templates/article/objects/cover_story.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="o-article__meta">
<p class="o-article__snippet">{% if article.lede %}{{article.lede|safe}}{% else %}{{article.search_description|safe}}{% endif %}</p>
<div class="o-article__byline">
<span class="o-article__author">{% if article.get_authors_with_urls %}{{article.get_authors_with_urls|safe }}{% else %}Ubyssey Staff{% endif %}</span>
<span class="o-article__author">{% if article.get_authors_split_out_visual_bylines %}{{article.authors_split_out_visual_bylines |safe }}{% else %}Ubyssey Staff{% endif %}</span>
<span> &nbsp;&nbsp; </span>
<a href="{{article|get_section_link}}" class="o-article__section-tag" style="background-color: {{article|get_colour}}">{{article|get_section_title}}</a>
<span> &nbsp;&nbsp; </span>
Expand Down
2 changes: 1 addition & 1 deletion article/templates/article/objects/infinitefeed_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h2 class="o-article__headline">
</h2>
<p class="o-article__snippet">{{ article.lede|safe }}</p>
<p class="o-article__byline">
<span class="o-article__author">{{ article.get_authors_with_urls|safe }}</span>
<span class="o-article__author">{{ article.get_authors_split_out_visual_bylines|safe }}</span>
<span> &nbsp;&nbsp; </span>
<span class="o-article__published">{{ article.explicit_published_at|display_pubdate }}</span>
</p>
Expand Down
2 changes: 1 addition & 1 deletion article/templates/article/objects/top_article.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h2 class="o-article__headline">
<a href="{% pageurl article %}">{{ article.title|safe }}</a>
</h2>
<div class="o-article__byline">
<span class="o-article__author">{{ article.get_authors_with_urls|safe }}</span>
<span class="o-article__author">{{ article.get_authors_split_out_visual_bylines|safe }}</span>
<span> &nbsp;&nbsp; </span>
<span class="o-article__published">{{ article.explicit_published_at|display_pubdate }}</span>
</div>
Expand Down
22 changes: 14 additions & 8 deletions authors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,21 @@ def organize_media(self, media_type, request, context):
elif media_type == "visual-bylines":
# Get articles where this author is credited with something other than "author" and "org_role"
authors_media = []
keys = []
for a in ArticleAuthorsOrderable.objects.filter(author=self).exclude(Q(author_role="author") | Q(author_role="org_role")).order_by(article_order+'article_page__explicit_published_at'):
# we gotta do this because I can't use .distinct() on a field with mysql. We have to move to postgres for that (sounds like a lot of work) - samlow 21/10/2024
if not a.article_page in authors_media:
authors_media.append(a.article_page)
if not a.article_page_id in keys:
keys.append(a.article_page_id)
authors_media.append(a)
else:
# Get articles where this author is creditted with either "author" or "org_role"
authors_media = []
keys = []
for a in ArticleAuthorsOrderable.objects.filter(Q(author=self, author_role="author") | Q(author=self, author_role="org_role")).order_by(article_order+'article_page__explicit_published_at'):
# same here, can't use .distinct() cause not using postgres - samlow 21/10/2024
if not a.article_page in authors_media:
authors_media.append(a.article_page)
if not a.article_page_id in keys:
keys.append(a.article_page_id)
authors_media.append(a)
#authors_media = ArticlePage.objects.live().public().filter(article_authors__author=self).distinct().order_by(article_order)

if search_query:
Expand Down Expand Up @@ -234,6 +238,8 @@ def organize_media(self, media_type, request, context):
paginated_articles = paginator.page(paginator.num_pages)
context["current_page"] = paginator.num_pages

if media_type == "visual-bylines" or "articles":
context['is_orderable'] = True
context["paginated_articles"] = paginated_articles

return context
Expand All @@ -246,14 +252,14 @@ def get_context(self, request, *args, **kwargs):

media_types = []

if VideoAuthorsOrderable.objects.filter(author=self).exists():
media_types.append(("videos", "videos"))
if UbysseyImage.objects.filter(author=self).exists():
media_types.append(("photos", "photos"))
if ArticleAuthorsOrderable.objects.filter(author=self, author_role="author").exists():
media_types.append(("articles", "articles"))
if ArticleAuthorsOrderable.objects.filter(author=self).exclude(author_role="author").exists():
media_types.append(("visual-bylines", "visual bylines"))
if UbysseyImage.objects.filter(author=self).exists():
media_types.append(("photos", "photos"))
if VideoAuthorsOrderable.objects.filter(author=self).exists():
media_types.append(("videos", "videos"))

context["media_types"] = media_types
context["media_type"] = self.main_media_type
Expand Down
2 changes: 1 addition & 1 deletion authors/templates/authors/author_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h2 class="author-heading {% if media_type == type.0 %}selected{% endif %}"><a h
<h2 class="author-heading">Latest {{media_type_name}} from {{self.title}}</h2>

{% if media_type == "articles" or media_type == "visual-bylines" %}
{% include 'archive/objects/archive.html' with page_obj=paginated_articles %}
{% include 'archive/objects/archive.html' with page_obj=paginated_articles current_page_articles=current_page_articles %}
{% elif media_type == "photos" %}
{% include 'archive/objects/gallery.html' with page_obj=paginated_articles %}
{% elif media_type == "videos" %}
Expand Down

0 comments on commit f1cb635

Please sign in to comment.