Compare commits

..

13 commits

Author SHA1 Message Date
f3ada439fa Merge pull request '12955-add-terms-link-footer' (#11) from 12955-add-terms-link-footer into master
Reviewed-on: #11
2024-07-19 14:43:53 +00:00
PCoder
b3b2a73fc9 Cleanup 2024-07-19 20:13:11 +05:30
PCoder
df467691b8 More reorganize 2024-07-19 20:09:23 +05:30
PCoder
2a6434e569 Simplify 2024-07-19 20:01:32 +05:30
PCoder
87332a9f05 Cleanup 2024-07-19 19:56:32 +05:30
PCoder
822fca63c3 Add add_item_to_page_queryset method 2024-07-19 16:21:47 +02:00
PCoder
9618ac0094 Cleanup and use correct page for EN 2024-07-19 17:50:38 +05:30
app
a7abe02784 Merging 2024-07-19 12:05:03 +00:00
app
454767b551 Fix footer menuitems translation 2024-07-19 11:58:23 +00:00
PCoder
99eb7c39fe Fix error instance 2024-07-19 16:20:19 +05:30
PCoder
780a4ce2d7 Fix bug footer menu items not translated 2024-07-19 14:04:15 +05:30
PCoder
31a0a6b060 Search hostname instead of site object 2024-07-19 14:03:53 +05:30
PCoder
a68dcb7574 Show terms and conditions link in the footer bottom 2024-07-19 13:38:15 +05:30

View file

@ -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'],
}