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
17ab618f
Commit
17ab618f
authored
7 years ago
by
yamijuan
Browse files
Options
Downloads
Patches
Plain Diff
Added support to AppConfig notation in INSTALLED_APPS settings
parent
dd3559f6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
menu_generator/templatetags/utils.py
+3
-2
3 additions, 2 deletions
menu_generator/templatetags/utils.py
menu_generator/tests/testsettings.py
+1
-1
1 addition, 1 deletion
menu_generator/tests/testsettings.py
menu_generator/utils.py
+22
-0
22 additions, 0 deletions
menu_generator/utils.py
with
26 additions
and
3 deletions
menu_generator/templatetags/utils.py
+
3
−
2
View file @
17ab618f
from
django.conf
import
settings
from
..utils
import
get_callable
from
..utils
import
get_callable
,
clean_app_config
MENU_DICT
=
"
.menus.MENUS
"
...
...
@@ -14,8 +14,9 @@ def get_menu_from_apps(menu_name):
installed_apps
=
getattr
(
settings
,
"
INSTALLED_APPS
"
,
[])
menu_list
=
[]
for
app
in
installed_apps
:
cleaned_app
=
clean_app_config
(
app
)
try
:
all_menus_dict
=
get_callable
(
app
+
MENU_DICT
)
all_menus_dict
=
get_callable
(
cleaned_
app
+
MENU_DICT
)
except
ImportError
:
all_menus_dict
=
None
except
AttributeError
:
...
...
This diff is collapsed.
Click to expand it.
menu_generator/tests/testsettings.py
+
1
−
1
View file @
17ab618f
...
...
@@ -7,7 +7,7 @@ DATABASES = {
SECRET_KEY
=
"
r4dy
"
INSTALLED_APPS
=
[
'
menu_generator
'
,
'
menu_generator.tests.test_apps.app1
'
,
'
menu_generator.tests.test_apps.app1
.apps.MyAppConfig
'
,
'
menu_generator.tests.test_apps.app2
'
,
'
menu_generator.tests.test_apps.app3
'
]
...
...
This diff is collapsed.
Click to expand it.
menu_generator/utils.py
+
22
−
0
View file @
17ab618f
from
importlib
import
import_module
from
django.apps
import
apps
from
django.core.exceptions
import
ImproperlyConfigured
def
get_callable
(
func_or_path
):
"""
...
...
@@ -13,3 +16,22 @@ def get_callable(func_or_path):
_module
=
import_module
(
module_name
)
func
=
getattr
(
_module
,
function_name
)
return
func
def
clean_app_config
(
app_path
):
"""
Removes the AppConfig path for this app and returns the new string
"""
apps_names
=
[
app
.
name
for
app
in
apps
.
get_app_configs
()]
if
app_path
in
apps_names
:
return
app_path
else
:
app_split
=
app_path
.
split
(
'
.
'
)
new_app
=
'
.
'
.
join
(
app_split
[:
len
(
app_split
)
-
2
])
if
new_app
in
apps_names
:
return
new_app
else
:
raise
ImproperlyConfigured
(
"
The application {0} is not in the configured apps or does
"
+
"
not have the pattern app.apps.AppConfig
"
.
format
(
app_path
)
)
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