Skip to content

Commit

Permalink
Merge branch 'release/1.3.0b0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyue92tree committed Jul 6, 2019
2 parents 3b1d50e + bf75715 commit 494f63e
Show file tree
Hide file tree
Showing 340 changed files with 554 additions and 29,520 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# custom menu base on treebeard
'treebeard',
...
]
```
Expand All @@ -67,6 +69,13 @@ python manage.py migrate django_admin_settings
## general_option
![general_option](./images/general_option.jpg)

# Thanks

- [AdminLTE](https://github.com/ColorlibHQ/AdminLTE)
- [django](https://github.com/django/django)
- [django-treebeard](https://github.com/django-treebeard/django-treebeard)
- [django-suit](https://github.com/darklow/django-suit)

# Donate

Your donation take me higher. 🚀
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ setup
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# custom menu base on treebeard
'treebeard',
...
]

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.2.0'
version = '1.3.0b0'
default_app_config = 'adminlteui.apps.AdminlteUIConfig'
57 changes: 50 additions & 7 deletions adminlteui/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from django.template.response import TemplateResponse
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from .models import Options
from django.utils.html import format_html
from django.db import models
from django.conf import settings
from adminlteui.widgets import AdminlteSelect, AdminlteSelectMultiple
from treebeard.admin import TreeAdmin
from treebeard.forms import movenodeform_factory
from .models import Options, Menu


def get_option(option_name):
Expand All @@ -20,7 +26,7 @@ def get_option(option_name):

def handle_uploaded_file(f, file_name):
# save site_logo
with open('media/' + file_name, 'wb+') as destination:
with open(settings.MEDIA_ROOT + '/' + file_name, 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)

Expand All @@ -43,16 +49,19 @@ def get_image_box():
class GeneralOptionForm(forms.Form):
site_title = forms.CharField(label=_('Site Title'),
widget=widgets.AdminTextInputWidget(),
help_text=_("Text to put at the end of each page's tag title."))
help_text=_(
"Text to put at the end of each page's tag title."))
site_header = forms.CharField(label=_('Site Header'),
widget=widgets.AdminTextInputWidget(),
help_text=_("Text to put in base page's tag b."))
help_text=_(
"Text to put in base page's tag b."))
# index_title = forms.CharField(label=_('Index Title'),
# widget=widgets.AdminTextInputWidget())
site_logo = forms.ImageField(label=_('Site Logo'),
widget=forms.ClearableFileInput(),
required=False,
help_text=_("Transparent background picture is a good choice."))
help_text=_(
"Transparent background picture is a good choice."))
welcome_sign = forms.CharField(
label=_('Welcome Sign'),
widget=widgets.AdminTextInputWidget(),
Expand All @@ -65,30 +74,41 @@ def save(self):
if self.data.get('site_logo-clear'):
obj = Options.objects.get(option_name='site_logo')
obj.delete()
self.changed_data.remove('site_logo')

for data_item in self.changed_data:
try:
obj = Options.objects.get(option_name=data_item)

if data_item == 'site_logo':
if not settings.MEDIA_ROOT or not settings.MEDIA_URL:
self.errors[data_item] = _(
'site_logo depends on setting.MEDIA_URL and setting.MEDIA_ROOT.')
return False
if not self.files.get(data_item) or self.data.get(
data_item) == '':
continue
handle_uploaded_file(self.files.get(data_item),
self.files.get(data_item).name)
obj.option_value = 'media/' + self.files.get(
obj.option_value = settings.MEDIA_URL.lstrip(
'/') + self.files.get(
data_item).name
else:
if obj.option_value == self.data.get(data_item):
continue
obj.option_value = self.data.get(data_item)
except Options.DoesNotExist:
if data_item == 'site_logo':
if not settings.MEDIA_ROOT or not settings.MEDIA_URL:
self.errors[data_item] = _(
'site_logo depends on setting.MEDIA_URL and setting.MEDIA_ROOT.')
return False
handle_uploaded_file(self.files.get(data_item),
self.files.get(data_item).name)
obj = Options.objects.create(
option_name=data_item,
option_value='media/' + self.files.get(
option_value=settings.MEDIA_URL.lstrip(
'/') + self.files.get(
data_item).name,
create_time=timezone.now())
else:
Expand Down Expand Up @@ -168,3 +188,26 @@ def general_option_view(self, request):
context['line'] = form
return TemplateResponse(request, 'adminlte/general_option.html',
context)


@admin.register(Menu)
class MenuAdmin(TreeAdmin):
list_display = ('name', 'position', 'link_type', 'link',
'content_type', 'display_icon',
'valid')
list_filter = ('position', 'link_type', 'valid')
list_editable = ('valid',)
form = movenodeform_factory(Menu)
change_list_template = 'adminlte/menu_change_list.html'
change_form_template = 'adminlte/menu_change_form.html'
formfield_overrides = {
models.ForeignKey: {'widget': AdminlteSelect}
}

def display_icon(self, obj):
if obj.icon:
return format_html(
'<i class="fa {}"></i> {}'.format(obj.icon, obj.icon))
return obj.icon

display_icon.short_description = _('Icon')
Binary file modified adminlteui/locale/zh-Hans/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 494f63e

Please sign in to comment.