Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style fix #585

Open
wants to merge 12 commits into
base: django2
Choose a base branch
from
3 changes: 2 additions & 1 deletion xadmin/adminx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion xadmin/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
PLUGINS = (
'actions',
'filters',
'bookmark',
#'bookmark',
'export',
'layout',
'refresh',
Expand Down
20 changes: 13 additions & 7 deletions xadmin/plugins/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 = (
Expand All @@ -101,7 +107,7 @@ def get_form_layout(self):
),
Side(
Fieldset(_('Status'),
'is_active', 'is_staff', 'is_superuser',
'is_active', 'is_admin',
),
)
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions xadmin/plugins/bookmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion xadmin/plugins/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions xadmin/plugins/relate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -101,15 +105,15 @@ def related_link(self, instance):
links.append(link)
ul_html = '<ul class="dropdown-menu" role="menu">%s</ul>' % ''.join(
links)
return '<div class="dropdown related_menu pull-right"><a title="%s" class="relate_menu dropdown-toggle" data-toggle="dropdown"><i class="icon fa fa-list"></i></a>%s</div>' % (_('Related Objects'), ul_html)
related_link.short_description = '&nbsp;'
return '<div class="dropdown related_menu"><a title="%s" class="relate_menu dropdown-toggle" data-toggle="dropdown"><i class="icon fa fa-list"></i></a>%s</div>' % (_('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

Expand Down
2 changes: 0 additions & 2 deletions xadmin/plugins/xversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion xadmin/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
1 change: 1 addition & 0 deletions xadmin/static/xadmin/css/xadmin.main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions xadmin/templates/xadmin/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-right">
{% view_block 'top_navmenu' %}
{% if user.is_active and user.is_staff %}
{% if user.is_active %}
<li class="dropdown">
<a class="dropdown-toggle" role="button" data-toggle="dropdown" href="#">
<strong>{% trans 'Welcome,' %} {% firstof user.first_name user.username %}</strong> <span class="caret"></span></a>
Expand Down Expand Up @@ -65,10 +65,6 @@
{% block nav_toggles %}
{% include "xadmin/includes/toggle_back.html" %}
{% endblock %}

<a class="navbar-brand" data-toggle="collapse" data-target="#top-nav .navbar-collapse">
{% block nav_title %}{% endblock %}
</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
Expand Down
2 changes: 2 additions & 0 deletions xadmin/templates/xadmin/views/model_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
</ul>
</div>
{% else %}
<a href="#">
{{ o.label }}
</a>
{% endif %}
</th>{% endfor %}
</tr>
Expand Down
2 changes: 1 addition & 1 deletion xadmin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def admin_urlname(value, arg):

def boolean_icon(field_val):
return mark_safe(u'<i class="%s" alt="%s"></i>' % (
{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):
Expand Down
8 changes: 4 additions & 4 deletions xadmin/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
2 changes: 1 addition & 1 deletion xadmin/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xadmin/views/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xadmin/views/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xadmin/views/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xadmin/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div class="datetime clearfix"><div class="input-group date bootstrap-datepicker"><span class="input-group-addon"><i class="fa fa-calendar"></i></span>%s'
'<span class="input-group-btn"><button class="btn btn-default" type="button">%s</button></span></div>'
Expand Down