Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
792aa26
feat: Enhance article templates and optimize database queries for tag…
brylie Aug 31, 2025
75fe738
fix: Ensure all tagged page queries include live and public filters
brylie Aug 31, 2025
d538c58
fix: Improve publication date display format in magazine issue template
brylie Aug 31, 2025
4157a2a
refactor: Remove unnecessary DB-level ordering in tagged page queries
brylie Aug 31, 2025
0c3e2b1
refactor: Use get_queryset() for LibraryItem, MagazineArticle, and Wf…
brylie Aug 31, 2025
c9c2482
fix: Update article reference in magazine article template to use ent…
brylie Aug 31, 2025
29d3ea2
fix: Improve author display formatting and refactor issue link render…
brylie Aug 31, 2025
9764ec5
refactor: Simplify queryset methods in LibraryItem, MagazineArticle, …
brylie Aug 31, 2025
f980f4e
fix: Update author display to use translation for "Authors" label in …
brylie Aug 31, 2025
eb76955
refactor: Remove redundant article queryset filtering in MagazineDepa…
brylie Aug 31, 2025
35bdd54
refactor: Optimize queryset in MagazineArticle for better performance
brylie Aug 31, 2025
23488ff
refactor: Optimize queryset in LibraryItem by using select_related fo…
brylie Aug 31, 2025
51598d5
refactor: Improve HTML structure in magazine article summary template…
brylie Aug 31, 2025
3c7a72a
refactor: Optimize queryset in MagazineArticle for related fetches an…
brylie Aug 31, 2025
f547f34
refactor: Improve HTML structure in magazine article summary template…
brylie Aug 31, 2025
c0e6f5d
refactor: Optimize queryset in LibraryItem by deferring streamfields …
brylie Aug 31, 2025
6d7b4a6
refactor: Add authors to magazine article tests and improve template …
brylie Aug 31, 2025
06c8750
refactor: Correctly reference specific issue object in magazine artic…
brylie Aug 31, 2025
03c4ac4
refactor: Enhance author handling in template rendering tests and imp…
brylie Aug 31, 2025
ec5f79b
refactor: Update authors label and list to use dynamic IDs for improv…
brylie Aug 31, 2025
f588b10
refactor: Improve authors label handling in template rendering tests …
brylie Aug 31, 2025
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
20 changes: 9 additions & 11 deletions library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,20 @@ class LibraryItem(DrupalFields, Page): # type: ignore

