Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/ubyssey/ubyssey.ca into …
Browse files Browse the repository at this point in the history
…month-toggle-redo-merges
  • Loading branch information
SamuelmdLow committed Nov 14, 2024
2 parents dda87e4 + a25b8a2 commit eac6f2a
Show file tree
Hide file tree
Showing 92 changed files with 2,190 additions and 726 deletions.
6 changes: 3 additions & 3 deletions archive/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ def get_paginated_articles(self, context, objects, video_section, request):
def get_order_objects(self, order, objects, videos_section):
if videos_section == False:
if order == 'oldest':
article_order = "explicit_published_at"
article_order = "first_published_at"
else:
article_order = "-explicit_published_at"
article_order = "-first_published_at"

return objects.order_by(article_order)
else:
Expand All @@ -211,7 +211,7 @@ def get_order_objects(self, order, objects, videos_section):

def get_year_objects(self, objects, videos_section):
if videos_section == False:
return objects.filter(explicit_published_at__year=str(self.year))
return objects.filter(first_published_at__year=str(self.year))
else:
return objects.filter(created_at__gte=str(self.year) + "-01-01", created_at__lte = str(self.year + 1) + "-12-31")

Expand Down
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
22 changes: 11 additions & 11 deletions archive/templates/archive/objects/archive_filter.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ <h2>Spoofs <a href="#" class="filterDropdown"><ion-icon name="caret-down-outline
<div class="o-archive__dropdown-filters">

{% if years %}
<div class="o-mobile-dropdown open-modal">
<div class="o-mobile-dropdown setup-modal">

<a class="o-mobile-dropdown__button" href="#">
<a class="o-mobile-dropdown__button open-modal" href="#">
<span>{% if year %}{{ year }}{% else %}All years{% endif %}</span>
<ion-icon name="caret-down-outline"></ion-icon>
</a>

<div class="add-to-modal o-mobile-dropdown__list">
<div class="js-dropdown-container"></div>
<dialog class="modal o-mobile-dropdown__list" aria-modal="true">
<div class="js-dropdown-container close-modal"></div>
<div class="o-mobile-dropdown__list__container">
<div class="o-mobile-dropdown__header">
<h2 class="o-mobile-dropdown__title">Filter by year:</h3>
Expand All @@ -141,21 +141,21 @@ <h2 class="o-mobile-dropdown__title">Filter by year:</h3>
{% endfor %}
</ul>
</div>
</div>
</dialog>

</div>
{% endif %}

{% if sections %}
<div class="o-mobile-dropdown open-modal">
<div class="o-mobile-dropdown setup-modal">

<a class="o-mobile-dropdown__button" href="#">
<a class="o-mobile-dropdown__button open-modal" href="#">
<span>{% if section_slug %}{{ section_slug }}{% else %}All sections{% endif %}</span>
<ion-icon name="caret-down-outline"></ion-icon>
</a>

<div class="add-to-modal o-mobile-dropdown__list">
<div class="js-dropdown-container"></div>
<dialog class="modal o-mobile-dropdown__list" aria-modal="true">
<div class="js-dropdown-container close-modal"></div>
<div class="o-mobile-dropdown__list__container">
<div class="o-mobile-dropdown__header">
<h2 class="o-mobile-dropdown__title">Filter by section:</h3>
Expand Down Expand Up @@ -200,7 +200,7 @@ <h2 class="o-mobile-dropdown__title">Filter by section:</h3>
{% endfor %}
</ul>
</div>
</div>
</dialog>
</div>
{% endif %}
</div>
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
6 changes: 3 additions & 3 deletions archive/templates/archive/objects/gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ <h3 class="o-archive__header__title">
{% if page_obj %} {{ page_obj.paginator.count }} RESULTS {% else %}NO RESULTS{% endif %}
{% if q %} FOR "{{ q }}"{% endif %}
</h3>
<div class="o-archive__header__sort o-dropdown js-dropdown">
<a class="o-button o-dropdown__button">
<div class="o-archive__header__sort o-dropdown">
<a class="o-button o-dropdown__button preventDefault" href="#">
<span>{{ order|title }}</span>
<ion-icon name="caret-down-outline"></ion-icon>
</a>
<ul class="o-dropdown__list js-dropdown-list">
<ul class="o-dropdown__list">
<li class="o-dropdown__item{% if order == 'newest' %} o-dropdown__item--is-active{% endif %}">
<a href="?{% modify_query_string 'order' 'newest' %}">Newest</a>
</li>
Expand Down
31 changes: 28 additions & 3 deletions article/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,41 @@

