Skip to content

Commit

Permalink
pep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
areski committed Oct 4, 2013
1 parent fbe3338 commit cd3f126
Show file tree
Hide file tree
Showing 31 changed files with 71 additions and 76 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from setuptools import setup, find_packages
from setuptools import setup

# version_tuple = __import__('xadmin.version').VERSION
# version = ".".join([str(v) for v in version_tuple])
Expand Down
4 changes: 3 additions & 1 deletion xadmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

VERSION = [0,4,0]


class Settings(object):
pass


def autodiscover():
"""
Auto-discover INSTALLED_APPS admin.py modules and fail silently when
Expand All @@ -21,7 +23,7 @@ def autodiscover():
"textinput": "textinput textInput form-control",
"fileinput": "fileinput fileUpload form-control",
"passwordinput": "textinput textInput form-control",
})
})

from xadmin.views import register_builtin_views
register_builtin_views(site)
Expand Down
1 change: 0 additions & 1 deletion xadmin/adminx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import xadmin
from xadmin import views
from models import UserSettings
from xadmin.layout import *

Expand Down
5 changes: 2 additions & 3 deletions xadmin/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from django.db import models
from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import smart_unicode
Expand All @@ -12,12 +10,13 @@
from django.utils.text import Truncator

from xadmin.views.list import EMPTY_CHANGELIST_VALUE
import datetime

FILTER_PREFIX = '_p_'
SEARCH_VAR = '_q_'

from util import (get_model_from_relation,
reverse_field_path, get_limit_choices_to_from_path, prepare_lookup_value)
reverse_field_path, get_limit_choices_to_from_path, prepare_lookup_value)


class BaseFilter(object):
Expand Down
6 changes: 1 addition & 5 deletions xadmin/layout.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from crispy_forms.helper import FormHelper
from crispy_forms.layout import *
from crispy_forms.bootstrap import *
from crispy_forms.utils import render_field, flatatt

from crispy_forms.utils import render_field
from crispy_forms import layout
from crispy_forms import bootstrap

import math


Expand Down
9 changes: 5 additions & 4 deletions xadmin/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

PLUGINS = ('actions', 'filters', 'bookmark', 'export', 'layout', 'refresh', 'sortable', 'details',
'editable', 'relate', 'chart', 'ajax', 'relfield', 'inline', 'topnav', 'portal', 'quickform',
'wizard', 'images', 'auth', 'multiselect', 'themes', 'aggregation', 'mobile', 'passwords',
PLUGINS = ('actions', 'filters', 'bookmark', 'export', 'layout', 'refresh', 'sortable', 'details',
'editable', 'relate', 'chart', 'ajax', 'relfield', 'inline', 'topnav', 'portal', 'quickform',
'wizard', 'images', 'auth', 'multiselect', 'themes', 'aggregation', 'mobile', 'passwords',
'sitemenu', 'language', 'comments')


def register_builtin_plugins(site):
from django.utils.importlib import import_module
from django.conf import settings

exclude_plugins = getattr(settings, 'XADMIN_EXCLUDE_PLUGINS', [])

[import_module('xadmin.plugins.%s' % plugin) for plugin in PLUGINS if plugin not in exclude_plugins]
[import_module('xadmin.plugins.%s' % plugin) for plugin in PLUGINS if plugin not in exclude_plugins]
2 changes: 1 addition & 1 deletion xadmin/plugins/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def post_response(self, response, *args, **kwargs):
# Actions with no confirmation
if self.actions and 'action' in request.POST:
action = request.POST['action']

if action not in self.actions:
msg = _("Items must be selected in order to perform "
"actions on them. No items have been changed.")
Expand Down
9 changes: 5 additions & 4 deletions xadmin/plugins/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
except:
has_xlwt = False


class ExportMenuPlugin(BaseAdminPlugin):

list_export = ('xls', 'csv', 'xml', 'json')
Expand All @@ -37,7 +38,7 @@ def block_top_toolbar(self, context, nodes):
'export_types': [{'type': et, 'name': self.export_names[et]} for et in self.list_export],
})
nodes.append(loader.render_to_string('xadmin/blocks/model_list.top_toolbar.exports.html', context_instance=context))


class ExportPlugin(BaseAdminPlugin):

Expand All @@ -62,14 +63,14 @@ def _get_objects(self, context):
headers = [c for c in context['result_headers'].cells if c.export]
rows = context['results']

return [dict([\
(force_unicode(headers[i].text), self._format_value(o)) for i, o in \
return [dict([
(force_unicode(headers[i].text), self._format_value(o)) for i, o in
enumerate(filter(lambda c:getattr(c, 'export', False), r.cells))]) for r in rows]

def _get_datas(self, context):
rows = context['results']

new_rows = [[self._format_value(o) for o in \
new_rows = [[self._format_value(o) for o in
filter(lambda c:getattr(c, 'export', False), r.cells)] for r in rows]
new_rows.insert(0, [force_unicode(c.text) for c in context['result_headers'].cells if c.export])
return new_rows
Expand Down
1 change: 0 additions & 1 deletion xadmin/plugins/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def get_list_queryset(self, queryset):
if new_qs is not None:
queryset = new_qs


self.filter_specs.append(spec)

self.has_filters = bool(self.filter_specs)
Expand Down
1 change: 1 addition & 0 deletions xadmin/plugins/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_gallery_modal():
</div>
""" % (_('Previous'), _('Next'), _('Slideshow'), _('Download'))


