Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django-menu-generator-ng
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
AlekSIS®
Libraries
django-menu-generator-ng
Commits
c58b8dcd
Verified
Commit
c58b8dcd
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'natureshadow/patch-2'
parents
d99c3c00
f77cc68f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
menu_generator/menu.py
+3
-3
3 additions, 3 deletions
menu_generator/menu.py
menu_generator/utils.py
+10
-0
10 additions, 0 deletions
menu_generator/utils.py
with
13 additions
and
3 deletions
menu_generator/menu.py
+
3
−
3
View file @
c58b8dcd
...
...
@@ -2,7 +2,7 @@ import copy
import
django
from
django.core.exceptions
import
ImproperlyConfigured
from
.utils
import
get_callable
,
parse_url
from
.utils
import
get_callable
,
parse_url
,
path_startswith
if
django
.
VERSION
>=
(
1
,
10
):
# pragma: no cover
from
django.urls
import
reverse
,
NoReverseMatch
...
...
@@ -91,14 +91,14 @@ class MenuBase(object):
If related URLS are given, it also returns true if one of the related URLS is part of path.
"""
url
=
self
.
_get_url
(
item_dict
)
if
self
.
_is_root
(
item_dict
)
and
url
in
self
.
path
:
if
self
.
_is_root
(
item_dict
)
and
path_startswith
(
self
.
path
,
url
)
:
return
True
elif
url
==
self
.
path
:
return
True
else
:
# Go through all related URLs and test
for
related_url
in
self
.
_get_related_urls
(
item_dict
):
if
related_url
in
self
.
path
:
if
path_startswith
(
self
.
path
,
related_url
)
:
return
True
return
False
...
...
This diff is collapsed.
Click to expand it.
menu_generator/utils.py
+
10
−
0
View file @
c58b8dcd
...
...
@@ -52,3 +52,13 @@ def parse_url(url):
except
NoReverseMatch
:
final_url
=
url
return
final_url
def
path_startswith
(
path
,
prefix
):
"""
Returns True if the leftmost path components are the same as prefix.
"""
path_components
=
path
.
strip
(
"
/
"
).
split
(
"
/
"
)
prefix_components
=
prefix
.
strip
(
"
/
"
).
split
(
"
/
"
)
return
path_components
[:
len
(
prefix_components
)]
==
prefix_components
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment