|
@@ -1,13 +1,8 @@
|
|
|
-from django import template
|
|
|
from wagtail.models import Page, Site
|
|
|
|
|
|
from bakerydemo.base.models import FooterText
|
|
|
|
|
|
-register = template.Library()
|
|
|
-# https://docs.djangoproject.com/en/3.2/howto/custom-template-tags/
|
|
|
|
|
|
-
|
|
|
-@register.simple_tag(takes_context=True)
|
|
|
def get_site_root(context):
|
|
|
# This returns a core.Page. The main menu needs to have the site.root_page
|
|
|
# defined else will return an object attribute error ('str' object has no
|
|
@@ -35,8 +30,7 @@ def is_active(page, current_page):
|
|
|
# Retrieves the top menu items - the immediate children of the parent page
|
|
|
# The has_menu_children method is necessary because the Foundation menu requires
|
|
|
# a dropdown class to be applied to a parent
|
|
|
-@register.inclusion_tag("tags/top_menu.html", takes_context=True)
|
|
|
-def top_menu(context, parent, calling_page=None):
|
|
|
+def top_menu(parent, calling_page=None):
|
|
|
menuitems = parent.get_children().live().in_menu()
|
|
|
for menuitem in menuitems:
|
|
|
menuitem.show_dropdown = has_menu_children(menuitem)
|
|
@@ -51,14 +45,11 @@ def top_menu(context, parent, calling_page=None):
|
|
|
return {
|
|
|
"calling_page": calling_page,
|
|
|
"menuitems": menuitems,
|
|
|
- # required by the pageurl tag that we want to use within this template
|
|
|
- "request": context["request"],
|
|
|
}
|
|
|
|
|
|
|
|
|
# Retrieves the children of the top menu items for the drop downs
|
|
|
-@register.inclusion_tag("tags/top_menu_children.html", takes_context=True)
|
|
|
-def top_menu_children(context, parent, calling_page=None):
|
|
|
+def top_menu_children(parent, calling_page=None):
|
|
|
menuitems_children = parent.get_children()
|
|
|
menuitems_children = menuitems_children.live().in_menu()
|
|
|
for menuitem in menuitems_children:
|
|
@@ -75,14 +66,11 @@ def top_menu_children(context, parent, calling_page=None):
|
|
|
return {
|
|
|
"parent": parent,
|
|
|
"menuitems_children": menuitems_children,
|
|
|
- # required by the pageurl tag that we want to use within this template
|
|
|
- "request": context["request"],
|
|
|
}
|
|
|
|
|
|
|
|
|
-@register.inclusion_tag("tags/breadcrumbs.html", takes_context=True)
|
|
|
def breadcrumbs(context):
|
|
|
- self = context.get("self")
|
|
|
+ self = context.get("page")
|
|
|
if self is None or self.depth <= 2:
|
|
|
# When on the home page, displaying breadcrumbs is irrelevant.
|
|
|
ancestors = ()
|
|
@@ -90,12 +78,11 @@ def breadcrumbs(context):
|
|
|
ancestors = Page.objects.ancestor_of(self, inclusive=True).filter(depth__gt=1)
|
|
|
return {
|
|
|
"ancestors": ancestors,
|
|
|
- "request": context["request"],
|
|
|
}
|
|
|
|
|
|
|
|
|
-@register.inclusion_tag("base/include/footer_text.html", takes_context=True)
|
|
|
def get_footer_text(context):
|
|
|
+ # Use together with base/include/footer_text.html.
|
|
|
# Get the footer text from the context if exists,
|
|
|
# so that it's possible to pass a custom instance e.g. for previews
|
|
|
# or page types that need a custom footer
|