From 2a6434e569af8f824372cf44f18827a1b3ceb99b Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 19 Jul 2024 20:01:32 +0530 Subject: [PATCH] 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)])