diff options
author | Jonathan DeMasi <jonathan.demasi@colorado.edu> | 2020-03-06 00:40:46 -0700 |
---|---|---|
committer | Jonathan DeMasi <jonathan.demasi@colorado.edu> | 2020-03-06 00:40:46 -0700 |
commit | c8b64c8069b6bd7ba6aa42bc73aca9ec82a19f13 (patch) | |
tree | 4e3d5a4d13e33c0f9fbb20719c4701f0a7b76ff5 | |
parent | bf0aa252851d58576ff6df557dc173257c8a4250 (diff) | |
download | jthanio-c8b64c8069b6bd7ba6aa42bc73aca9ec82a19f13.tar jthanio-c8b64c8069b6bd7ba6aa42bc73aca9ec82a19f13.tar.gz jthanio-c8b64c8069b6bd7ba6aa42bc73aca9ec82a19f13.tar.bz2 jthanio-c8b64c8069b6bd7ba6aa42bc73aca9ec82a19f13.tar.lz jthanio-c8b64c8069b6bd7ba6aa42bc73aca9ec82a19f13.tar.xz jthanio-c8b64c8069b6bd7ba6aa42bc73aca9ec82a19f13.tar.zst jthanio-c8b64c8069b6bd7ba6aa42bc73aca9ec82a19f13.zip |
pagination working
-rw-r--r-- | blog/models.py | 14 | ||||
-rw-r--r-- | jthanio/settings/base.py | 2 |
2 files changed, 15 insertions, 1 deletions
diff --git a/blog/models.py b/blog/models.py index 5ce14e4..d53fb64 100644 --- a/blog/models.py +++ b/blog/models.py @@ -1,5 +1,6 @@ from django.db import models from django import forms +from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from wagtail.core.models import Page, Orderable from wagtail.core.fields import RichTextField, StreamField from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanel, StreamFieldPanel @@ -24,6 +25,19 @@ class BlogIndexPage(Page): # Update context to include only published posts, ordered by reverse-chron context = super().get_context(request) blogpages = self.get_children().live().order_by('-first_published_at') + paginator = Paginator(blogpages, 5) + # Try to get the ?page=x value + page = request.GET.get("page") + try: + # If the page exists and the ?page=x is an int + blogpages = paginator.page(page) + except PageNotAnInteger: + # If the ?page=x is not an int; show the first page + blogpages = paginator.page(1) + except EmptyPage: + # If the ?page=x is out of range (too high most likely) + # Then return the last page + blogpages = paginator.page(paginator.num_pages) context['blogpages'] = blogpages return context diff --git a/jthanio/settings/base.py b/jthanio/settings/base.py index 4a89fac..466fd1d 100644 --- a/jthanio/settings/base.py +++ b/jthanio/settings/base.py @@ -162,4 +162,4 @@ WAGTAIL_SITE_NAME = "jthanio" # Base URL to use when referring to full URLs within the Wagtail admin backend - # e.g. in notification emails. Don't include '/admin' or a trailing slash BASE_URL = 'http://example.com' -WAGTAIL_CODE_BLOCK_THEME = 'twilight' +WAGTAIL_CODE_BLOCK_THEME = 'okaidia' |