class AudioBlock(blocks.StructBlock):
caption = blocks.CharBlock(required=False)
audio = DocumentChooserBlock(required=True, help_text="Must be mp3 format")

audio = DocumentChooserBlock(required=True, help_text="File format: .m4a, .mp4, .mp, .wav, or .ogg")

def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context)
if value['audio'].url[-4:] == '.wav':
context['self'].format = 'wav'
if value['audio'].url[-4:] == '.mp3':
context['self'].format = 'mpeg'
if value['audio'].url[-4:] == '.ogg':
context['self'].format = 'ogg'
else:
context['self'].format = 'mp4'
return context

class Meta:
template = 'article/stream_blocks/audio.html',
icon = "media"

class PullQuoteBlock(blocks.StructBlock):
content = blocks.CharBlock(required=True)
source = blocks.CharBlock(required=False)
audio = DocumentChooserBlock(required=False, help_text="optional, must be mp3 format")
audio = DocumentChooserBlock(required=False, help_text="Optional, file format: .m4a, .mp4, .mp, .wav, or .ogg")

def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context)
if value['audio']:
if value['audio'].url[-4:] == '.wav':
context['self'].format = 'wav'
if value['audio'].url[-4:] == '.mp3':
context['self'].format = 'mpeg'
if value['audio'].url[-4:] == '.ogg':
context['self'].format = 'ogg'
else:
context['self'].format = 'mp4'
return context

class Meta:
template = 'article/stream_blocks/quote.html',
Expand Down
110 changes: 76 additions & 34 deletions 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 @@ -168,6 +168,7 @@ class ArticleAuthorsOrderable(Orderable):
('illustrator','Illustrator'),
('photographer','Photographer'),
('videographer','Videographer'),
('designer','Designer'),
('org_role', 'Show organization role'),
],
),
Expand Down Expand Up @@ -479,7 +480,7 @@ class ArticlePage(RoutablePageMixin, SectionablePage, UbysseyMenuMixin):
('dropcap', blocks.TextBlock(
label = "Dropcap Block",
template = 'article/stream_blocks/dropcap.html',
help_text = "DO NOT USE - Legacy block. Create a block where special dropcap styling with be applied to the first letter and the first letter only.\n\nThe contents of this block will be enclosed in a <p class=\"drop-cap\">...</p> element, allowing its targetting for styling.\n\nNo RichText allowed."
help_text = "Create a block where special dropcap styling with be applied to the first letter and the first letter only.\n\nThe contents of this block will be enclosed in a <p class=\"drop-cap\">...</p> element, allowing its targetting for styling.\n\nNo RichText allowed."
)),
('video', video_blocks.OneOffVideoBlock(
label = "Credited/Captioned One-Off Video",
Expand Down Expand Up @@ -545,7 +546,7 @@ class ArticlePage(RoutablePageMixin, SectionablePage, UbysseyMenuMixin):
blank=True,
default='',
max_length=255,
help_text="Enter the slug of the tag to be used for linking at the end of the article. For example, the slug of the tag 'blue chip' is 'blue-chip'.",
help_text="IF USED, SHOULD ALSO BE IN TAGS FIELD. Enter the slug of the tag to be used for linking at the end of the article. For example, the slug of the tag 'blue chip' is 'blue-chip'.",
)
tag_page_link = models.BooleanField(
null=False,
Expand Down Expand Up @@ -743,6 +744,8 @@ def get_template(self, request):
return "article/article_page_spoof_2024.html"
elif self.layout == 'guide-2024':
return "article/article_page_guide_2024.html"
elif self.layout == 'science-2024':
return "article/article_page_supplement_2024_science.html"

return "article/article_page.html"

Expand Down Expand Up @@ -873,6 +876,7 @@ def get_template(self, request):
('magazine-2024', 'Magazine (2024 style)'),
('spoof-2024', 'Spoof (2024 style)'),
('guide-2024', 'Guide (2024 style)'),
('science-2024', 'Science Supplement (2024)'),
],
),
),
Expand Down Expand Up @@ -1131,51 +1135,89 @@ def get_authors_with_roles(self) -> str:
"""Returns list of authors as a comma-separated string
sorted by author type (with 'and' before last author)."""

