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

Community N+1 loop #820

Merged
merged 2 commits into from
Jul 25, 2023
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
18 changes: 18 additions & 0 deletions community/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.http import HttpRequest
from wagtail import blocks as wagtail_blocks
from wagtail.admin.panels import FieldPanel, PageChooserPanel
from wagtail.fields import RichTextField, StreamField
Expand Down Expand Up @@ -122,6 +123,23 @@ class OnlineWorshipIndexPage(Page):

template = "community/online_worship_index_page.html"

def get_context(
self,
request: HttpRequest,
*args: tuple,
**kwargs: dict,
) -> dict:
context = super().get_context(request, *args, **kwargs)

# Get all live OnlineWorship objects sorted by title
online_worship_meetings = OnlineWorship.objects.live().order_by(
"title",
)

context["online_worship_meetings"] = online_worship_meetings

return context


class CommunityDirectory(Page):
description = RichTextField(blank=True)
Expand Down
30 changes: 15 additions & 15 deletions community/templates/community/online_worship_index_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,53 @@ <h1>

{{ page.intro | richtext }}

{% for online_worship in self.get_children|dictsort:"title" %}
{% for online_worship in online_worship_meetings %}
<div class="card mb-3">
<div class="card-body">
<h2 class="card-title fs-3">{{ online_worship.title }}</h2>

{% if online_worship.specific.times_of_worship %}
{% if online_worship.times_of_worship %}
<p class="card-text">
<strong>Times of worship:</strong>&nbsp;
{{ online_worship.specific.times_of_worship | richtext }}
{{ online_worship.times_of_worship | richtext }}
</p>
{% endif %}

{% if online_worship.specific.hosted_by %}
{% if online_worship.hosted_by %}
<p>
<strong>Hosted by:</strong>&nbsp;
{{ online_worship.specific.hosted_by }}
{{ online_worship.hosted_by }}
</p>
{% endif %}

{% if online_worship.specific.online_worship_day %}
{% if online_worship.online_worship_day %}
<p>
<strong>Online worship day:</strong>&nbsp;
{{ online_worship.specific.online_worship_day }}
{{ online_worship.online_worship_day }}
</p>
{% endif %}

{% if online_worship.specific.online_worship_time %}
{% if online_worship.online_worship_time %}
<p>
<strong>Online worship time:</strong>&nbsp;
{{ online_worship.specific.online_worship_time }}
{% if online_worship.specific.online_worship_timezone %}
({{ online_worship.specific.online_worship_timezone }})
{{ online_worship.online_worship_time }}
{% if online_worship.online_worship_timezone %}
({{ online_worship.online_worship_timezone }})
{% endif %}
</p>
{% endif %}

{% if online_worship.specific.online_worship_url %}
{% if online_worship.online_worship_url %}
<p>
<strong>Online worship URL:</strong>&nbsp;
{{ online_worship.specific.online_worship_url }}
{{ online_worship.online_worship_url }}
</p>
{% endif %}

{% if online_worship.specific.online_worship_notes %}
{% if online_worship.online_worship_notes %}
<p>
<strong>Online worship notes:</strong>&nbsp;
{{ online_worship.specific.online_worship_notes }}
{{ online_worship.online_worship_notes }}
</p>
{% endif %}
<a href="{{ online_worship.url }}" class="btn btn-primary stretched-link">View details</a>
Expand Down
16 changes: 12 additions & 4 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.contrib.sitemaps.views import sitemap
from wagtail.documents import urls as wagtaildocs_urls
import debug_toolbar

if settings.DEBUG:
import debug_toolbar
# TODO: Change this line to send verification emails when registering users
# Note: this will require two activation email tempates (subject and body)
# from django_registration.backends.activation.views import RegistrationView
Expand Down Expand Up @@ -50,5 +49,14 @@
if settings.DEBUG:
# Serve static and media files from development server
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [path("__debug__/", include(debug_toolbar.urls))] # type: ignore
urlpatterns += static(
settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT,
)
urlpatterns.insert(
0,
path(
"__debug__/",
include(debug_toolbar.urls),
),
)