Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyue92tree committed Jul 9, 2019
2 parents b1483dd + 630e1db commit 1d90bee
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 50 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ python manage.py migrate django_admin_settings
## general_option
![general_option](./images/general_option.jpg)

## menu list

![menu list](./images/menu-list.png)


# features

- [Custom General Option](https://django-adminlte-ui.readthedocs.io/en/latest/guide/#general-option)
- [Widgets](https://django-adminlte-ui.readthedocs.io/en/latest/guide/#widgets)
- [Custom Menu](https://django-adminlte-ui.readthedocs.io/en/latest/guide/#menu)

# TODO

- Custom Dashboard


# Thanks

- [AdminLTE](https://github.com/ColorlibHQ/AdminLTE)
Expand Down
2 changes: 1 addition & 1 deletion adminlteui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = '1.3.0b1'
version = '1.3.0'
default_app_config = 'adminlteui.apps.AdminlteUIConfig'
2 changes: 2 additions & 0 deletions adminlteui/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,12 @@ def exchange_menu_view(self, request):
if not use_custom_menu or use_custom_menu.option_value == '0':
use_custom_menu.option_value = '1'
use_custom_menu.save()
messages.add_message(request, messages.SUCCESS, _('Menu exchanged, current is `custom menu`.'))

else:
use_custom_menu.option_value = '0'
use_custom_menu.save()
messages.add_message(request, messages.SUCCESS, _('Menu exchanged, current is `system menu`.'))
return HttpResponse(json.dumps(response_data),
content_type="application/json,charset=utf-8")
return HttpResponse('method not allowed.')
Expand Down
Binary file modified adminlteui/locale/zh-Hans/LC_MESSAGES/django.mo
Binary file not shown.
44 changes: 28 additions & 16 deletions adminlteui/locale/zh-Hans/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-08 21:39+0800\n"
"POT-Creation-Date: 2019-07-09 10:24+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -17,59 +17,67 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: admin.py:52
#: admin.py:51
msgid "Site Title"
msgstr "站点标题"

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

#: admin.py:56
#: admin.py:55
msgid "Site Header"
msgstr "站点标头"

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

#: admin.py:62
#: admin.py:61
msgid "Site Logo"
msgstr "站点logo"

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

#: admin.py:68
#: admin.py:67
msgid "Welcome Sign"
msgstr "欢迎标语"

#: admin.py:70
#: admin.py:69
msgid "Login page welcome sign."
msgstr "登录页面欢迎标语"

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

#: admin.py:186
#: admin.py:185
msgid "General Option Saved."
msgstr "基本设置保存成功。"

#: admin.py:189
#: admin.py:188
msgid "General Option Save Failed."
msgstr "基本设置保存失败。"

#: admin.py:218 admin.py:286 models.py:49
#: admin.py:217 admin.py:287 models.py:49
msgid "ContentType"
msgstr "关联Model"

#: admin.py:270 models.py:41
#: admin.py:245
msgid "Menu exchanged, current is `custom menu`."
msgstr "菜单切换成功,当前为`自定义菜单`"

#: admin.py:250
msgid "Menu exchanged, current is `system menu`."
msgstr "菜单切换成功,当前为`系统菜单`"

#: admin.py:271 models.py:41
msgid "Link"
msgstr "链接"

#: admin.py:278 models.py:46
#: admin.py:279 models.py:46
msgid "Icon"
msgstr "图标"

Expand Down Expand Up @@ -131,6 +139,10 @@ msgstr "菜单位置"
msgid "Link Type"
msgstr "链接类型"

#: models.py:42
msgid "support admin:index or /admin/ or http://"
msgstr "支持 admin:index 或 /admin/ 或 http://"

#: models.py:52
msgid "use for permission control."
msgstr "用于权限控制。"
Expand Down Expand Up @@ -558,7 +570,7 @@ msgstr ""
#: templates/adminlte/general_option.html:14
#: templates/adminlte/general_option.html:18
#: templates/adminlte/general_option.html:27
#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:106
#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:139
msgid "General Option"
msgstr "基本设置"

Expand Down
Binary file modified adminlteui/locale/zh/LC_MESSAGES/django.mo
Binary file not shown.
44 changes: 28 additions & 16 deletions adminlteui/locale/zh/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-08 21:39+0800\n"
"POT-Creation-Date: 2019-07-09 10:24+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -17,59 +17,67 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: admin.py:52
#: admin.py:51
msgid "Site Title"
msgstr "站点标题"

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

#: admin.py:56
#: admin.py:55
msgid "Site Header"
msgstr "站点标头"

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

#: admin.py:62
#: admin.py:61
msgid "Site Logo"
msgstr "站点logo"

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

#: admin.py:68
#: admin.py:67
msgid "Welcome Sign"
msgstr "欢迎标语"

#: admin.py:70
#: admin.py:69
msgid "Login page welcome sign."
msgstr "登录页面欢迎标语"

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

#: admin.py:186
#: admin.py:185
msgid "General Option Saved."
msgstr "基本设置保存成功。"

#: admin.py:189
#: admin.py:188
msgid "General Option Save Failed."
msgstr "基本设置保存失败。"

#: admin.py:218 admin.py:286 models.py:49
#: admin.py:217 admin.py:287 models.py:49
msgid "ContentType"
msgstr "关联Model"

#: admin.py:270 models.py:41
#: admin.py:245
msgid "Menu exchanged, current is `custom menu`."
msgstr "菜单切换成功,当前为`自定义菜单`"

#: admin.py:250
msgid "Menu exchanged, current is `system menu`."
msgstr "菜单切换成功,当前为`系统菜单`"

#: admin.py:271 models.py:41
msgid "Link"
msgstr "链接"

#: admin.py:278 models.py:46
#: admin.py:279 models.py:46
msgid "Icon"
msgstr "图标"

Expand Down Expand Up @@ -131,6 +139,10 @@ msgstr "菜单位置"
msgid "Link Type"
msgstr "链接类型"

#: models.py:42
msgid "support admin:index or /admin/ or http://"
msgstr "支持 admin:index 或 /admin/ 或 http://"

#: models.py:52
msgid "use for permission control."
msgstr "用于权限控制。"
Expand Down Expand Up @@ -558,7 +570,7 @@ msgstr ""
#: templates/adminlte/general_option.html:14
#: templates/adminlte/general_option.html:18
#: templates/adminlte/general_option.html:27
#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:106
#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:139
msgid "General Option"
msgstr "基本设置"

Expand Down
2 changes: 1 addition & 1 deletion adminlteui/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Menu(MP_Node):
verbose_name=_('Link Type'))
link = models.CharField(max_length=255, blank=True, null=True,
verbose_name=_('Link'),
help_text='support admin:index or /admin/ or http://')
help_text=_('support admin:index or /admin/ or http://'))
icon = models.CharField(max_length=255,
blank=True,
null=True,
Expand Down
61 changes: 47 additions & 14 deletions adminlteui/templatetags/adminlte_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib.admin import AdminSite
from django.http import HttpRequest
from django.utils.translation import gettext_lazy as _
from django.contrib.contenttypes.models import ContentType
from adminlteui.templatetags.adminlte_options import get_adminlte_option
from adminlteui.models import Menu

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

def get_custom_menu(available_apps):

def get_custom_menu(request):
"""
use content_type and user.permission control the menu
`label:model`
:param request:
:return:
"""
all_permissions = request.user.get_all_permissions()

limit_for_internal_link = []
for permission in all_permissions:
app_label = permission.split('.')[0]
model = permission.split('.')[1].split('_')[1]
limit_for_internal_link.append('{}:{}'.format(app_label, model))

limit_for_internal_link = set(limit_for_internal_link)
new_available_apps = []
menu = Menu.dump_bulk()
for menu_item in menu:
Expand All @@ -42,28 +61,41 @@ def get_custom_menu(available_apps):
new_available_apps_item['name'] = data.get('name')
new_available_apps_item['icon'] = data.get('icon')

if data.get('link_type') in (0, 1):
new_available_apps_item['admin_url'] = get_reverse_link(
data.get('link'))

children = (menu_item.get('children'))
children = menu_item.get('children')
if not children:
new_available_apps.append(new_available_apps_item)
# skip menu_item that no children and link type is devide.
if data.get('link_type') in (0, 1):
new_available_apps_item['admin_url'] = get_reverse_link(
data.get('link'))
new_available_apps.append(new_available_apps_item)
continue
new_available_apps_item['models'] = []

for children_item in children:
if children_item.get('data').get('link_type') == 0:
# internal link should connect a content_type, otherwise it will be hide.
if children_item.get('data').get('content_type'):
obj = ContentType.objects.get(id=children_item.get('data').get('content_type'))
# if user hasn't permission, the model will be skip.
if obj.app_label + ':' + obj.model not in limit_for_internal_link:
continue
else:
continue

if children_item.get('data').get('valid') is False:
continue
new_children_item = {}
new_children_item = dict()
new_children_item['name'] = children_item.get('data').get('name')
new_children_item['admin_url'] = get_reverse_link(
children_item.get('data').get('link')
)
if not new_children_item['admin_url']:
continue
new_children_item['icon'] = children_item.get('data').get('icon')
# new_children_item['admin_url'] = children_item.get('link')
new_available_apps_item['models'].append(new_children_item)
new_available_apps.append(new_available_apps_item)
if new_available_apps_item['models']:
new_available_apps.append(new_available_apps_item)

return new_available_apps

Expand All @@ -75,6 +107,12 @@ def get_menu(context, request):
"""
if not isinstance(request, HttpRequest):
return None

use_custom_menu = get_adminlte_option('USE_CUSTOM_MENU')
if use_custom_menu.get('USE_CUSTOM_MENU',
'0') == '1' and use_custom_menu.get('valid') is True:
return get_custom_menu(request)

# Django 1.9+
available_apps = context.get('available_apps')
if not available_apps:
Expand All @@ -94,11 +132,6 @@ def get_menu(context, request):
if not available_apps:
logging.warn('adminlteui was unable to retrieve apps list for menu.')

use_custom_menu = get_adminlte_option('USE_CUSTOM_MENU')
if use_custom_menu.get('USE_CUSTOM_MENU',
'0') == '1' and use_custom_menu.get('valid') is True:
return get_custom_menu(available_apps)

for app in available_apps:
if app.get('app_label') == 'django_admin_settings':
app.get('models').insert(0,
Expand Down
12 changes: 12 additions & 0 deletions docs/about.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# ChangeLog

## [v1.3.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.3.0b1)

- add exchange_menu logic with permission limit;
- add message when call exchange menu;
- update docs.

## [v1.3.0b1](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.3.0b1)

- update models, content_type option add null=True;
- add js logic for menu;
- add exchange_menu logic without permission limit.

## [v1.3.0b0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.3.0b0)

- add treebeard as menu depends;
Expand Down
Loading

0 comments on commit 1d90bee

Please sign in to comment.