@classmethod
def get_queryset(cls):
related_fields = [
related_prefetch = [
"authors__author",
"topics__topic",
"item_audience",
"item_genre",
"item_medium",
"item_time_period",
"tags__tag",
"tags",
]
return (
super()
.get_queryset()
.filter(live=True)
.prefetch_related(
*related_fields,
cls.objects.live()
.select_related(
"item_audience",
"item_genre",
"item_medium",
"item_time_period",
)
.prefetch_related(*related_prefetch)
)

content_panels = Page.content_panels + [
Expand Down
25 changes: 10 additions & 15 deletions magazine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,25 +299,13 @@ def get_context(
) -> dict:
context = super().get_context(request)

context["articles"] = (
MagazineArticle.objects.filter(
department__title=self.title,
)
.live()
.prefetch_related(
"authors__author",
"issue",
)
)

articles = (
MagazineArticle.objects.filter(
department__title=self.title,
)
.live()
.prefetch_related(
"authors__author",
"issue",
)
)

Expand Down Expand Up @@ -365,9 +353,16 @@ class MagazineArticle(DrupalFields, Page): # type: ignore

@classmethod
def get_queryset(cls):
"""Prefetch authors and tags for performance."""
related_fields = ["authors__author", "tags__tag", "department"]
return super().get_queryset().prefetch_related(*related_fields)
"""Optimize related fetches for listings.

Note: Use cls.objects rather than super().get_queryset() because the
base class does not provide a classmethod get_queryset.
"""
return (
cls.objects.defer_streamfields()
.select_related("department")
.prefetch_related("authors__author", "tags")
)

class Meta:
verbose_name = "Magazine Article"
Expand Down
55 changes: 35 additions & 20 deletions magazine/templates/magazine/magazine_article_summary.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load wagtailcore_tags %}
{% load i18n wagtailcore_tags %}

<article class="card bg-base-100 shadow-sm hover:shadow-md transition-shadow mb-4">
<div class="card-body">
Expand All @@ -8,29 +8,44 @@ <h3 class="card-title">
</a>
</h3>

{% if article.authors.count %}
<div class="mb-2">
<span class="font-medium">Author(s):</span>
{% for author in article.authors.all %}
{% if author.author.live %}
<a href="{% pageurl author.author %}">{{ author.author }}</a>{% if not forloop.last %},{% endif %}
{% else %}
{{ author.author }}{% if not forloop.last %},{% endif %}
{% endif %}
{% endfor %}
</div>
{% endif %}
{% with author_links=article.authors.all %}
{% if author_links %}
<div class="mb-2">
<span class="font-medium">{% translate "Authors" %}:</span>
<ul class="inline">
{% for author in author_links %}
<li class="inline">
{% if author.author.live %}
<a href="{% pageurl author.author %}">{{ author.author }}</a>
{% else %}
{{ author.author }}
{% endif %}
{% if not forloop.last %}, {% endif %}
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endwith %}

<div class="prose">
{{ article.teaser|richtext }}
</div>

<div class="card-actions">
<span>
Issue: <a href="{% pageurl article.get_parent %}" class="link">
{{ article.get_parent }} ({{ article.get_parent.specific.publication_date|date:"F Y" }})
</a>
</span>
</div>
{% with issue=article.get_parent %}
<div class="card-actions">
<span>
<span class="font-medium">{% translate "Issue" %}:</span>
<a href="{% pageurl issue %}" class="link">
{{ issue }}
{% if issue.specific.publication_date %}
(<time datetime="{{ issue.specific.publication_date|date:'Y-m-d' }}">
{{ issue.specific.publication_date|date:"F Y" }}
</time>)
{% endif %}
</a>
</span>
</div>
{% endwith %}
</div>
</article>
1 change: 1 addition & 0 deletions magazine/templates/search/magazine_article.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include "magazine/magazine_article_summary.html" with article=entity %}
16 changes: 16 additions & 0 deletions magazine/templates/search/magazine_issue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% load wagtailcore_tags %}
<article class="card bg-base-100 shadow-sm hover:shadow-md transition-shadow mb-4">
<div class="card-body">
<h3 class="card-title">
<a href="{% pageurl entity %}">{{ entity.title }}</a>
</h3>
{% if entity.specific.publication_date %}
<p class="text-sm text-base-content/70">
Published
<time datetime="{{ entity.specific.publication_date|date:'Y-m-d' }}">
{{ entity.specific.publication_date|date:"F Y" }}
</time>
</p>
{% endif %}
</div>
</article>
37 changes: 32 additions & 5 deletions tags/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,42 @@ def get_queryset(self):
# Get all the pages tagged with the given tag
filter_condition = Q(tags__slug__in=[tag])

library_items = LibraryItem.objects.filter(filter_condition).order_by("title")
library_items = (
LibraryItem.get_queryset()
.filter(filter_condition)
.live()
.public()
.select_related("content_type")
.prefetch_related("authors__author")
# DB-level ordering unnecessary; combined list is sorted below
)

magazine_articles = MagazineArticle.objects.filter(filter_condition).order_by(
"title",
magazine_articles = (
MagazineArticle.get_queryset()
.filter(filter_condition)
.live()
.public()
.select_related("content_type")
.prefetch_related("authors__author")
# DB-level ordering unnecessary; combined list is sorted below
)

news_items = NewsItem.objects.filter(filter_condition).order_by("title")
news_items = (
NewsItem.objects.filter(filter_condition)
.live()
.public()
.select_related("content_type")
# DB-level ordering unnecessary; combined list is sorted below
)

pages = WfPage.objects.filter(filter_condition).order_by("title")
pages = (
WfPage.get_queryset()
.filter(filter_condition)
.live()
.public()
.select_related("content_type")
# DB-level ordering unnecessary; combined list is sorted below
)

combined_queryset_list = list(
chain(
Expand Down
2 changes: 1 addition & 1 deletion wf_pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class WfPage(DrupalFields, Page):
@classmethod
def get_queryset(cls):
"""Prefetch tags for performance."""
return super().get_queryset().prefetch_related("tags__tag")
return cls.objects.prefetch_related("tags")

content_panels = Page.content_panels + [
FieldPanel("body"),
Expand Down