From f8b13640dcbd0d91aa08b391acbe83cedc0d92a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E5=B2=B3?= Date: Tue, 9 Jul 2019 17:57:46 +0800 Subject: [PATCH 1/9] update README docs --- README.md | 4 ++-- docs/about.md | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 43f11c4..b09726d 100644 --- a/README.md +++ b/README.md @@ -74,13 +74,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/docs/about.md b/docs/about.md index 7652811..bfa26ae 100644 --- a/docs/about.md +++ b/docs/about.md @@ -1,6 +1,11 @@ # ChangeLog -## [v1.3.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.3.0b1) +## [v1.3.1](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.3.1) + +- fix #2 get 500 when exchange menu; +- add .gitattributes. + +## [v1.3.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.3.0) - add exchange_menu logic with permission limit; - add message when call exchange menu; From eb22d7ba7cd24b498b7067a9fb05e3086ba38b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E5=B2=B3?= Date: Wed, 10 Jul 2019 09:52:48 +0800 Subject: [PATCH 2/9] add gitter --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b09726d..e9fb3e1 100644 --- a/README.md +++ b/README.md @@ -9,24 +9,25 @@ [![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 +# Install ``` pip install django-adminlte-ui ``` -# setup +# Setup ``` # settings.py @@ -52,7 +53,7 @@ INSTALLED_APPS = [ python manage.py migrate django_admin_settings ``` -# screen shot +# Screen shot ## login page ![login](./images/login.jpg) From af31a30fc71bd943b3dcd2f928e6b193be78ee39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E5=B2=B3?= Date: Wed, 10 Jul 2019 17:19:44 +0800 Subject: [PATCH 3/9] add permission control for general_option & exchange_menu --- adminlteui/admin.py | 15 ++++++++-- adminlteui/templatetags/adminlte_menu.py | 38 +++++++++++++----------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/adminlteui/admin.py b/adminlteui/admin.py index 89ef7a0..b6c8694 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 @@ -144,6 +144,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), ) @@ -230,6 +235,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 +251,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/templatetags/adminlte_menu.py b/adminlteui/templatetags/adminlte_menu.py index 1130668..3e55b11 100644 --- a/adminlteui/templatetags/adminlte_menu.py +++ b/adminlteui/templatetags/adminlte_menu.py @@ -42,7 +42,7 @@ def get_custom_menu(request): :return: """ all_permissions = request.user.get_all_permissions() - + print(all_permissions) limit_for_internal_link = [] for permission in all_permissions: app_label = permission.split('.')[0] @@ -75,7 +75,8 @@ def get_custom_menu(request): 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')) + 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 @@ -134,22 +135,23 @@ def get_menu(context, request): for app in available_apps: if app.get('app_label') == 'django_admin_settings': - app.get('models').insert(0, - { - 'name': _('General Option'), - 'object_name': 'Options', - 'perms': - { - 'add': True, - 'change': True, - 'delete': True, - 'view': True - }, - 'admin_url': reverse( - 'admin:general_option'), - 'view_only': False - } - ) + if request.user.has_perm('django_admin_settings.add_options') or \ + request.user.has_perm( + 'django_admin_settings.change_options'): + app.get('models').insert(0, { + 'name': _('General Option'), + 'object_name': 'Options', + 'perms': + { + 'add': True, + 'change': True, + 'delete': True, + 'view': True + }, + 'admin_url': reverse( + 'admin:general_option'), + 'view_only': False + }) # return MenuManager(available_apps, context, request) return available_apps From cf53c106caf9ed3a3ec837da226e2bd50c09de87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E5=B2=B3?= Date: Wed, 10 Jul 2019 17:20:55 +0800 Subject: [PATCH 4/9] update menuAction js --- adminlteui/templates/admin/base.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adminlteui/templates/admin/base.html b/adminlteui/templates/admin/base.html index d2f35f9..226e533 100644 --- a/adminlteui/templates/admin/base.html +++ b/adminlteui/templates/admin/base.html @@ -462,9 +462,10 @@

Chat Settings

} console.log('menu matched.', window.location.href, menuActions[i].href); - menuActions[i].parentNode.setAttribute('class', 'active'); - menuActions[i].parentNode.parentNode.setAttribute('class', 'treeview-menu menu-open'); - menuActions[i].parentNode.parentNode.parentNode.setAttribute('class', 'treeview active'); + if (menuActions[i].parentNode.parentNode.getAttribute('class') !== 'sidebar-menu') { + menuActions[i].parentNode.parentNode.setAttribute('class', 'treeview-menu menu-open'); + menuActions[i].parentNode.parentNode.parentNode.setAttribute('class', 'treeview active'); + } break } } catch (e) { From 517e7dba590b7b4ae57a4ed5961a1c4200f043b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E5=B2=B3?= Date: Wed, 10 Jul 2019 21:57:53 +0800 Subject: [PATCH 5/9] add logged_out.html --- .../templates/registration/logged_out.html | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 adminlteui/templates/registration/logged_out.html diff --git a/adminlteui/templates/registration/logged_out.html b/adminlteui/templates/registration/logged_out.html new file mode 100644 index 0000000..6957cd0 --- /dev/null +++ b/adminlteui/templates/registration/logged_out.html @@ -0,0 +1,70 @@ +{% load i18n admin_static adminlte_options %} +{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %} + + + + + + + {% get_adminlte_option 'site_title' as adminlte_site_title %} + {% if adminlte_site_title.valid %} + {{ adminlte_site_title.site_title }} + {% else %} + {{ site_title|default:_('Django site admin') }} + {% endif %} + | {% trans 'Log in again' %} + + + + + + + + + + + + + + + + + + + + + + + From ec64d716b6177a5cbe4c33761474eafdcea036cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E5=B2=B3?= Date: Wed, 10 Jul 2019 21:59:01 +0800 Subject: [PATCH 6/9] add show_avatar and avatar_field logic --- adminlteui/admin.py | 30 +++++++++++++- adminlteui/templates/admin/base.html | 44 ++++++++++++++++++++- adminlteui/templatetags/adminlte_options.py | 15 ++++++- 3 files changed, 84 insertions(+), 5 deletions(-) diff --git a/adminlteui/admin.py b/adminlteui/admin.py index b6c8694..d29fce7 100644 --- a/adminlteui/admin.py +++ b/adminlteui/admin.py @@ -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) @@ -164,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: @@ -183,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, diff --git a/adminlteui/templates/admin/base.html b/adminlteui/templates/admin/base.html index 226e533..9572880 100644 --- a/adminlteui/templates/admin/base.html +++ b/adminlteui/templates/admin/base.html @@ -76,14 +76,28 @@