Skip to content

Commit

Permalink
locale in blog posts
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiboutas committed Jan 14, 2024
1 parent 0ff48f0 commit cfb3a9d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cms/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def cms_menu_pages(request):
try:
locale = Locale.objects.get(language_code=request.LANGUAGE_CODE)
except Locale.DoesNotExist:
return {"cms_navbar_pages": None}
return {"cms_navbar_pages": None, "cms_footer_pages": None}
blog_pages = BlogIndexPage.objects.filter(locale=locale, show_in_menus=True)
flex_pages = FlexPage.objects.filter(locale=locale, show_in_menus=True)
text_pages = TextPage.objects.filter(locale=locale, show_in_menus=True)
Expand Down
18 changes: 12 additions & 6 deletions cms/models/blog.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from django.db import models
from django.core.paginator import EmptyPage
from django.core.paginator import PageNotAnInteger
from django.core.paginator import Paginator
from django.db import models

from modelcluster.fields import ParentalKey
from wagtail.admin.panels import FieldPanel
from wagtail.admin.panels import InlinePanel
from wagtail.admin.panels import FieldPanel, InlinePanel
from wagtail.fields import StreamField
from wagtail.models import Orderable
from wagtail.models import Page
from wagtail.models import Page, Orderable, Locale

from ..streams import ArticleStreamBlock

Expand All @@ -21,8 +20,15 @@ class BlogIndexPage(Page):
def get_context(self, request, *args, **kwargs):
"""Adding custom stuff to our context."""
context = super().get_context(request, *args, **kwargs)
# locale
locale = Locale.objects.get(language_code=request.LANGUAGE_CODE)
# Get all posts
all_posts = BlogPostPage.objects.live().public().order_by("-first_published_at")
all_posts = (
BlogPostPage.objects.live()
.filter(locale=locale)
.public()
.order_by("-first_published_at")
)
# Paginate all posts by 24 per page
paginator = Paginator(all_posts, 24)
# Try to get the ?page=x value
Expand Down

0 comments on commit cfb3a9d

Please sign in to comment.