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
20b28c69
Verified
Commit
20b28c69
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Implement related views
parent
e0d733a3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
menu_generator/menu.py
+13
-2
13 additions, 2 deletions
menu_generator/menu.py
with
13 additions
and
2 deletions
menu_generator/menu.py
+
13
−
2
View file @
20b28c69
...
...
@@ -5,9 +5,9 @@ from django.core.exceptions import ImproperlyConfigured
from
.utils
import
get_callable
,
parse_url
if
django
.
VERSION
>=
(
1
,
10
):
# pragma: no cover
from
django.urls
import
reverse
,
NoReverseMatch
from
django.urls
import
resolve
,
reverse
,
NoReverseMatch
else
:
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
from
django.core.urlresolvers
import
resolve
,
reverse
,
NoReverseMatch
class
MenuBase
(
object
):
...
...
@@ -83,12 +83,20 @@ class MenuBase(object):
related_urls
=
item_dict
.
get
(
'
related_urls
'
,
[])
return
[
parse_url
(
url
)
for
url
in
related_urls
]
def
_get_related_views
(
self
,
item_dict
):
"""
Given a menu item dictionary, it returns the relateds viewss or an empty list.
"""
related_views
=
item_dict
.
get
(
'
related_views
'
,
[])
return
related_views
def
_is_selected
(
self
,
item_dict
):
"""
Given a menu item dictionary, it returns true if `url` is on path,
unless the item is marked as a root, in which case returns true if `url` is part of path.
If related URLS are given, it also returns true if one of the related URLS is part of path.
If related views are given, it also returns true if the path maps to one of these views.
"""
url
=
self
.
_get_url
(
item_dict
)
if
self
.
_is_root
(
item_dict
)
and
url
in
self
.
path
:
...
...
@@ -100,6 +108,9 @@ class MenuBase(object):
for
related_url
in
self
.
_get_related_urls
(
item_dict
):
if
related_url
in
self
.
path
:
return
True
# Resolve URL and check if it relates to a related views
if
resolve
(
self
.
path
).
func
in
self
.
_get_related_views
(
item_dict
):
return
True
return
False
def
_is_root
(
self
,
item_dict
):
...
...
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