Skip to content

Commit 1d90bee

Browse files
committed
Merge branch 'release/1.3.0'
2 parents b1483dd + 630e1db commit 1d90bee

File tree

14 files changed

+199
-50
lines changed

14 files changed

+199
-50
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ python manage.py migrate django_admin_settings
6969
## general_option
7070
![general_option](./images/general_option.jpg)
7171

72+
## menu list
73+
74+
![menu list](./images/menu-list.png)
75+
76+
77+
# features
78+
79+
- [Custom General Option](https://django-adminlte-ui.readthedocs.io/en/latest/guide/#general-option)
80+
- [Widgets](https://django-adminlte-ui.readthedocs.io/en/latest/guide/#widgets)
81+
- [Custom Menu](https://django-adminlte-ui.readthedocs.io/en/latest/guide/#menu)
82+
83+
# TODO
84+
85+
- Custom Dashboard
86+
87+
7288
# Thanks
7389

7490
- [AdminLTE](https://github.com/ColorlibHQ/AdminLTE)

adminlteui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = '1.3.0b1'
1+
version = '1.3.0'
22
default_app_config = 'adminlteui.apps.AdminlteUIConfig'

adminlteui/admin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,12 @@ def exchange_menu_view(self, request):
242242
if not use_custom_menu or use_custom_menu.option_value == '0':
243243
use_custom_menu.option_value = '1'
244244
use_custom_menu.save()
245+
messages.add_message(request, messages.SUCCESS, _('Menu exchanged, current is `custom menu`.'))
245246

246247
else:
247248
use_custom_menu.option_value = '0'
248249
use_custom_menu.save()
250+
messages.add_message(request, messages.SUCCESS, _('Menu exchanged, current is `system menu`.'))
249251
return HttpResponse(json.dumps(response_data),
250252
content_type="application/json,charset=utf-8")
251253
return HttpResponse('method not allowed.')
342 Bytes
Binary file not shown.

adminlteui/locale/zh-Hans/LC_MESSAGES/django.po

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2019-07-08 21:39+0800\n"
11+
"POT-Creation-Date: 2019-07-09 10:24+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,59 +17,67 @@ msgstr ""
1717
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"
1919

20-
#: admin.py:52
20+
#: admin.py:51
2121
msgid "Site Title"
2222
msgstr "站点标题"
2323

24-
#: admin.py:55
24+
#: admin.py:54
2525
msgid "Text to put at the end of each page's tag title."
2626
msgstr "每个页面的标题后缀,对应templates中的site_title标签。"
2727

28-
#: admin.py:56
28+
#: admin.py:55
2929
msgid "Site Header"
3030
msgstr "站点标头"
3131

32-
#: admin.py:59
32+
#: admin.py:58
3333
msgid "Text to put in base page's tag b."
3434
msgstr "右上角文字标头,对应templates中的site_header标签。"
3535

36-
#: admin.py:62
36+
#: admin.py:61
3737
msgid "Site Logo"
3838
msgstr "站点logo"
3939

40-
#: admin.py:66
40+
#: admin.py:65
4141
msgid "Transparent background picture is a good choice."
4242
msgstr "透明背景的图片更适合。"
4343

44-
#: admin.py:68
44+
#: admin.py:67
4545
msgid "Welcome Sign"
4646
msgstr "欢迎标语"
4747

48-
#: admin.py:70
48+
#: admin.py:69
4949
msgid "Login page welcome sign."
5050
msgstr "登录页面欢迎标语"
5151

52-
#: admin.py:88 admin.py:106
52+
#: admin.py:87 admin.py:105
5353
msgid "site_logo depends on setting.MEDIA_URL and setting.MEDIA_ROOT."
5454
msgstr "site_logo依赖于setting.MEDIA_URL和setting.MEDIA_ROOT。"
5555

56-
#: admin.py:186
56+
#: admin.py:185
5757
msgid "General Option Saved."
5858
msgstr "基本设置保存成功。"
5959

60-
#: admin.py:189
60+
#: admin.py:188
6161
msgid "General Option Save Failed."
6262
msgstr "基本设置保存失败。"
6363

64-
#: admin.py:218 admin.py:286 models.py:49
64+
#: admin.py:217 admin.py:287 models.py:49
6565
msgid "ContentType"
6666
msgstr "关联Model"
6767

68-
#: admin.py:270 models.py:41
68+
#: admin.py:245
69+
msgid "Menu exchanged, current is `custom menu`."
70+
msgstr "菜单切换成功,当前为`自定义菜单`"
71+
72+
#: admin.py:250
73+
msgid "Menu exchanged, current is `system menu`."
74+
msgstr "菜单切换成功,当前为`系统菜单`"
75+
76+
#: admin.py:271 models.py:41
6977
msgid "Link"
7078
msgstr "链接"
7179

72-
#: admin.py:278 models.py:46
80+
#: admin.py:279 models.py:46
7381
msgid "Icon"
7482
msgstr "图标"
7583

@@ -131,6 +139,10 @@ msgstr "菜单位置"
131139
msgid "Link Type"
132140
msgstr "链接类型"
133141

142+
#: models.py:42
143+
msgid "support admin:index or /admin/ or http://"
144+
msgstr "支持 admin:index 或 /admin/ 或 http://"
145+
134146
#: models.py:52
135147
msgid "use for permission control."
136148
msgstr "用于权限控制。"
@@ -558,7 +570,7 @@ msgstr ""
558570
#: templates/adminlte/general_option.html:14
559571
#: templates/adminlte/general_option.html:18
560572
#: templates/adminlte/general_option.html:27
561-
#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:106
573+
#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:139
562574
msgid "General Option"
563575
msgstr "基本设置"
564576

342 Bytes
Binary file not shown.

adminlteui/locale/zh/LC_MESSAGES/django.po

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2019-07-08 21:39+0800\n"
11+
"POT-Creation-Date: 2019-07-09 10:24+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,59 +17,67 @@ msgstr ""
1717
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"
1919

20-
#: admin.py:52
20+
#: admin.py:51
2121
msgid "Site Title"
2222
msgstr "站点标题"
2323

24-
#: admin.py:55
24+
#: admin.py:54
2525
msgid "Text to put at the end of each page's tag title."
2626
msgstr "每个页面的标题后缀,对应templates中的site_title标签。"
2727

28-
#: admin.py:56
28+
#: admin.py:55
2929
msgid "Site Header"
3030
msgstr "站点标头"
3131

32-
#: admin.py:59
32+
#: admin.py:58
3333
msgid "Text to put in base page's tag b."
3434
msgstr "右上角文字标头,对应templates中的site_header标签。"
3535

36-
#: admin.py:62
36+
#: admin.py:61
3737
msgid "Site Logo"
3838
msgstr "站点logo"
3939

40-
#: admin.py:66
40+
#: admin.py:65
4141
msgid "Transparent background picture is a good choice."
4242
msgstr "透明背景的图片更适合。"
4343

44-
#: admin.py:68
44+
#: admin.py:67
4545
msgid "Welcome Sign"
4646
msgstr "欢迎标语"
4747

48-
#: admin.py:70
48+
#: admin.py:69
4949
msgid "Login page welcome sign."
5050
msgstr "登录页面欢迎标语"
5151

52-
#: admin.py:88 admin.py:106
52+
#: admin.py:87 admin.py:105
5353
msgid "site_logo depends on setting.MEDIA_URL and setting.MEDIA_ROOT."
5454
msgstr "site_logo依赖于setting.MEDIA_URL和setting.MEDIA_ROOT。"
5555

56-
#: admin.py:186
56+
#: admin.py:185
5757
msgid "General Option Saved."
5858
msgstr "基本设置保存成功。"
5959

60-
#: admin.py:189
60+
#: admin.py:188
6161
msgid "General Option Save Failed."
6262
msgstr "基本设置保存失败。"
6363

64-
#: admin.py:218 admin.py:286 models.py:49
64+
#: admin.py:217 admin.py:287 models.py:49
6565
msgid "ContentType"
6666
msgstr "关联Model"
6767

68-
#: admin.py:270 models.py:41
68+
#: admin.py:245
69+
msgid "Menu exchanged, current is `custom menu`."
70+
msgstr "菜单切换成功,当前为`自定义菜单`"
71+
72+
#: admin.py:250
73+
msgid "Menu exchanged, current is `system menu`."
74+
msgstr "菜单切换成功,当前为`系统菜单`"
75+
76+
#: admin.py:271 models.py:41
6977
msgid "Link"
7078
msgstr "链接"
7179

72-
#: admin.py:278 models.py:46
80+
#: admin.py:279 models.py:46
7381
msgid "Icon"
7482
msgstr "图标"
7583

@@ -131,6 +139,10 @@ msgstr "菜单位置"
131139
msgid "Link Type"
132140
msgstr "链接类型"
133141

142+
#: models.py:42
143+
msgid "support admin:index or /admin/ or http://"
144+
msgstr "支持 admin:index 或 /admin/ 或 http://"
145+
134146
#: models.py:52
135147
msgid "use for permission control."
136148
msgstr "用于权限控制。"
@@ -558,7 +570,7 @@ msgstr ""
558570
#: templates/adminlte/general_option.html:14
559571
#: templates/adminlte/general_option.html:18
560572
#: templates/adminlte/general_option.html:27
561-
#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:106
573+
#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:139
562574
msgid "General Option"
563575
msgstr "基本设置"
564576

adminlteui/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Menu(MP_Node):
3939
verbose_name=_('Link Type'))
4040
link = models.CharField(max_length=255, blank=True, null=True,
4141
verbose_name=_('Link'),
42-
help_text='support admin:index or /admin/ or http://')
42+
help_text=_('support admin:index or /admin/ or http://'))
4343
icon = models.CharField(max_length=255,
4444
blank=True,
4545
null=True,

adminlteui/templatetags/adminlte_menu.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.contrib.admin import AdminSite
66
from django.http import HttpRequest
77
from django.utils.translation import gettext_lazy as _
8+
from django.contrib.contenttypes.models import ContentType
89
from adminlteui.templatetags.adminlte_options import get_adminlte_option
910
from adminlteui.models import Menu
1011

@@ -30,7 +31,25 @@ def get_reverse_link(link):
3031
except Exception as e:
3132
return None
3233

33-
def get_custom_menu(available_apps):
34+
35+
def get_custom_menu(request):
36+
"""
37+
use content_type and user.permission control the menu
38+
39+
`label:model`
40+
41+
:param request:
42+
:return:
43+
"""
44+
all_permissions = request.user.get_all_permissions()
45+
46+
limit_for_internal_link = []
47+
for permission in all_permissions:
48+
app_label = permission.split('.')[0]
49+
model = permission.split('.')[1].split('_')[1]
50+
limit_for_internal_link.append('{}:{}'.format(app_label, model))
51+
52+
limit_for_internal_link = set(limit_for_internal_link)
3453
new_available_apps = []
3554
menu = Menu.dump_bulk()
3655
for menu_item in menu:
@@ -42,28 +61,41 @@ def get_custom_menu(available_apps):
4261
new_available_apps_item['name'] = data.get('name')
4362
new_available_apps_item['icon'] = data.get('icon')
4463

45-
if data.get('link_type') in (0, 1):
46-
new_available_apps_item['admin_url'] = get_reverse_link(
47-
data.get('link'))
48-
49-
children = (menu_item.get('children'))
64+
children = menu_item.get('children')
5065
if not children:
51-
new_available_apps.append(new_available_apps_item)
66+
# skip menu_item that no children and link type is devide.
67+
if data.get('link_type') in (0, 1):
68+
new_available_apps_item['admin_url'] = get_reverse_link(
69+
data.get('link'))
70+
new_available_apps.append(new_available_apps_item)
5271
continue
5372
new_available_apps_item['models'] = []
5473

5574
for children_item in children:
75+
if children_item.get('data').get('link_type') == 0:
76+
# internal link should connect a content_type, otherwise it will be hide.
77+
if children_item.get('data').get('content_type'):
78+
obj = ContentType.objects.get(id=children_item.get('data').get('content_type'))
79+
# if user hasn't permission, the model will be skip.
80+
if obj.app_label + ':' + obj.model not in limit_for_internal_link:
81+
continue
82+
else:
83+
continue
84+
5685
if children_item.get('data').get('valid') is False:
5786
continue
58-
new_children_item = {}
87+
new_children_item = dict()
5988
new_children_item['name'] = children_item.get('data').get('name')
6089
new_children_item['admin_url'] = get_reverse_link(
6190
children_item.get('data').get('link')
6291
)
92+
if not new_children_item['admin_url']:
93+
continue
6394
new_children_item['icon'] = children_item.get('data').get('icon')
6495
# new_children_item['admin_url'] = children_item.get('link')
6596
new_available_apps_item['models'].append(new_children_item)
66-
new_available_apps.append(new_available_apps_item)
97+
if new_available_apps_item['models']:
98+
new_available_apps.append(new_available_apps_item)
6799

68100
return new_available_apps
69101

@@ -75,6 +107,12 @@ def get_menu(context, request):
75107
"""
76108
if not isinstance(request, HttpRequest):
77109
return None
110+
111+
use_custom_menu = get_adminlte_option('USE_CUSTOM_MENU')
112+
if use_custom_menu.get('USE_CUSTOM_MENU',
113+
'0') == '1' and use_custom_menu.get('valid') is True:
114+
return get_custom_menu(request)
115+
78116
# Django 1.9+
79117
available_apps = context.get('available_apps')
80118
if not available_apps:
@@ -94,11 +132,6 @@ def get_menu(context, request):
94132
if not available_apps:
95133
logging.warn('adminlteui was unable to retrieve apps list for menu.')
96134

97-
use_custom_menu = get_adminlte_option('USE_CUSTOM_MENU')
98-
if use_custom_menu.get('USE_CUSTOM_MENU',
99-
'0') == '1' and use_custom_menu.get('valid') is True:
100-
return get_custom_menu(available_apps)
101-
102135
for app in available_apps:
103136
if app.get('app_label') == 'django_admin_settings':
104137
app.get('models').insert(0,

docs/about.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# ChangeLog
22

3+
## [v1.3.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.3.0b1)
4+
5+
- add exchange_menu logic with permission limit;
6+
- add message when call exchange menu;
7+
- update docs.
8+
9+
## [v1.3.0b1](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.3.0b1)
10+
11+
- update models, content_type option add null=True;
12+
- add js logic for menu;
13+
- add exchange_menu logic without permission limit.
14+
315
## [v1.3.0b0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.3.0b0)
416

517
- add treebeard as menu depends;

0 commit comments

Comments
 (0)