File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import django
44from django .core .exceptions import ImproperlyConfigured
5- from .utils import get_callable , parse_url
5+ from .utils import get_callable , parse_url , path_startswith
66
77if django .VERSION >= (1 , 10 ): # pragma: no cover
88 from django .urls import reverse , NoReverseMatch
@@ -91,14 +91,14 @@ def _is_selected(self, item_dict):
9191 If related URLS are given, it also returns true if one of the related URLS is part of path.
9292 """
9393 url = self ._get_url (item_dict )
94- if self ._is_root (item_dict ) and url in self .path :
94+ if self ._is_root (item_dict ) and path_startswith ( self .path , url ) :
9595 return True
9696 elif url == self .path :
9797 return True
9898 else :
9999 # Go through all related URLs and test
100100 for related_url in self ._get_related_urls (item_dict ):
101- if related_url in self .path :
101+ if path_startswith ( self .path , related_url ) :
102102 return True
103103 return False
104104
Original file line number Diff line number Diff line change @@ -52,3 +52,13 @@ def parse_url(url):
5252 except NoReverseMatch :
5353 final_url = url
5454 return final_url
55+
56+
57+ def path_startswith (path , prefix ):
58+ """
59+ Returns True if the leftmost path components are the same as prefix.
60+ """
61+ path_components = path .strip ("/" ).split ("/" )
62+ prefix_components = prefix .strip ("/" ).split ("/" )
63+
64+ return path_components [:len (prefix_components )] == prefix_components
You can’t perform that action at this time.
0 commit comments