From a68dcb7574624569d36b0316426ef6cd590c9bad Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 13:38:15 +0530 Subject: [PATCH 01/11] Show terms and conditions link in the footer bottom --- publichealth/home/templatetags/navigation.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index 9d984e9..f9e9896 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -67,7 +67,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: @@ -90,6 +90,18 @@ def menuitems_children(parent): 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 in ['sphc.ch', 'public-health.ch']: + print("site is %s, add terms and conditions to footer" % site.hostname) + # custom page here is the terms and conditions page for public-health.ch and sphc.ch (common) + custom_page_id = 994 + custom_page = Page.objects.get(id=custom_page_id) + menuitems_children = list(menuitems_children) + menuitems_children.append(custom_page) + page_ids = [page.id for page in menuitems_children] + menuitems_children = Page.objects.filter(id__in=page_ids).specific() return menuitems_children # Retrieves the children of the top menu items for the drop downs @@ -106,6 +118,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'], } -- 2.45.2 From 31a0a6b0607bc432684f9d827f2a0a25c9cb1d04 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 14:03:53 +0530 Subject: [PATCH 02/11] Search hostname instead of site object --- publichealth/home/templatetags/navigation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index f9e9896..7025c5d 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -93,7 +93,7 @@ def menuitems_children(parent, context=None): if context: request = context['request'] site = Site.find_for_request(request) - if site in ['sphc.ch', 'public-health.ch']: + if site.hostname in ['sphc.ch', 'public-health.ch']: print("site is %s, add terms and conditions to footer" % site.hostname) # custom page here is the terms and conditions page for public-health.ch and sphc.ch (common) custom_page_id = 994 -- 2.45.2 From 780a4ce2d73d4285a3659e94aaa71aa5cf9770cc Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 14:04:15 +0530 Subject: [PATCH 03/11] Fix bug footer menu items not translated --- publichealth/home/templatetags/navigation.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index 7025c5d..f03aea3 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -78,15 +78,13 @@ def menuitems_children(parent, context=None): 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) + menuitem.title = menuitem.trans_title except AttributeError: + print("Menuitem %s has an issue :: %s" % (menuitem.title, str(ae))) pass for item in items_to_remove: menuitems_children = menuitems_children & Page.objects.not_page(item) -- 2.45.2 From 99eb7c39fe9d4f167f7c5dc46c43d875baf35462 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 16:20:19 +0530 Subject: [PATCH 04/11] Fix error instance --- publichealth/home/templatetags/navigation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index f03aea3..3db9dab 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -83,7 +83,7 @@ def menuitems_children(parent, context=None): elif 'mitglied werden' in menuitem.title.lower() and remove_mitglied: items_to_remove.append(menuitem) menuitem.title = menuitem.trans_title - except AttributeError: + except AttributeError as ae: print("Menuitem %s has an issue :: %s" % (menuitem.title, str(ae))) pass for item in items_to_remove: -- 2.45.2 From 454767b55122193c49b3ea913e7b9558b23d0886 Mon Sep 17 00:00:00 2001 From: app Date: Fri, 19 Jul 2024 11:58:23 +0000 Subject: [PATCH 05/11] Fix footer menuitems translation --- publichealth/home/templatetags/navigation.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index f03aea3..669f443 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -77,13 +77,16 @@ def menuitems_children(parent, context=None): menuitems_children = parent.get_children().live().in_menu().specific() items_to_remove = [] for menuitem in menuitems_children: + print('type => %s' % type(menuitem)) try: 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) - menuitem.title = menuitem.trans_title - except AttributeError: + #menuitem.title = menuitem.trans_title + if context: + print(" title=%s ---- trans_title=%s" % (menuitem.title, menuitem.trans_title)) + except AttributeError as ae: print("Menuitem %s has an issue :: %s" % (menuitem.title, str(ae))) pass for item in items_to_remove: @@ -100,6 +103,11 @@ def menuitems_children(parent, context=None): menuitems_children.append(custom_page) page_ids = [page.id for page in menuitems_children] menuitems_children = Page.objects.filter(id__in=page_ids).specific() + for menuitem in menuitems_children: + try: + menuitem.title = menuitem.trans_title + except AttributeError as aee: + pass return menuitems_children # Retrieves the children of the top menu items for the drop downs -- 2.45.2 From 9618ac009427c449612416bb4d8383f53186534c Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 17:50:38 +0530 Subject: [PATCH 06/11] Cleanup and use correct page for EN --- publichealth/home/templatetags/navigation.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index 9b5afe5..21d1d8a 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -77,14 +77,12 @@ def menuitems_children(parent, context=None): menuitems_children = parent.get_children().live().in_menu().specific() items_to_remove = [] for menuitem in menuitems_children: - print('type => %s' % type(menuitem)) try: 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 as ae: - print("Menuitem %s has an issue :: %s" % (menuitem.title, str(ae))) pass for item in items_to_remove: menuitems_children = menuitems_children & Page.objects.not_page(item) @@ -94,7 +92,10 @@ def menuitems_children(parent, context=None): if site.hostname in ['sphc.ch', 'public-health.ch']: print("site is %s, add terms and conditions to footer" % site.hostname) # custom page here is the terms and conditions page for public-health.ch and sphc.ch (common) - custom_page_id = 994 + 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 = list(menuitems_children) menuitems_children.append(custom_page) -- 2.45.2 From 822fca63c3852968ca9fdb680756b33ce2997582 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 16:21:47 +0200 Subject: [PATCH 07/11] Add add_item_to_page_queryset method --- publichealth/home/templatetags/navigation.py | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index 21d1d8a..3bb6ea9 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -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 @@ -98,16 +99,36 @@ def menuitems_children(parent, context=None): custom_page_id = 994 custom_page = Page.objects.get(id=custom_page_id) menuitems_children = list(menuitems_children) - menuitems_children.append(custom_page) + if custom_page not in menuitems_children: + #menuitems_children.append(custom_page) + print("custom_page == ") page_ids = [page.id for page in menuitems_children] + print("hostname is %s" % site.hostname) menuitems_children = Page.objects.filter(id__in=page_ids).specific() for menuitem in menuitems_children: try: menuitem.title = menuitem.trans_title + print(menuitem.title) except AttributeError as aee: pass + menuitems_children = add_item_to_page_queryset(menuitems_children, custom_page) 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): -- 2.45.2 From 87332a9f0532e9f782b970e96efd057af0390e5e Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 19:56:32 +0530 Subject: [PATCH 08/11] Cleanup --- publichealth/home/templatetags/navigation.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index 3bb6ea9..74018dd 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -91,7 +91,6 @@ def menuitems_children(parent, context=None): request = context['request'] site = Site.find_for_request(request) if site.hostname in ['sphc.ch', 'public-health.ch']: - print("site is %s, add terms and conditions to footer" % site.hostname) # 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 @@ -99,11 +98,7 @@ def menuitems_children(parent, context=None): custom_page_id = 994 custom_page = Page.objects.get(id=custom_page_id) menuitems_children = list(menuitems_children) - if custom_page not in menuitems_children: - #menuitems_children.append(custom_page) - print("custom_page == ") page_ids = [page.id for page in menuitems_children] - print("hostname is %s" % site.hostname) menuitems_children = Page.objects.filter(id__in=page_ids).specific() for menuitem in menuitems_children: try: @@ -117,15 +112,12 @@ def menuitems_children(parent, context=None): 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 -- 2.45.2 From 2a6434e569af8f824372cf44f18827a1b3ceb99b Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 20:01:32 +0530 Subject: [PATCH 09/11] Simplify --- publichealth/home/templatetags/navigation.py | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index 74018dd..f1f495b 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -97,16 +97,16 @@ def menuitems_children(parent, context=None): else: custom_page_id = 994 custom_page = Page.objects.get(id=custom_page_id) - menuitems_children = list(menuitems_children) - page_ids = [page.id for page in menuitems_children] - menuitems_children = Page.objects.filter(id__in=page_ids).specific() - for menuitem in menuitems_children: - try: - menuitem.title = menuitem.trans_title - print(menuitem.title) - except AttributeError as aee: - pass + #menuitems_children = list(menuitems_children) + #page_ids = [page.id for page in menuitems_children] + #menuitems_children = Page.objects.filter(id__in=page_ids).specific() menuitems_children = add_item_to_page_queryset(menuitems_children, custom_page) + #for menuitem in menuitems_children: + # try: + # menuitem.title = menuitem.trans_title + # print(menuitem.title) + # except AttributeError as aee: + # pass return menuitems_children def add_item_to_page_queryset(queryset, custom_page): @@ -114,6 +114,11 @@ def add_item_to_page_queryset(queryset, custom_page): pages_list = list(queryset) # Add the custom page to the list pages_list.append(custom_page) + for menuitem in pages_list: + try: + menuitem.title = menuitem.trans_title + except AttributeError as aee: + pass # 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)]) -- 2.45.2 From df467691b8c7bf1ffbce4bf1f4d14b65b5078291 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 20:09:23 +0530 Subject: [PATCH 10/11] More reorganize --- publichealth/home/templatetags/navigation.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index f1f495b..ce74ae3 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -97,16 +97,13 @@ def menuitems_children(parent, context=None): else: custom_page_id = 994 custom_page = Page.objects.get(id=custom_page_id) - #menuitems_children = list(menuitems_children) - #page_ids = [page.id for page in menuitems_children] - #menuitems_children = Page.objects.filter(id__in=page_ids).specific() menuitems_children = add_item_to_page_queryset(menuitems_children, custom_page) - #for menuitem in menuitems_children: - # try: - # menuitem.title = menuitem.trans_title - # print(menuitem.title) - # except AttributeError as aee: - # pass + for menuitem in menuitems_children: + try: + menuitem.title = menuitem.trans_title + print(menuitem.title) + except AttributeError as aee: + pass return menuitems_children def add_item_to_page_queryset(queryset, custom_page): @@ -114,11 +111,6 @@ def add_item_to_page_queryset(queryset, custom_page): pages_list = list(queryset) # Add the custom page to the list pages_list.append(custom_page) - for menuitem in pages_list: - try: - menuitem.title = menuitem.trans_title - except AttributeError as aee: - pass # 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)]) -- 2.45.2 From b3b2a73fc9eea362c59e743a684b1e587acbc257 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 20:13:11 +0530 Subject: [PATCH 11/11] Cleanup --- publichealth/home/templatetags/navigation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index ce74ae3..83d5c08 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -101,7 +101,6 @@ def menuitems_children(parent, context=None): for menuitem in menuitems_children: try: menuitem.title = menuitem.trans_title - print(menuitem.title) except AttributeError as aee: pass return menuitems_children -- 2.45.2