Skip to content

Commit

Permalink
Add paginated authored pages to person profile
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Nov 25, 2024
1 parent 85dfff3 commit 8c26f92
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 deletions.
65 changes: 33 additions & 32 deletions app/templates/people/person.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,49 +85,51 @@ <h1 class="tna-heading-xl" itemprop="name">{{ page_data.title }}</h1>
'icon': 'arrow-left'
}) }}
</div>
<h2 class="tna-heading-l tna-!--no-margin-top">Articles by {{ page_data.first_name }}, page {{ page }} of {{ pages }}</h2>
<h2 class="tna-heading-l tna-!--no-margin-top">Articles by {{ page_data.first_name }}{% if pages > 1 %}, page {{ page }} of {{ pages }}{% endif %}</h2>
</div>
</div>
<ul class="tna-container">
{%- for article in articles %}
<li class="tna-column tna-column--width-1-3 tna-column--width-1-2-medium tna-column--small-tiny tna-column--full-tiny tna-!--margin-top-l">
{% set card_content = {
'supertitle': article.page.type_label,
'title': article.page.title,
'supertitle': article.type_label,
'title': article.title,
'headingLevel': 3,
'headingSize': 's',
'href': article.page.url,
'body': article.page.teaser_text,
'label': 'New' if article.page.is_newly_published,
'href': article.url,
'body': article.teaser_text,
'label': 'New' if article.is_newly_published,
'labelColour': 'green',
'fullAreaClick': True,
'classes': 'tna-card--full-height'
} %}
{%- if article.page.teaser_image %}
{%- if article.teaser_image %}
{% set card_content = dict(card_content, **{
'imageSrc': article.page.teaser_image.jpeg.full_url,
'imageAlt': article.page.teaser_image.alt_text or '',
'imageWidth': article.page.teaser_image.jpeg.width,
'imageHeight': article.page.teaser_image.jpeg.height,
'imageSrc': article.teaser_image.jpeg.full_url,
'imageAlt': article.teaser_image.alt_text or '',
'imageWidth': article.teaser_image.jpeg.width,
'imageHeight': article.teaser_image.jpeg.height,
'imageSources': [
{
'src': article.page.teaser_image.webp.full_url,
'src': article.teaser_image.webp.full_url,
'type': 'image/webp',
'width': article.page.teaser_image.webp.width,
'height': article.page.teaser_image.webp.height
'width': article.teaser_image.webp.width,
'height': article.teaser_image.webp.height
}
]
}) %}
{%- endif %}
{{ tnaCard(card_content) }}
<meta itemprop="significantLink" content="{{ article.page.url }}">
<meta itemprop="significantLink" content="{{ article.url }}">
</li>
{%- endfor %}
</ul>
<div class="tna-container">
<div class="tna-column tna-column--full tna-!--margin-top-xl">
<div class="tna-container tna-!--margin-top-xl">
{% if pages > 1 %}
<div class="tna-column tna-column--full">
{{ tnaPagination(pagination) }}
</div>
{% endif %}
</div>
{% else %}
<div class="tna-container tna-container--centred">
Expand Down Expand Up @@ -186,40 +188,39 @@ <h2 id="articles" class="tna-heading-l tna-!--padding-bottom-m">Articles</h2>
{%- for article in articles %}
<li class="tna-column tna-column--width-1-2 tna-column--full-tiny tna-!--margin-bottom-l">
{% set card_content = {
'supertitle': article.page.type_label,
'title': article.page.title,
'supertitle': article.type_label,
'title': article.title,
'headingLevel': 3,
'headingSize': 's',
'href': article.page.url,
'body': article.page.teaser_text,
'label': 'New' if article.page.is_newly_published,
'href': article.url,
'body': article.teaser_text,
'label': 'New' if article.is_newly_published,
'labelColour': 'green',
'fullAreaClick': True,
'classes': 'tna-card--full-height'
} %}
{%- if article.page.teaser_image %}
{%- if article.teaser_image %}
{% set card_content = dict(card_content, **{
'imageSrc': article.page.teaser_image.jpeg.full_url,
'imageAlt': article.page.teaser_image.alt_text or '',
'imageWidth': article.page.teaser_image.jpeg.width,
'imageHeight': article.page.teaser_image.jpeg.height,
'imageSrc': article.teaser_image.jpeg.full_url,
'imageAlt': article.teaser_image.alt_text or '',
'imageWidth': article.teaser_image.jpeg.width,
'imageHeight': article.teaser_image.jpeg.height,
'imageSources': [
{
'src': article.page.teaser_image.webp.full_url,
'src': article.teaser_image.webp.full_url,
'type': 'image/webp',
'width': article.page.teaser_image.webp.width,
'height': article.page.teaser_image.webp.height
'width': article.teaser_image.webp.width,
'height': article.teaser_image.webp.height
}
],
'lazyImage': True
}) %}
{%- endif %}
{{ tnaCard(card_content) }}
<meta itemprop="significantLink" content="{{ article.page.url }}">
<meta itemprop="significantLink" content="{{ article.url }}">
</li>
{%- endfor %}
</ul>
{{ more_articles }}
{% if more_articles %}
<div class="tna-button-group tna-button-group--centred tna-!--margin-bottom-l">
{{ tnaButton({
Expand Down
13 changes: 13 additions & 0 deletions app/wagtail/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ def page_children_paginated(
)


def authored_pages_paginated(
author_id,
page,
limit=None,
params={},
):
return pages_paginated(
page=page,
limit=limit,
params=params | {"author": author_id},
)


def page_descendants(
page_id,
params={},
Expand Down
14 changes: 9 additions & 5 deletions app/wagtail/pages/person_page.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import math

from app.lib.pagination import pagination_object
from app.wagtail.api import authors_paginated, breadcrumbs
from app.wagtail.api import authored_pages_paginated, breadcrumbs
from flask import current_app, render_template, request
from pydash import objects


def person_page(page_data):
articles_preview_list = 2
articles_per_page = 1
articles_preview_list = 4
articles_per_page = 12
page = (
int(request.args.get("page"))
if request.args.get("page") and request.args.get("page").isnumeric()
else 0
)
try:
articles = authors_paginated(page_data["id"], page or 1)
articles = authored_pages_paginated(
page_data["id"],
page or 1,
articles_per_page if page else articles_preview_list,
)
except ConnectionError:
current_app.logger.error(
f"API error getting author articles for page {page_data['id']}"
Expand All @@ -39,6 +43,6 @@ def person_page(page_data):
pagination=pagination_object(page, pages, request.args),
page=page,
pages=pages,
articles=articles if page else articles[0:articles_preview_list],
articles=articles,
more_articles=total_article_count > articles_preview_list,
)

0 comments on commit 8c26f92

Please sign in to comment.