Compare commits
13 commits
fc6f9e43a7
...
f3ada439fa
Author | SHA1 | Date | |
---|---|---|---|
f3ada439fa | |||
|
b3b2a73fc9 | ||
|
df467691b8 | ||
|
2a6434e569 | ||
|
87332a9f05 | ||
|
822fca63c3 | ||
|
9618ac0094 | ||
|
a7abe02784 | ||
|
454767b551 | ||
|
99eb7c39fe | ||
|
780a4ce2d7 | ||
|
31a0a6b060 | ||
|
a68dcb7574 |
1 changed files with 32 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from django import template
|
from django import template
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
from django.db.models import Case, When
|
||||||
|
|
||||||
from wagtail.core.models import Site, Page
|
from wagtail.core.models import Site, Page
|
||||||
from ..models.forms import ContactForm
|
from ..models.forms import ContactForm
|
||||||
|
@ -67,7 +68,7 @@ def top_menu(context, parent, calling_page=None):
|
||||||
'request': context['request'],
|
'request': context['request'],
|
||||||
}
|
}
|
||||||
|
|
||||||
def menuitems_children(parent):
|
def menuitems_children(parent, context=None):
|
||||||
remove_mitglied = False
|
remove_mitglied = False
|
||||||
remove_devenez = False
|
remove_devenez = False
|
||||||
if 'Qui sommes-nous' in parent.title:
|
if 'Qui sommes-nous' in parent.title:
|
||||||
|
@ -78,20 +79,44 @@ def menuitems_children(parent):
|
||||||
items_to_remove = []
|
items_to_remove = []
|
||||||
for menuitem in menuitems_children:
|
for menuitem in menuitems_children:
|
||||||
try:
|
try:
|
||||||
if type(menuitem) == ContactForm:
|
|
||||||
menuitem.title = menuitem.title
|
|
||||||
else:
|
|
||||||
menuitem.title = menuitem.trans_title
|
|
||||||
if 'devenez' in menuitem.title.lower() and remove_devenez:
|
if 'devenez' in menuitem.title.lower() and remove_devenez:
|
||||||
items_to_remove.append(menuitem)
|
items_to_remove.append(menuitem)
|
||||||
elif 'mitglied werden' in menuitem.title.lower() and remove_mitglied:
|
elif 'mitglied werden' in menuitem.title.lower() and remove_mitglied:
|
||||||
items_to_remove.append(menuitem)
|
items_to_remove.append(menuitem)
|
||||||
except AttributeError:
|
except AttributeError as ae:
|
||||||
pass
|
pass
|
||||||
for item in items_to_remove:
|
for item in items_to_remove:
|
||||||
menuitems_children = menuitems_children & Page.objects.not_page(item)
|
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
|
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
|
# Retrieves the children of the top menu items for the drop downs
|
||||||
@register.inclusion_tag('tags/top_menu_children.html', takes_context=True)
|
@register.inclusion_tag('tags/top_menu_children.html', takes_context=True)
|
||||||
def top_menu_children(context, parent):
|
def top_menu_children(context, parent):
|
||||||
|
@ -106,6 +131,6 @@ def top_menu_children(context, parent):
|
||||||
def footer_menu(context, parent, calling_page=None):
|
def footer_menu(context, parent, calling_page=None):
|
||||||
return {
|
return {
|
||||||
'calling_page': calling_page,
|
'calling_page': calling_page,
|
||||||
'menuitems': menuitems_children(parent),
|
'menuitems': menuitems_children(parent, context),
|
||||||
'request': context['request'],
|
'request': context['request'],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue