12955-add-terms-link-footer #11
1 changed files with 32 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django import template
|
||||
from django.utils import translation
|
||||
from django.db.models import Case, When
|
||||
|
||||
from wagtail.core.models import Site, Page
|
||||
from ..models.forms import ContactForm
|
||||
|
@ -67,7 +68,7 @@ def top_menu(context, parent, calling_page=None):
|
|||
'request': context['request'],
|
||||
}
|
||||
|
||||
def menuitems_children(parent):
|
||||
def menuitems_children(parent, context=None):
|
||||
remove_mitglied = False
|
||||
remove_devenez = False
|
||||
if 'Qui sommes-nous' in parent.title:
|
||||
|
@ -78,20 +79,44 @@ def menuitems_children(parent):
|
|||
items_to_remove = []
|
||||
for menuitem in menuitems_children:
|
||||
try:
|
||||
if type(menuitem) == ContactForm:
|
||||
menuitem.title = menuitem.title
|
||||
else:
|
||||
menuitem.title = menuitem.trans_title
|
||||
if 'devenez' in menuitem.title.lower() and remove_devenez:
|
||||
items_to_remove.append(menuitem)
|
||||
elif 'mitglied werden' in menuitem.title.lower() and remove_mitglied:
|
||||
items_to_remove.append(menuitem)
|
||||
except AttributeError:
|
||||
except AttributeError as ae:
|
||||
pass
|
||||
for item in items_to_remove:
|
||||
menuitems_children = menuitems_children & Page.objects.not_page(item)
|
||||
if context:
|
||||
request = context['request']
|
||||
site = Site.find_for_request(request)
|
||||
if site.hostname in ['sphc.ch', 'public-health.ch']:
|
||||
# custom page here is the terms and conditions page for public-health.ch and sphc.ch (common)
|
||||
if request.__dict__.get('LANGUAGE_CODE', 'de').lower() == 'en':
|
||||
custom_page_id = 1020
|
||||
else:
|
||||
custom_page_id = 994
|
||||
custom_page = Page.objects.get(id=custom_page_id)
|
||||
menuitems_children = add_item_to_page_queryset(menuitems_children, custom_page)
|
||||
for menuitem in menuitems_children:
|
||||
try:
|
||||
menuitem.title = menuitem.trans_title
|
||||
except AttributeError as aee:
|
||||
pass
|
||||
return menuitems_children
|
||||
|
||||
def add_item_to_page_queryset(queryset, custom_page):
|
||||
# Convert queryset to a list
|
||||
pages_list = list(queryset)
|
||||
# Add the custom page to the list
|
||||
pages_list.append(custom_page)
|
||||
# Create a new ordered queryset based on the list order
|
||||
page_ids = [page.id for page in pages_list]
|
||||
preserved_order = Case(*[When(pk=pk, then=pos) for pos, pk in enumerate(page_ids)])
|
||||
new_queryset = Page.objects.filter(id__in=page_ids).order_by(preserved_order).specific()
|
||||
return new_queryset
|
||||
|
||||
|
||||
# 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):
|
||||
|
@ -106,6 +131,6 @@ def top_menu_children(context, parent):
|
|||
def footer_menu(context, parent, calling_page=None):
|
||||
return {
|
||||
'calling_page': calling_page,
|
||||
'menuitems': menuitems_children(parent),
|
||||
'menuitems': menuitems_children(parent, context),
|
||||
'request': context['request'],
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue