This commit is contained in:
PCoder 2024-07-19 20:01:32 +05:30
parent 87332a9f05
commit 2a6434e569

View file

@ -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)])