class AdminImageField(forms.ImageField):

def widget_attrs(self, widget):
Expand Down
5 changes: 3 additions & 2 deletions xadmin/plugins/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.forms.formsets import all_valid, DELETION_FIELD_NAME
from django.forms.models import inlineformset_factory, BaseInlineFormSet
from django.contrib.contenttypes.generic import BaseGenericInlineFormSet, generic_inlineformset_factory
from django.template import loader, Context
from django.template import loader
from django.template.loader import render_to_string
from xadmin.layout import FormHelper, Layout, flatatt, Container, Column, Field, Fieldset
from xadmin.sites import site
Expand Down Expand Up @@ -266,6 +266,7 @@ def has_delete_permission(self):
return self.user.has_perm(
self.opts.app_label + '.' + self.opts.get_delete_permission())


class GenericInlineModelAdmin(InlineModelAdmin):
ct_field = "content_type"
ct_fk_field = "object_id"
Expand Down Expand Up @@ -362,7 +363,7 @@ def inline_instances(self):
inline_instances = []
for inline_class in self.inlines:
inline = self.admin_view.get_view(
(getattr(inline_class, 'generic_inline', False) and GenericInlineModelAdmin or InlineModelAdmin),
(getattr(inline_class, 'generic_inline', False) and GenericInlineModelAdmin or InlineModelAdmin),
inline_class).init(self.admin_view)
if not (inline.has_add_permission() or
inline.has_change_permission() or
Expand Down
2 changes: 1 addition & 1 deletion xadmin/plugins/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def block_top_navmenu(self, context, nodes):

if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES:
site.register_plugin(SetLangNavPlugin, CommAdminView)
site.register_view(r'^i18n/', lambda site:'django.conf.urls.i18n', 'i18n')
site.register_view(r'^i18n/', lambda site: 'django.conf.urls.i18n', 'i18n')
10 changes: 6 additions & 4 deletions xadmin/plugins/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
}


class GridLayoutPlugin(BaseAdminPlugin):

grid_layouts = []
Expand Down Expand Up @@ -51,10 +52,11 @@ def init_request(self, *args, **kwargs):
def result_item(self, item, obj, field_name, row):
if self._current_layout == 'thumbnails':
if getattr(item.attr, 'is_column', True):
item.field_label = label_for_field(field_name, self.model,
model_admin=self.admin_view,
return_attr=False
)
item.field_label = label_for_field(
field_name, self.model,
model_admin=self.admin_view,
return_attr=False
)
if getattr(item.attr, 'thumbnail_img', False):
setattr(item, 'thumbnail_hidden', True)
row['thumbnail_img'] = item
Expand Down
5 changes: 3 additions & 2 deletions xadmin/plugins/mobile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

from xadmin.sites import site
#coding:utf-8
#from xadmin.sites import site
from xadmin.views import BaseAdminPlugin, CommAdminView


class MobilePlugin(BaseAdminPlugin):

def _test_mobile(self):
Expand Down
10 changes: 5 additions & 5 deletions xadmin/plugins/passwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class ResetPasswordSendView(BaseAdminView):

need_site_permission = False

password_reset_form = PasswordResetForm
Expand Down Expand Up @@ -75,7 +75,7 @@ def block_form_bottom(self, context, nodes):


class ResetPasswordComfirmView(BaseAdminView):

need_site_permission = False

password_reset_set_form = SetPasswordForm
Expand All @@ -101,20 +101,20 @@ def get_media(self):
return super(ResetPasswordComfirmView, self).get_media() + \
self.vendor('xadmin.page.form.js', 'xadmin.form.css')

