1313
1414from .. import version
1515from ..settings import get_settings , get_ui_tweaks
16- from ..utils import order_with_respect_to , get_filter_id , get_custom_url , get_admin_url , get_model_permissions
16+ from ..utils import order_with_respect_to , get_filter_id , get_custom_url , get_admin_url , get_view_permissions
1717
1818User = get_user_model ()
1919register = Library ()
2020logger = logging .getLogger (__name__ )
21- OPTIONS = get_settings ()
22- UI_TWEAKS = get_ui_tweaks ()
2321
2422
2523@register .simple_tag (takes_context = True )
2624def get_side_menu (context ):
2725 """
2826 Get the list of apps and models to render out in the side menu and on the dashboard page
2927 """
28+
3029 user = context .get ('user' )
3130 if not user :
3231 return []
3332
34- model_permissions = get_model_permissions (user )
33+ model_permissions = get_view_permissions (user )
34+ options = get_settings ()
3535
3636 menu = []
3737 available_apps = copy .deepcopy (context .get ('available_apps' , []))
3838 for app in available_apps :
3939 app_label = app ['app_label' ].lower ()
40- if app_label in OPTIONS ['hide_apps' ]:
40+ if app_label in options ['hide_apps' ]:
4141 continue
4242
4343 allowed_models = []
4444 for model in app .get ('models' , []):
4545 model_str = '{app_label}.{model}' .format (app_label = app_label , model = model ["object_name" ]).lower ()
4646 if model_str not in model_permissions :
4747 continue
48- if model_str in OPTIONS .get ('hide_models' , []):
48+ if model_str in options .get ('hide_models' , []):
4949 continue
5050
51- model ['icon' ] = OPTIONS .get ('icons' , {}).get (model_str )
51+ model ['icon' ] = options .get ('icons' , {}).get (model_str )
5252 allowed_models .append (model )
5353
54- for custom_link in OPTIONS .get ('custom_links' , {}).get (app_label , []):
54+ for custom_link in options .get ('custom_links' , {}).get (app_label , []):
5555
5656 perm_matches = []
5757 for perm in custom_link .get ('permissions' , []):
@@ -71,8 +71,8 @@ def get_side_menu(context):
7171 app ['models' ] = allowed_models
7272 menu .append (app )
7373
74- if OPTIONS .get ('order_with_respect_to' ):
75- menu = order_with_respect_to (menu , OPTIONS ['order_with_respect_to' ])
74+ if options .get ('order_with_respect_to' ):
75+ menu = order_with_respect_to (menu , options ['order_with_respect_to' ])
7676
7777 return menu
7878
@@ -82,10 +82,11 @@ def get_top_menu(user):
8282 if not user :
8383 return []
8484
85- model_permissions = get_model_permissions (user )
85+ model_permissions = get_view_permissions (user )
86+ options = get_settings ()
8687
8788 menu = []
88- for item in get_settings () .get ('topmenu_links' , []):
89+ for item in options .get ('topmenu_links' , []):
8990
9091 perm_matches = []
9192 for perm in item .get ('permissions' , []):
@@ -112,21 +113,15 @@ def get_jazzmin_settings():
112113 """
113114 Return Jazzmin settings
114115 """
115- return OPTIONS
116+ return get_settings ()
116117
117118
118119@register .simple_tag
119120def get_jazzmin_ui_tweaks ():
120121 """
121122 Return Jazzmin ui tweaks
122-
123- Find all the places references in ui-builder.js
124-
125- and get template variables in there
126-
127- ensure we have sane defaults
128123 """
129- return UI_TWEAKS
124+ return get_ui_tweaks ()
130125
131126
132127@register .simple_tag
@@ -143,11 +138,12 @@ def get_user_avatar(user):
143138 For the given user, try to get the avatar image
144139 """
145140 no_avatar = static ("adminlte/img/user2-160x160.jpg" )
141+ options = get_settings ()
146142
147- if not OPTIONS .get ('user_avatar' ):
143+ if not options .get ('user_avatar' ):
148144 return no_avatar
149145
150- avatar_field = getattr (user , OPTIONS ['user_avatar' ], None )
146+ avatar_field = getattr (user , options ['user_avatar' ], None )
151147 if avatar_field :
152148 return avatar_field .url
153149
0 commit comments