string_written = ''
string_photos = ''
string_illustrations = ''
string_videos = ''
string_org = ''

authors = dict((k, list(v)) for k, v in groupby(self.article_authors.all(), lambda a: a.author_role))
for author in authors:
if author == 'author':
string_written += 'Words by ' + self.get_authors_string(links=True, authors_list=authors['author'])
if author == 'photographer':
string_photos += 'Photos by ' + self.get_authors_string(links=True, authors_list=authors['photographer'])
if author == 'illustrator':
string_illustrations += 'Illustrations by ' + self.get_authors_string(links=True, authors_list=authors['illustrator'])
if author == 'videographer':
string_videos += 'Videos by ' + self.get_authors_string(links=True, authors_list=authors['videographer'])
if author == 'org_role':
string_org = ",".join( map(lambda a: ' ' + a.author.ubyssey_role + ": " + self.get_authors_string(links=True, authors_list=[a]) , authors['org_role']))


authors_with_roles = filter(lambda a: a != '', [string_written, string_photos, string_illustrations, string_videos, string_org])
return ', '.join(authors_with_roles)
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']
authors_with_roles = []
for k, v in groupby(self.article_authors.all(), lambda a: a.author_role):
if k=='org_role':
authors_with_roles.append([k, ",".join( map(lambda a: ' ' + a.author.ubyssey_role + ": " + self.get_authors_string(links=True, authors_list=[a]) , list(v)))])
else:
authors_with_roles.append([k, role_types_words[k] + self.get_authors_string(links=True, authors_list=list(v))])
authors_with_roles.sort(key=lambda s: role_types.index(s[0]))
return ', '.join(map(lambda a: a[1], authors_with_roles))
authors_with_roles = property(fget=get_authors_with_roles)

def get_category_articles(self, order='-first_published_at') -> QuerySet:
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', max=10) -> QuerySet:
"""
Returns a list of articles within the Article's category
"""
category_articles = ArticlePage.objects.live().filter(category=self.category).not_page(self).order_by(order)
category_articles = ArticlePage.objects.live().filter(category=self.category).not_page(self).order_by(order)[:max]

return category_articles

def get_section_articles(self, order='-first_published_at') -> QuerySet:
def get_section_articles(self, order='-first_published_at', max=10) -> QuerySet:
"""
Returns a list of articles within the Article's section
"""

section_articles = ArticlePage.objects.live().child_of(self.get_parent()).not_page(self).order_by(order)
section_articles = ArticlePage.objects.live().child_of(self.get_parent()).not_page(self).order_by(order)[:max]

return section_articles
def get_articles_by_tag(self, order='-first_published_at') -> QuerySet:
def get_articles_by_tag(self, order='-first_published_at', max=10) -> QuerySet:
"""
Returns a list of articles with the same tags as the current article
"""
articles_by_tag = ArticlePage.objects.live().filter(tags__slug=self.primary_tag_slug).not_page(self).order_by(order)
articles_by_tag = ArticlePage.objects.live().filter(tags__slug=self.primary_tag_slug).not_page(self).order_by(order)[:max]
return articles_by_tag

def get_suggested(self, number_suggested=3):
Expand All @@ -1185,7 +1227,7 @@ def get_suggested(self, number_suggested=3):
from taggit.models import Tag
suggested = {}
if self.filter_by_tags:
articles_by_tag = self.get_articles_by_tag()
articles_by_tag = self.get_articles_by_tag(max=number_suggested)
if len(articles_by_tag) > 0:
tag = Tag.objects.get(slug=self.primary_tag_slug)
suggested = {}
Expand All @@ -1194,15 +1236,15 @@ def get_suggested(self, number_suggested=3):
suggested['link'] = "/tag/" + tag.slug
if not suggested:
if self.category != None:
category_articles = self.get_category_articles()
category_articles = self.get_category_articles(max=number_suggested)
if len(category_articles) > 0:
suggested = {}
suggested['title'] = self.category.title
suggested['articles'] = category_articles[:number_suggested]
suggested['link'] = self.category.section_page.url + "category/" + self.category.slug

if not suggested:
section_articles = self.get_section_articles()
section_articles = self.get_section_articles(max=number_suggested)
if len(section_articles) > 0:
suggested = {}
suggested['title'] = self.get_parent().title
Expand Down
Loading

0 comments on commit eac6f2a

Please sign in to comment.