Browse Source

Use url_path to check for descendant pages in navigation tags

This ensures that they continue working on pages that have no routable URL. Fixes #180
Matt Westcott 7 years ago
parent
commit
df1257ef2b
1 changed files with 3 additions and 3 deletions
  1. 3 3
      bakerydemo/base/templatetags/navigation_tags.py

+ 3 - 3
bakerydemo/base/templatetags/navigation_tags.py

@@ -31,7 +31,7 @@ def has_children(page):
 
 def is_active(page, current_page):
     # To give us active state on main navigation
-    return (current_page.url.startswith(page.url) if current_page else False)
+    return (current_page.url_path.startswith(page.url_path) if current_page else False)
 
 
 # Retrieves the top menu items - the immediate children of the parent page
@@ -45,7 +45,7 @@ def top_menu(context, parent, calling_page=None):
         # We don't directly check if calling_page is None since the template
         # engine can pass an empty string to calling_page
         # if the variable passed as calling_page does not exist.
-        menuitem.active = (calling_page.url.startswith(menuitem.url)
+        menuitem.active = (calling_page.url_path.startswith(menuitem.url_path)
                            if calling_page else False)
     return {
         'calling_page': calling_page,
@@ -65,7 +65,7 @@ def top_menu_children(context, parent, calling_page=None):
         # We don't directly check if calling_page is None since the template
         # engine can pass an empty string to calling_page
         # if the variable passed as calling_page does not exist.
-        menuitem.active = (calling_page.url.startswith(menuitem.url)
+        menuitem.active = (calling_page.url_path.startswith(menuitem.url_path)
                            if calling_page else False)
         menuitem.children = menuitem.get_children().live().in_menu()
     return {