diff --git a/xadmin/adminx.py b/xadmin/adminx.py index e7a66e0ff..89c5c0344 100644 --- a/xadmin/adminx.py +++ b/xadmin/adminx.py @@ -29,4 +29,5 @@ def link(self, instance): search_fields = ['ip_addr', 'message'] model_icon = 'fa fa-cog' -xadmin.site.register(Log, LogAdmin) +# 暂时不需要修改记录 +# xadmin.site.register(Log, LogAdmin) diff --git a/xadmin/plugins/__init__.py b/xadmin/plugins/__init__.py index d0611656f..e7548d9c5 100644 --- a/xadmin/plugins/__init__.py +++ b/xadmin/plugins/__init__.py @@ -2,7 +2,7 @@ PLUGINS = ( 'actions', 'filters', - 'bookmark', + #'bookmark', 'export', 'layout', 'refresh', diff --git a/xadmin/plugins/auth.py b/xadmin/plugins/auth.py index 1ab6f6110..b123b948e 100644 --- a/xadmin/plugins/auth.py +++ b/xadmin/plugins/auth.py @@ -59,10 +59,11 @@ def get_field_attrs(self, db_field, **kwargs): class UserAdmin(object): change_user_password_template = None - list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff') - list_filter = ('is_staff', 'is_superuser', 'is_active') - search_fields = ('username', 'first_name', 'last_name', 'email') - ordering = ('username',) + list_display = ('username', 'email', 'date_joined', 'is_admin') + list_filter = ('is_admin', 'is_active') + list_display_links = ('email') + search_fields = ('username', 'introduce_by', 'date_joined', 'email') + ordering = ('email',) style_fields = {'user_permissions': 'm2m_transfer'} model_icon = 'fa fa-user' relfield_style = 'fk-ajax' @@ -80,6 +81,11 @@ def get_model_form(self, **kwargs): self.form = UserChangeForm return super(UserAdmin, self).get_model_form(**kwargs) + def queryset(self): + qs = super(UserAdmin, self).queryset().filter(is_superuser=False) + return qs + + def get_form_layout(self): if self.org_obj: self.form_layout = ( @@ -101,7 +107,7 @@ def get_form_layout(self): ), Side( Fieldset(_('Status'), - 'is_active', 'is_staff', 'is_superuser', + 'is_active', 'is_admin', ), ) ) @@ -182,7 +188,7 @@ class ChangePasswordView(ModelAdminView): def get(self, request, object_id): if not self.has_change_permission(request): raise PermissionDenied - self.obj = self.get_object(unquote(object_id)) + self.obj = self.get_object(object_id) self.form = self.change_password_form(self.obj) return self.get_response() @@ -219,7 +225,7 @@ def get_response(self): def post(self, request, object_id): if not self.has_change_permission(request): raise PermissionDenied - self.obj = self.get_object(unquote(object_id)) + self.obj = self.get_object(object_id) self.form = self.change_password_form(self.obj, request.POST) if self.form.is_valid(): diff --git a/xadmin/plugins/bookmark.py b/xadmin/plugins/bookmark.py index f6e0708e8..6f4e768d7 100644 --- a/xadmin/plugins/bookmark.py +++ b/xadmin/plugins/bookmark.py @@ -163,6 +163,7 @@ class BookmarkAdmin(object): list_display_links = ('title',) user_fields = ['user'] hidden_menu = True + remove_permissions = ['add', 'delete'] def queryset(self): if self.user.is_superuser: diff --git a/xadmin/plugins/editable.py b/xadmin/plugins/editable.py index beddc5532..8ba843d56 100644 --- a/xadmin/plugins/editable.py +++ b/xadmin/plugins/editable.py @@ -66,7 +66,7 @@ def get_media(self, media): class EditPatchView(ModelFormAdminView, ListAdminView): def init_request(self, object_id, *args, **kwargs): - self.org_obj = self.get_object(unquote(object_id)) + self.org_obj = self.get_object(object_id) # For list view get new field display html self.pk_attname = self.opts.pk.attname diff --git a/xadmin/plugins/relate.py b/xadmin/plugins/relate.py index 31642757c..9819dc08a 100644 --- a/xadmin/plugins/relate.py +++ b/xadmin/plugins/relate.py @@ -57,8 +57,12 @@ def get_related_list(self): continue if rel.related_model not in self.admin_site._registry.keys(): continue - has_view_perm = self.has_model_perm(rel.related_model, 'view') - has_add_perm = self.has_model_perm(rel.related_model, 'add') + if self.user.is_admin: + has_view_perm = True + has_add_perm = True + else: + has_view_perm = self.has_model_perm(rel.related_model, 'view') + has_add_perm = self.has_model_perm(rel.related_model, 'add') if not (has_view_perm or has_add_perm): continue @@ -101,15 +105,15 @@ def related_link(self, instance): links.append(link) ul_html = '
' % ''.join( links) - return ' ' % (_('Related Objects'), ul_html) - related_link.short_description = ' ' + return ' ' % (_('Related Objects'), ul_html) + related_link.short_description = '关联' related_link.allow_tags = True related_link.allow_export = False related_link.is_column = False def get_list_display(self, list_display): if self.use_related_menu and len(self.get_related_list()): - list_display.append('related_link') + list_display.insert(-1, 'related_link') self.admin_view.related_link = self.related_link return list_display diff --git a/xadmin/plugins/xversion.py b/xadmin/plugins/xversion.py index a0f6107bd..1280fee79 100644 --- a/xadmin/plugins/xversion.py +++ b/xadmin/plugins/xversion.py @@ -252,7 +252,6 @@ def get_context(self): return context def get(self, request, object_id, *args, **kwargs): - object_id = unquote(object_id) self.obj = self.get_object(object_id) if not self.has_change_permission(self.obj): @@ -282,7 +281,6 @@ def get_version_object(self, version): return obj, detail def post(self, request, object_id, *args, **kwargs): - object_id = unquote(object_id) self.obj = self.get_object(object_id) if not self.has_change_permission(self.obj): diff --git a/xadmin/sites.py b/xadmin/sites.py index fe5f4dae9..f929a13e2 100644 --- a/xadmin/sites.py +++ b/xadmin/sites.py @@ -158,7 +158,7 @@ def has_permission(self, request): Returns True if the given HttpRequest has permission to view *at least one* page in the admin site. """ - return request.user.is_active and request.user.is_staff + return request.user.is_active def check_dependencies(self): """ diff --git a/xadmin/static/xadmin/css/xadmin.main.css b/xadmin/static/xadmin/css/xadmin.main.css index 2113276e2..2ce27a460 100644 --- a/xadmin/static/xadmin/css/xadmin.main.css +++ b/xadmin/static/xadmin/css/xadmin.main.css @@ -232,6 +232,7 @@ ul.nav-sitemenu li a { } .panel-group.nav-sitemenu .panel .list-group { border-radius: 0px; + margin-left: 20px; } .panel-group.nav-sitemenu .panel .list-group .list-group-item:first-child { border-top-width: 1px; diff --git a/xadmin/templates/xadmin/base_site.html b/xadmin/templates/xadmin/base_site.html index 9045bad69..26f9ecb06 100644 --- a/xadmin/templates/xadmin/base_site.html +++ b/xadmin/templates/xadmin/base_site.html @@ -12,7 +12,7 @@ {% else %} + {{ o.label }} + {% endif %} {% endfor %} diff --git a/xadmin/util.py b/xadmin/util.py index c9ed8f84e..e9d59aef3 100644 --- a/xadmin/util.py +++ b/xadmin/util.py @@ -317,7 +317,7 @@ def admin_urlname(value, arg): def boolean_icon(field_val): return mark_safe(u'' % ( - {True: 'fa fa-check-circle text-success', False: 'fa fa-times-circle text-error', None: 'fa fa-question-circle muted'}[field_val], field_val)) + {True: 'fa fa-check-circle text-success', False: 'fa fa-times-circle text-danger', None: 'glyphicon glyphicon-minus muted'}[field_val], field_val)) def display_for_field(value, field): diff --git a/xadmin/views/base.py b/xadmin/views/base.py index 6d946a54d..34e356579 100644 --- a/xadmin/views/base.py +++ b/xadmin/views/base.py @@ -588,17 +588,17 @@ def has_view_permission(self, obj=None): view_codename = get_permission_codename('view', self.opts) change_codename = get_permission_codename('change', self.opts) - return ('view' not in self.remove_permissions) and (self.user.has_perm('%s.%s' % (self.app_label, view_codename)) or + return ('view' not in self.remove_permissions) and (self.user.is_admin or self.user.has_perm('%s.%s' % (self.app_label, view_codename)) or self.user.has_perm('%s.%s' % (self.app_label, change_codename))) def has_add_permission(self): codename = get_permission_codename('add', self.opts) - return ('add' not in self.remove_permissions) and self.user.has_perm('%s.%s' % (self.app_label, codename)) + return ('add' not in self.remove_permissions) and (self.user.is_admin or self.user.has_perm('%s.%s' % (self.app_label, codename))) def has_change_permission(self, obj=None): codename = get_permission_codename('change', self.opts) - return ('change' not in self.remove_permissions) and self.user.has_perm('%s.%s' % (self.app_label, codename)) + return ('change' not in self.remove_permissions) and (self.user.is_admin or self.user.has_perm('%s.%s' % (self.app_label, codename))) def has_delete_permission(self, obj=None): codename = get_permission_codename('delete', self.opts) - return ('delete' not in self.remove_permissions) and self.user.has_perm('%s.%s' % (self.app_label, codename)) + return ('delete' not in self.remove_permissions) and (self.user.is_admin or self.user.has_perm('%s.%s' % (self.app_label, codename))) diff --git a/xadmin/views/dashboard.py b/xadmin/views/dashboard.py index 3a26f5055..e319f7ce1 100644 --- a/xadmin/views/dashboard.py +++ b/xadmin/views/dashboard.py @@ -641,7 +641,7 @@ def get_title(self): return self.title % force_text(self.obj) def init_request(self, object_id, *args, **kwargs): - self.obj = self.get_object(unquote(object_id)) + self.obj = self.get_object(object_id) if not self.has_view_permission(self.obj): raise PermissionDenied diff --git a/xadmin/views/delete.py b/xadmin/views/delete.py index 77d49f5c3..f50441e9f 100644 --- a/xadmin/views/delete.py +++ b/xadmin/views/delete.py @@ -19,7 +19,7 @@ class DeleteAdminView(ModelAdminView): def init_request(self, object_id, *args, **kwargs): "The 'delete' admin view for this model." - self.obj = self.get_object(unquote(object_id)) + self.obj = self.get_object(object_id) if not self.has_delete_permission(self.obj): raise PermissionDenied diff --git a/xadmin/views/detail.py b/xadmin/views/detail.py index 96f6aec1b..adf3afd3e 100644 --- a/xadmin/views/detail.py +++ b/xadmin/views/detail.py @@ -135,7 +135,7 @@ class DetailAdminView(ModelAdminView): form_layout = None def init_request(self, object_id, *args, **kwargs): - self.obj = self.get_object(unquote(object_id)) + self.obj = self.get_object(object_id) if not self.has_view_permission(self.obj): raise PermissionDenied diff --git a/xadmin/views/edit.py b/xadmin/views/edit.py index ca6e8411e..dd7d7d161 100644 --- a/xadmin/views/edit.py +++ b/xadmin/views/edit.py @@ -456,7 +456,7 @@ def post_response(self): class UpdateAdminView(ModelFormAdminView): def init_request(self, object_id, *args, **kwargs): - self.org_obj = self.get_object(unquote(object_id)) + self.org_obj = self.get_object(object_id) if not self.has_change_permission(self.org_obj): raise PermissionDenied diff --git a/xadmin/widgets.py b/xadmin/widgets.py index 8fba092ca..cb2c530f6 100644 --- a/xadmin/widgets.py +++ b/xadmin/widgets.py @@ -72,7 +72,7 @@ def __init__(self, attrs=None): forms.MultiWidget.__init__(self, widgets, attrs) def render(self, name, value, attrs=None): - input_html = [ht for ht in super(AdminSplitDateTime, self).render(name, value, attrs).split('\n') if ht != ''] + input_html = [ht for ht in super(AdminSplitDateTime, self).render(name, value, attrs).split('>') if ht != ''] # return input_html return mark_safe('