site.register_view(r'^xadmin/password_reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
site.register_view(r'^xadmin/password_reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
ResetPasswordComfirmView, name='xadmin_password_reset_confirm')


class ResetPasswordCompleteView(BaseAdminView):

need_site_permission = False

password_reset_complete_template = 'xadmin/auth/password_reset/complete.html'

def get(self, request, *args, **kwargs):
context = super(ResetPasswordCompleteView, self).get_context()
context['login_url'] = self.get_admin_url('index')

return TemplateResponse(request, self.password_reset_complete_template, context,
current_app=self.admin_site.name)

Expand Down
4 changes: 1 addition & 3 deletions xadmin/plugins/portal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

from django.template import loader

#coding:utf-8
from xadmin.sites import site
from xadmin.models import UserSettings
from xadmin.views import BaseAdminPlugin, ModelFormAdminView, DetailAdminView
Expand Down
1 change: 1 addition & 0 deletions xadmin/plugins/quickform.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from xadmin.views import BaseAdminPlugin, ModelFormAdminView
from xadmin.layout import Layout


class QuickFormPlugin(BaseAdminPlugin):

def init_request(self, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions xadmin/plugins/relfield.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.utils.html import escape,format_html
from django.utils.html import escape, format_html
from django.utils.text import Truncator
from django.utils.translation import ugettext as _
from django import forms
Expand Down Expand Up @@ -30,7 +30,7 @@ def render(self, name, value, attrs=None):
attrs['data-choices'] = '?'
if self.rel.limit_choices_to:
for i in list(self.rel.limit_choices_to):
attrs['data-choices'] += "&_p_%s=%s" % (i,self.rel.limit_choices_to[i])
attrs['data-choices'] += "&_p_%s=%s" % (i, self.rel.limit_choices_to[i])
attrs['data-choices'] = format_html(attrs['data-choices'])
if value:
attrs['data-label'] = self.label_for_value(value)
Expand Down
1 change: 1 addition & 0 deletions xadmin/plugins/sitemenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'accordion': 'xadmin/includes/sitemenu_accordion.html',
}


class SiteMenuStylePlugin(BaseAdminPlugin):

menu_style = None
Expand Down
5 changes: 1 addition & 4 deletions xadmin/plugins/sortable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@


from django.template import loader

#coding:utf-8
from xadmin.sites import site
from xadmin.views import BaseAdminPlugin, ListAdminView

Expand Down
7 changes: 3 additions & 4 deletions xadmin/plugins/themes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

#coding:utf-8
import urllib
from django.template import loader
from django.core.cache import cache
from django.utils.translation import ugettext as _

from xadmin.sites import site
from xadmin.models import UserSettings
from xadmin.views import BaseAdminPlugin, BaseAdminView
Expand Down Expand Up @@ -47,8 +46,8 @@ def block_top_navmenu(self, context, nodes):

themes = [{'name': _(u"Default"), 'description': _(
u"Default bootstrap theme"), 'css': self.default_theme},
{'name': _(u"Bootstrap2"), 'description': _(
u"Bootstrap 2.x theme"), 'css': self.bootstrap2_theme},]
{'name': _(u"Bootstrap2"), 'description': _(u"Bootstrap 2.x theme"),
'css': self.bootstrap2_theme}]
select_css = context.get('site_theme', self.default_theme)

if self.user_themes:
Expand Down
1 change: 0 additions & 1 deletion xadmin/plugins/topnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def block_top_navmenu(self, context, nodes):
site_name = self.admin_site.name
models = self.globe_search_models or self.admin_site._registry.keys()


models = self.globe_add_models or self.admin_site._registry.keys()
for model in models:
app_label = model._meta.app_label
Expand Down
5 changes: 2 additions & 3 deletions xadmin/plugins/xversion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from functools import partial

from django.contrib.contenttypes.generic import GenericInlineModelAdmin, GenericRelation
from django.contrib.contenttypes.generic import GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied
from django.db import models
Expand All @@ -24,6 +22,7 @@
from xadmin.views.detail import DetailAdminUtil
from reversion.models import Revision, Version
from reversion.revisions import default_revision_manager, RegistrationError
from functools import partial


def _autoregister(admin, model, follow=None):
Expand Down
4 changes: 0 additions & 4 deletions xadmin/sites.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import sys
from functools import update_wrapper

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.db.models.base import ModelBase
from django.http import HttpResponseRedirect
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect

reload(sys)
sys.setdefaultencoding("utf-8")
Expand Down
Loading

0 comments on commit cd3f126

Please sign in to comment.