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

Split out visual bylines #1555

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions archive/templates/archive/objects/article_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ <h3 class="o-article__headline">
<a href="{% pageurl article %}">{{ article.title|safe }}</a>
</h3>
<div class="o-article__byline">
<span class="o-article__author">By {{ article.get_authors_with_urls|safe }}</span>
<span class="o-article__author">{{article.authors_with_roles |safe }}</span>
<span> &nbsp;·&nbsp; </span>
<span class="o-article__published">{{ article.first_published_at|naturaltime }}</span>
<span class="o-article__published">{{ article.explicit_published_at|naturaltime }}</span>
</div>
</div>
{% if not hide_snippet %}
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
84 changes: 61 additions & 23 deletions authors/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.db import models
from django.db.models.query import QuerySet
from videos.models import VideoAuthorsOrderable
from django.db.models import Q
from django.utils.text import slugify
from django_extensions.db.fields import AutoSlugField
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from article.models import ArticlePage
from article.models import ArticlePage, ArticleAuthorsOrderable
from wagtail.admin.panels import (
# Panels
FieldPanel,
Expand Down Expand Up @@ -125,7 +127,7 @@ class AuthorPage(RoutablePageMixin, Page):



CHOICES = [("articles", "Articles"), ("photos", "Photos"), ("videos", "Videos")]
CHOICES = [("articles", "Articles"), ("photos", "Photos"), ("videos", "Videos"), ('visual-bylines', "Visual Bylines")]
main_media_type = models.CharField(
choices=CHOICES,
default='articles',
Expand Down Expand Up @@ -182,25 +184,34 @@ def organize_media(self, media_type, request, context):
search_query = request.GET.get("q")
page = request.GET.get("page")
order = request.GET.get("order")
if order == 'oldest':
article_order = ""
else:
article_order = "-"

if media_type == "photos":
if order == 'oldest':
article_order = "updated_at"
else:
article_order = "-updated_at"
authors_media = UbysseyImage.objects.filter(author=self).order_by(article_order)
authors_media = UbysseyImage.objects.filter(author=self).order_by(article_order+"updated_at")
elif media_type == "videos":
if order == 'oldest':
article_order = "updated_at"
else:
article_order = "-updated_at"
authors_media = VideoSnippet.objects.filter(video_authors__author=self).order_by(article_order)
authors_media = VideoSnippet.objects.filter(video_authors__author=self).order_by(article_order+"updated_at")
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_id in keys:
keys.append(a.article_page_id)
authors_media.append(a)
else:
if order == 'oldest':
article_order = "explicit_published_at"
else:
article_order = "-explicit_published_at"
authors_media = ArticlePage.objects.live().public().filter(article_authors__author=self).distinct().order_by(article_order)
# 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_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:
if media_type == "videos":
Expand All @@ -227,23 +238,32 @@ 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

def get_context(self, request, *args, **kwargs):
context = super().get_context(request, *args, **kwargs)
# For meta tags (see ubyssey.ca/ubyssey/templates/ubyssey/meta_tags.html)
context["self"].featured_media = self.image
context["self"].lede = self.bio_description

media_types = []
if VideoSnippet.objects.all().count() > 0:
media_types.append("videos")
if UbysseyImage.objects.all().count() > 0:
media_types.append("photos")
if ArticlePage.objects.live().public().all().count() > 0:
media_types.append("articles")

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
context["media_type_name"] = self.main_media_type.replace("-", " ")

order = request.GET.get("order")
if order == 'oldest':
Expand Down Expand Up @@ -332,11 +352,27 @@ def stories_page(self, request, *args, **kwargs):
context = self.get_context(request, *args, **kwargs)

context["media_type"] = "articles"
context["media_type_name"] = "articles"

context = self.organize_media("articles", request, context)

return render(request, self.template, context)

@route(r'^visual-bylines/$')
def visuals_page(self, request, *args, **kwargs):
"""
View function for author's stories
"""

context = self.get_context(request, *args, **kwargs)

context["media_type"] = "visual-bylines"
context["media_type_name"] = "visual bylines"

context = self.organize_media("visual-bylines", request, context)

return render(request, self.template, context)

@route(r'^photos/$')
def photos_page(self, request, *args, **kwargs):
"""
Expand All @@ -346,6 +382,7 @@ def photos_page(self, request, *args, **kwargs):
context = self.get_context(request, *args, **kwargs)

context["media_type"] = "photos"
context["media_type_name"] = "photos"

context = self.organize_media("photos", request, context)

Expand All @@ -360,6 +397,7 @@ def videos_page(self, request, *args, **kwargs):
context = self.get_context(request, *args, **kwargs)

context["media_type"] = "videos"
context["media_type_name"] = "videos"

context = self.organize_media("videos", request, context)

Expand Down
20 changes: 7 additions & 13 deletions authors/templates/authors/author_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,15 @@ <h2 class="author-heading">Pinned</h2>
{% endif %}

<div class="options">
{% if "articles" in media_types %}
<h2 class="author-heading {% if media_type == "articles" %}selected{% endif %}"><a href="/authors/{{self.slug}}/articles">Articles</a></h2>
{% endif %}
{% if "photos" in media_types %}
<h2 class="author-heading {% if media_type == "photos" %}selected{% endif %}"><a href="/authors/{{self.slug}}/photos">Photos</a></h2>
{% endif %}
{% if "videos" in media_types %}
<h2 class="author-heading {% if media_type == "videos" %}selected{% endif %}"><a href="/authors/{{self.slug}}/videos">Videos</a></h2>
{% endif %}
{% for type in media_types %}
<h2 class="author-heading {% if media_type == type.0 %}selected{% endif %}"><a href="/authors/{{self.slug}}/{{type.0}}/">{{type.1}}</a></h2>
{% endfor %}
</div>

<h2 class="author-heading">Latest {{media_type}} from {{self.title}}</h2>
{% if media_type == "articles" %}
{% include 'archive/objects/archive.html' with page_obj=paginated_articles %}
<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 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
4 changes: 4 additions & 0 deletions ubyssey/static_src/src/styles/components/_author-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@
}
}
.author-heading {
white-space: nowrap;
font-size: 1.2rem;
}
.options .author-heading {
text-transform: capitalize;
}
.options {
display: flex;
gap: 15px;
Expand Down
3 changes: 3 additions & 0 deletions ubyssey/static_src/src/styles/components/_section-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
@media($bp-smaller-than-phablet) {
display: block;
}
.o-archive__search__input {
width: 115px;
}
}

.c-section__button-label {
Expand Down
7 changes: 4 additions & 3 deletions ubyssey/static_src/src/styles/objects/_archive.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ $search-bar-height: 50px;
// Structure
position: relative;
margin-bottom: 1rem;
width:fit-content;
flex-grow: 1;
}

Expand All @@ -21,7 +20,7 @@ $search-bar-height: 50px;

.o-archive__search__input {
// Structure
width: 115px;
width: 180px;
padding-left: $search-bar-height;
padding-right: 1rem;
box-sizing: border-box;
Expand All @@ -30,6 +29,7 @@ $search-bar-height: 50px;
border: none;
border-bottom: 1px solid;
border-color: #ffffff00;
border-radius: 0;

// Background
background: none;
Expand All @@ -45,9 +45,10 @@ $search-bar-height: 50px;
&:focus {
border-color: var(--header_color);
outline: 0;
width:100%;
width:100% !important;
opacity: 1;
color: $color-accent-blue;
cursor: text;
}

&::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
Expand Down
Loading