From 6ae2c808f7e63c535304c27a18f0ae1d44736943 Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 23 Apr 2025 09:12:08 +1200 Subject: [PATCH 1/3] Remove trailing whitespace from event hero template --- templates/includes/event_hero.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/templates/includes/event_hero.html b/templates/includes/event_hero.html index 342fe72d..b32fd0d5 100644 --- a/templates/includes/event_hero.html +++ b/templates/includes/event_hero.html @@ -1,17 +1,17 @@ {% load wagtailcore_tags wagtailimages_tags l10n %}
- +

{{ self.title}}

- +

{# Display date differently depending on if it spans multiple days #} {% if self.start_time.date == self.end_time.date %} - – + {% else %} - – + {% endif %}

@@ -22,13 +22,13 @@

{{ self.title}}

{# Much of this schema is ported over from the old event template #} {% if self.location %}
{{ self.location.name }} {% if not self.location.name == "Virtual" %} -
@@ -54,7 +54,7 @@

Speakers

{% if self.tags.all %}
{% for tag in self.tags.all %} -
{{ tag }}
+
{{ tag }}
{% endfor %}
{% endif %} @@ -62,7 +62,7 @@

Speakers

{% if self.image %}
- {% comment %} + {% comment %} All are cropped to a 16:9 ratio. This differs from design, as discussed. If changing this by image rendition, update aspect-ratio in the CSS instead of via inline style. @@ -76,12 +76,12 @@

Speakers

{{ self.alt_text|default:img_base.alt }} - + {% if self.caption or self.credit %}
{% if self.credit %} @@ -97,7 +97,7 @@

Speakers

{% endif %}
- + {% endif %} - +
From 2dce2d06b1e5abbf884b15cb5eaebaae9eb693c8 Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 23 Apr 2025 09:12:55 +1200 Subject: [PATCH 2/3] [CDH-85] Add links from event speakers to CDH person-profiles --- templates/includes/event_hero.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/templates/includes/event_hero.html b/templates/includes/event_hero.html index b32fd0d5..5686f18b 100644 --- a/templates/includes/event_hero.html +++ b/templates/includes/event_hero.html @@ -45,7 +45,11 @@

{{ self.title}}

Speakers

    {% for speaker in page.speakers.all %} -
  • {{ speaker.person }}
  • + {% if speaker.person.profile %} +
  • {{ speaker.person }}
  • + {% else %} +
  • {{ speaker.person }}
  • + {% endif %} {% endfor %}
From 2e7c656404f6eb6516a70c958fb9d4c5d5962900 Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 23 Apr 2025 09:39:49 +1200 Subject: [PATCH 3/3] Swap navigation queries from exists()->first() to just first() This should reduce the number of queries we make on two fronts -- first, the exists does a `select 1 ...`, which doesn't contribute to the cache, and so the `.first()` call then makes a second query to get actual data. There were also a bunch of places where we were repeatedly calling `first` to get a related item, which might have been doing multiple queries -- but this way is also a but more readable --- cdhweb/pages/templatetags/core_tags.py | 50 +++++++++++++------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/cdhweb/pages/templatetags/core_tags.py b/cdhweb/pages/templatetags/core_tags.py index 118586e5..87452db7 100644 --- a/cdhweb/pages/templatetags/core_tags.py +++ b/cdhweb/pages/templatetags/core_tags.py @@ -19,21 +19,21 @@ def site_footer(context): Returns the site footer data. """ # Get footer items - footers = Footer.objects.prefetch_related( + footer = Footer.objects.prefetch_related( "contact_links", "useful_links", "imprint_links" - ) + ).first() data = { "request": context["request"], "site_search": context["site_search"], "SW_VERSION": context["SW_VERSION"], } - if footers.exists(): - contact_links = footers.first().contact_links.all() - social_media_links = footers.first().social_media_links.all() - physical_address = footers.first().address - useful_links = footers.first().useful_links.all() - imprint_links = footers.first().imprint_links.all() + if footer: + contact_links = footer.contact_links.all() + social_media_links = footer.social_media_links.all() + physical_address = footer.address + useful_links = footer.useful_links.all() + imprint_links = footer.imprint_links.all() data |= { "contact_links": contact_links, @@ -77,9 +77,9 @@ def _get_primary_nav_items(): l1_menu_items = [] primary_nav = PrimaryNavigation.objects.prefetch_related( "l1_items", "l1_items__l2_items" - ) - if primary_nav.exists(): - l1_menu_items = primary_nav.first().l1_items.all() + ).first() + if primary_nav: + l1_menu_items = primary_nav.l1_items.all() return l1_menu_items @@ -132,9 +132,9 @@ def _get_secondary_nav_items(): Get secondary nav items """ items = [] - secondary_nav = SecondaryNavigation.objects.prefetch_related("items") - if secondary_nav.exists(): - items = secondary_nav.first().items.all() + secondary_nav = SecondaryNavigation.objects.prefetch_related("items").first() + if secondary_nav: + items = secondary_nav.items.all() return items @@ -143,10 +143,10 @@ def _get_secondary_nav_cta_button(): """ Get secondary nav cta button """ - secondary_nav = SecondaryNavigation.objects.prefetch_related("cta_button") + secondary_nav = SecondaryNavigation.objects.prefetch_related("cta_button").first() - if secondary_nav.exists(): - return secondary_nav.first().cta_button.all() + if secondary_nav: + return secondary_nav.cta_button.all() return [] @@ -158,9 +158,9 @@ def primary_navigation(): l1_menu_items = [] main_menu = PrimaryNavigation.objects.prefetch_related( "l1_items", "l1_items__l2_items" - ) - if main_menu.exists(): - l1_menu_items = main_menu.first().l1_items.all() + ).first() + if main_menu: + l1_menu_items = main_menu.l1_items.all() data = { "l1_menu_items": l1_menu_items, @@ -177,10 +177,12 @@ def secondary_navigation(): """ items = [] - secondary_menu = SecondaryNavigation.objects.prefetch_related("items", "cta_button") - if secondary_menu.exists(): - items = secondary_menu.first().items.all() - cta_button = secondary_menu.first().cta_button.first() + secondary_menu = SecondaryNavigation.objects.prefetch_related( + "items", "cta_button" + ).first() + if secondary_menu: + items = secondary_menu.items.all() + cta_button = secondary_menu.cta_button.first() data = { "secondary_nav_items": items,