diff --git a/README.md b/README.md index 43f11c4..326c735 100644 --- a/README.md +++ b/README.md @@ -9,24 +9,36 @@ [![Download Status](https://img.shields.io/pypi/dm/django-adminlte-ui.svg)](https://pypi.python.org/pypi/django-adminlte-ui) [![Build Status](https://api.travis-ci.org/wuyue92tree/django-adminlte-ui.svg)](https://travis-ci.org/wuyue92tree/django-adminlte-ui) [![Documentation Status](https://readthedocs.org/projects/django-adminlte-ui/badge/?version=latest)](https://django-adminlte-ui.readthedocs.io/en/latest/?badge=latest) +[![Gitter](https://badges.gitter.im/django-adminlte-ui/community.svg)](https://gitter.im/django-adminlte-ui/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) django admin theme base on adminlte adminlte version: 2.3.6 -# helper +# Helper - if you have good ideas, just contact me. - if you find some bug, just add an issue. - if you think this project is good, just star and fork, make it better 🍉. -# install +# Demo + +[Chinese](http://django-demo.antio.top/zh-hans/admin/) + +[English](http://django-demo.antio.top/en/admin/) + +- username: demo +- password: demo123 + +database will restore every hour. 🍌 + +# Install ``` pip install django-adminlte-ui ``` -# setup +# Setup ``` # settings.py @@ -52,7 +64,7 @@ INSTALLED_APPS = [ python manage.py migrate django_admin_settings ``` -# screen shot +# Screen shot ## login page ![login](./images/login.jpg) @@ -74,13 +86,13 @@ python manage.py migrate django_admin_settings ![menu list](./images/menu-list.png) -# features +# 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 +# Todo - Custom Dashboard diff --git a/adminlteui/__init__.py b/adminlteui/__init__.py index c17da02..ae332fe 100644 --- a/adminlteui/__init__.py +++ b/adminlteui/__init__.py @@ -1,2 +1,2 @@ -version = '1.3.1' +version = '1.3.2' default_app_config = 'adminlteui.apps.AdminlteUIConfig' diff --git a/adminlteui/admin.py b/adminlteui/admin.py index 89ef7a0..d29fce7 100644 --- a/adminlteui/admin.py +++ b/adminlteui/admin.py @@ -10,7 +10,7 @@ from django.utils.translation import gettext_lazy as _ from django.utils.html import format_html from django.conf import settings -from django.http.response import HttpResponse +from django.http.response import HttpResponse, HttpResponseForbidden from adminlteui.widgets import AdminlteSelect from treebeard.admin import TreeAdmin from treebeard.forms import movenodeform_factory @@ -69,6 +69,14 @@ class GeneralOptionForm(forms.Form): help_text=_("Login page welcome sign.") ) + avatar_field = forms.CharField(label=_('Avatar Field'), + widget=widgets.AdminTextInputWidget(), + required=False, + help_text=_( + "which field is avatar.")) + show_avatar = forms.BooleanField( + label=_('Show Avatar'), required=False) + def save(self): try: # clear site-logo @@ -77,6 +85,16 @@ def save(self): obj.delete() self.changed_data.remove('site_logo') + if not self.data.get('show_avatar'): + try: + obj = Options.objects.get(option_name='show_avatar') + obj.option_value = 'off' + obj.save() + except Exception: + obj = Options.objects.create(option_name='show_avatar', + option_value='off') + obj.save() + for data_item in self.changed_data: try: obj = Options.objects.get(option_name=data_item) @@ -144,6 +162,11 @@ def get_urls(self): return urls + base_urls def general_option_view(self, request): + if request.user.has_perm('django_admin_settings.add_options') is False \ + and request.user.has_perm( + 'django_admin_settings.change_options') is False: + return HttpResponseForbidden(format_html('

403 Forbidden

')) + context = dict( self.admin_site.each_context(request), ) @@ -159,7 +182,11 @@ def general_option_view(self, request): 'welcome_sign': get_option(option_name='welcome_sign'), 'site_logo': ImageBox( get_option(option_name='site_logo')) if get_option( - option_name='site_logo') else '' + option_name='site_logo') else '', + 'show_avatar': True if get_option( + option_name='show_avatar') == 'on' else False, + 'avatar_field': get_option( + option_name='avatar_field') or 'request.user.head_avatar', } form = GeneralOptionForm(initial=initial_value) else: @@ -178,7 +205,11 @@ def general_option_view(self, request): 'welcome_sign': get_option(option_name='welcome_sign'), 'site_logo': ImageBox( get_option(option_name='site_logo')) if get_option( - option_name='site_logo') else '' + option_name='site_logo') else '', + 'show_avatar': True if get_option( + option_name='show_avatar') == 'on' else False, + 'avatar_field': get_option( + option_name='avatar_field') or 'request.user.head_avatar', } form = GeneralOptionForm(initial=initial_value) messages.add_message(request, messages.SUCCESS, @@ -230,6 +261,8 @@ def get_urls(self): return urls + base_urls def exchange_menu_view(self, request): + if request.user.has_perm('django_admin_settings.view_menu') is False: + return HttpResponseForbidden(format_html('

403 Forbidden

')) if request.is_ajax(): response_data = dict() response_data['message'] = 'success' @@ -244,12 +277,14 @@ 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`.')) + 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`.')) + 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.') diff --git a/adminlteui/locale/zh-Hans/LC_MESSAGES/django.mo b/adminlteui/locale/zh-Hans/LC_MESSAGES/django.mo index 817e990..a44bb92 100644 Binary files a/adminlteui/locale/zh-Hans/LC_MESSAGES/django.mo and b/adminlteui/locale/zh-Hans/LC_MESSAGES/django.mo differ diff --git a/adminlteui/locale/zh-Hans/LC_MESSAGES/django.po b/adminlteui/locale/zh-Hans/LC_MESSAGES/django.po index 9d6991c..8761cff 100644 --- a/adminlteui/locale/zh-Hans/LC_MESSAGES/django.po +++ b/adminlteui/locale/zh-Hans/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 10:24+0800\n" +"POT-Creation-Date: 2019-07-10 22:14+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -49,35 +49,47 @@ msgstr "欢迎标语" msgid "Login page welcome sign." msgstr "登录页面欢迎标语" -#: admin.py:87 admin.py:105 +#: admin.py:72 +msgid "Avatar Field" +msgstr "头像字段" + +#: admin.py:76 +msgid "which field is avatar." +msgstr "用户表中头像对应的字段" + +#: admin.py:78 +msgid "Show Avatar" +msgstr "显示头像" + +#: admin.py:105 admin.py:123 msgid "site_logo depends on setting.MEDIA_URL and setting.MEDIA_ROOT." msgstr "site_logo依赖于setting.MEDIA_URL和setting.MEDIA_ROOT。" -#: admin.py:185 +#: admin.py:216 msgid "General Option Saved." msgstr "基本设置保存成功。" -#: admin.py:188 +#: admin.py:219 msgid "General Option Save Failed." msgstr "基本设置保存失败。" -#: admin.py:217 admin.py:287 models.py:49 +#: admin.py:248 admin.py:324 models.py:49 msgid "ContentType" msgstr "关联Model" -#: admin.py:245 +#: admin.py:281 msgid "Menu exchanged, current is `custom menu`." msgstr "菜单切换成功,当前为`自定义菜单`" -#: admin.py:250 +#: admin.py:287 msgid "Menu exchanged, current is `system menu`." msgstr "菜单切换成功,当前为`系统菜单`" -#: admin.py:271 models.py:41 +#: admin.py:308 models.py:41 msgid "Link" msgstr "链接" -#: admin.py:279 models.py:46 +#: admin.py:316 models.py:46 msgid "Icon" msgstr "图标" @@ -227,7 +239,7 @@ msgstr "" #: templates/admin/auth/user/change_password.html:22 #: templates/admin/auth/user/change_password.html:27 #: templates/admin/auth/user/change_password.html:94 -#: templates/admin/base.html:119 +#: templates/admin/base.html:151 #: templates/registration/password_change_done.html:3 #: templates/registration/password_change_form.html:7 #: templates/registration/password_change_form.html:102 @@ -251,66 +263,67 @@ msgstr "" msgid "Please correct the errors below." msgstr "" -#: templates/admin/base.html:90 +#: templates/admin/base.html:104 templates/admin/base.html:120 msgid "Super manager" msgstr "超级管理员" -#: templates/admin/base.html:95 +#: templates/admin/base.html:109 templates/admin/base.html:125 msgid "Normal" msgstr "普通用户" -#: templates/admin/base.html:98 +#: templates/admin/base.html:112 templates/admin/base.html:128 msgid "Register time" msgstr "注册时间" -#: templates/admin/base.html:122 +#: templates/admin/base.html:154 #: templates/registration/password_change_done.html:3 #: templates/registration/password_change_form.html:7 msgid "Log out" msgstr "" -#: templates/admin/base.html:146 +#: templates/admin/base.html:185 msgid "Online" msgstr "在线" -#: templates/admin/base.html:152 templates/admin/search_form.html:20 +#: templates/admin/base.html:192 templates/admin/search_form.html:20 msgid "Search" msgstr "搜索" -#: templates/admin/base.html:162 +#: templates/admin/base.html:202 msgid "MAIN NAVIGATION" msgstr "页面导航" -#: templates/admin/base.html:165 +#: templates/admin/base.html:205 msgid "Dashboard" msgstr "仪表盘" -#: templates/admin/base.html:197 +#: templates/admin/base.html:237 msgid "System manage" msgstr "" -#: templates/admin/base.html:203 +#: templates/admin/base.html:243 msgid "Log manage" msgstr "" -#: templates/admin/base.html:204 +#: templates/admin/base.html:244 msgid "System config" msgstr "" -#: templates/admin/base.html:210 +#: templates/admin/base.html:250 msgid "Important" msgstr "" -#: templates/admin/base.html:211 +#: templates/admin/base.html:251 msgid "Warning" msgstr "" -#: templates/admin/base.html:212 +#: templates/admin/base.html:252 msgid "Information" msgstr "" #: templates/admin/base_site.html:8 templates/admin/login.html:13 #: templates/adminlte/general_option.html:23 +#: templates/registration/logged_out.html:13 msgid "Django site admin" msgstr "" @@ -466,7 +479,7 @@ msgstr "" msgid "Log in" msgstr "登录" -#: templates/admin/login.html:60 +#: templates/admin/login.html:60 templates/registration/logged_out.html:58 msgid "Login and Enjoy" msgstr "芝麻开门" @@ -570,7 +583,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:139 +#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:142 msgid "General Option" msgstr "基本设置" @@ -578,6 +591,17 @@ msgstr "基本设置" msgid "Exchange Menu" msgstr "菜单切换" +#: templates/registration/logged_out.html:15 +#: templates/registration/logged_out.html:63 +#, fuzzy +#| msgid "Log in" +msgid "Log in again" +msgstr "登录" + +#: templates/registration/logged_out.html:61 +msgid "Thanks for spending some quality time with the Web site today." +msgstr "" + #: templates/registration/password_change_done.html:3 #: templates/registration/password_change_form.html:7 msgid "Documentation" diff --git a/adminlteui/locale/zh/LC_MESSAGES/django.mo b/adminlteui/locale/zh/LC_MESSAGES/django.mo index 817e990..a44bb92 100644 Binary files a/adminlteui/locale/zh/LC_MESSAGES/django.mo and b/adminlteui/locale/zh/LC_MESSAGES/django.mo differ diff --git a/adminlteui/locale/zh/LC_MESSAGES/django.po b/adminlteui/locale/zh/LC_MESSAGES/django.po index 9d6991c..8761cff 100644 --- a/adminlteui/locale/zh/LC_MESSAGES/django.po +++ b/adminlteui/locale/zh/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 10:24+0800\n" +"POT-Creation-Date: 2019-07-10 22:14+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -49,35 +49,47 @@ msgstr "欢迎标语" msgid "Login page welcome sign." msgstr "登录页面欢迎标语" -#: admin.py:87 admin.py:105 +#: admin.py:72 +msgid "Avatar Field" +msgstr "头像字段" + +#: admin.py:76 +msgid "which field is avatar." +msgstr "用户表中头像对应的字段" + +#: admin.py:78 +msgid "Show Avatar" +msgstr "显示头像" + +#: admin.py:105 admin.py:123 msgid "site_logo depends on setting.MEDIA_URL and setting.MEDIA_ROOT." msgstr "site_logo依赖于setting.MEDIA_URL和setting.MEDIA_ROOT。" -#: admin.py:185 +#: admin.py:216 msgid "General Option Saved." msgstr "基本设置保存成功。" -#: admin.py:188 +#: admin.py:219 msgid "General Option Save Failed." msgstr "基本设置保存失败。" -#: admin.py:217 admin.py:287 models.py:49 +#: admin.py:248 admin.py:324 models.py:49 msgid "ContentType" msgstr "关联Model" -#: admin.py:245 +#: admin.py:281 msgid "Menu exchanged, current is `custom menu`." msgstr "菜单切换成功,当前为`自定义菜单`" -#: admin.py:250 +#: admin.py:287 msgid "Menu exchanged, current is `system menu`." msgstr "菜单切换成功,当前为`系统菜单`" -#: admin.py:271 models.py:41 +#: admin.py:308 models.py:41 msgid "Link" msgstr "链接" -#: admin.py:279 models.py:46 +#: admin.py:316 models.py:46 msgid "Icon" msgstr "图标" @@ -227,7 +239,7 @@ msgstr "" #: templates/admin/auth/user/change_password.html:22 #: templates/admin/auth/user/change_password.html:27 #: templates/admin/auth/user/change_password.html:94 -#: templates/admin/base.html:119 +#: templates/admin/base.html:151 #: templates/registration/password_change_done.html:3 #: templates/registration/password_change_form.html:7 #: templates/registration/password_change_form.html:102 @@ -251,66 +263,67 @@ msgstr "" msgid "Please correct the errors below." msgstr "" -#: templates/admin/base.html:90 +#: templates/admin/base.html:104 templates/admin/base.html:120 msgid "Super manager" msgstr "超级管理员" -#: templates/admin/base.html:95 +#: templates/admin/base.html:109 templates/admin/base.html:125 msgid "Normal" msgstr "普通用户" -#: templates/admin/base.html:98 +#: templates/admin/base.html:112 templates/admin/base.html:128 msgid "Register time" msgstr "注册时间" -#: templates/admin/base.html:122 +#: templates/admin/base.html:154 #: templates/registration/password_change_done.html:3 #: templates/registration/password_change_form.html:7 msgid "Log out" msgstr "" -#: templates/admin/base.html:146 +#: templates/admin/base.html:185 msgid "Online" msgstr "在线" -#: templates/admin/base.html:152 templates/admin/search_form.html:20 +#: templates/admin/base.html:192 templates/admin/search_form.html:20 msgid "Search" msgstr "搜索" -#: templates/admin/base.html:162 +#: templates/admin/base.html:202 msgid "MAIN NAVIGATION" msgstr "页面导航" -#: templates/admin/base.html:165 +#: templates/admin/base.html:205 msgid "Dashboard" msgstr "仪表盘" -#: templates/admin/base.html:197 +#: templates/admin/base.html:237 msgid "System manage" msgstr "" -#: templates/admin/base.html:203 +#: templates/admin/base.html:243 msgid "Log manage" msgstr "" -#: templates/admin/base.html:204 +#: templates/admin/base.html:244 msgid "System config" msgstr "" -#: templates/admin/base.html:210 +#: templates/admin/base.html:250 msgid "Important" msgstr "" -#: templates/admin/base.html:211 +#: templates/admin/base.html:251 msgid "Warning" msgstr "" -#: templates/admin/base.html:212 +#: templates/admin/base.html:252 msgid "Information" msgstr "" #: templates/admin/base_site.html:8 templates/admin/login.html:13 #: templates/adminlte/general_option.html:23 +#: templates/registration/logged_out.html:13 msgid "Django site admin" msgstr "" @@ -466,7 +479,7 @@ msgstr "" msgid "Log in" msgstr "登录" -#: templates/admin/login.html:60 +#: templates/admin/login.html:60 templates/registration/logged_out.html:58 msgid "Login and Enjoy" msgstr "芝麻开门" @@ -570,7 +583,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:139 +#: templates/adminlte/general_option.html:36 templatetags/adminlte_menu.py:142 msgid "General Option" msgstr "基本设置" @@ -578,6 +591,17 @@ msgstr "基本设置" msgid "Exchange Menu" msgstr "菜单切换" +#: templates/registration/logged_out.html:15 +#: templates/registration/logged_out.html:63 +#, fuzzy +#| msgid "Log in" +msgid "Log in again" +msgstr "登录" + +#: templates/registration/logged_out.html:61 +msgid "Thanks for spending some quality time with the Web site today." +msgstr "" + #: templates/registration/password_change_done.html:3 #: templates/registration/password_change_form.html:7 msgid "Documentation" diff --git a/adminlteui/templates/admin/base.html b/adminlteui/templates/admin/base.html index d2f35f9..b1f5f6f 100644 --- a/adminlteui/templates/admin/base.html +++ b/adminlteui/templates/admin/base.html @@ -76,14 +76,44 @@