Skip to content

Commit

Permalink
PEP8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
areski committed May 7, 2013
1 parent 707c044 commit c61d024
Show file tree
Hide file tree
Showing 54 changed files with 1,136 additions and 718 deletions.
83 changes: 49 additions & 34 deletions demo_app/app/adminx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
from xadmin.plugins.inline import Inline
from xadmin.plugins.batch import BatchChangeAction


class MainDashboard(object):
widgets = [
[
{"type": "html", "title": "Test Widget", "content": "<h3> Welcome to Xadmin! </h3><p>Join Online Group: <br/>QQ Qun : 282936295</p>"},
{"type": "chart", "model": "app.accessrecord", 'chart': 'user_count', 'params': {'_p_date__gte': '2013-01-08', 'p': 1, '_p_date__lt': '2013-01-29'}},
{"type": "list", "model": "app.host", 'params': {'o':'-guarantee_date'}},
{"type": "list", "model": "app.host", 'params': {
'o':'-guarantee_date'}},
],
[
{"type": "qbutton", "title": "Quick Start", "btns": [{'model': Host}, {'model':IDC}, {'title': "Google", 'url': "http://www.google.com"}]},
Expand All @@ -20,130 +22,143 @@ class MainDashboard(object):
]
xadmin.site.register(views.website.IndexView, MainDashboard)


class BaseSetting(object):
enable_themes = True
use_bootswatch = True
xadmin.site.register(views.BaseAdminView, BaseSetting)


class GolbeSetting(object):
globe_search_models = [Host, IDC]
globe_models_icon = {
Host: 'laptop', IDC: 'cloud'
}
xadmin.site.register(views.CommAdminView, GolbeSetting)


class MaintainInline(object):
model = MaintainLog
extra = 1
style = 'accordion'


class IDCAdmin(object):
list_display = ('name', 'description', 'create_time')
list_display_links = ('name',)
wizard_form_list = [
('Frist\'s Form', ('name', 'description')),
('Seocnd Form', ('contact', 'telphone', 'address')),
('First\'s Form', ('name', 'description')),
('Second Form', ('contact', 'telphone', 'address')),
('Thread Form', ('customer_id',))
]

search_fields = ['name']
relfield_style = 'fk-ajax'
reversion_enable = True

actions = [BatchChangeAction,]
actions = [BatchChangeAction, ]
batch_fields = ('contact', 'create_time')



class HostAdmin(object):
def open_web(self, instance):
return "<a href='http://%s' target='_blank'>Open</a>" % instance.ip
open_web.short_description = "Acts"
open_web.allow_tags = True
open_web.is_column = True

list_display = ('name', 'idc', 'guarantee_date', 'service_type', 'status', 'open_web', 'description')
list_display = ('name', 'idc', 'guarantee_date', 'service_type',
'status', 'open_web', 'description')
list_display_links = ('name',)

raw_id_fields = ('idc',)
style_fields = {'system': "radio-inline"}

search_fields = ['name', 'ip', 'description']
list_filter = ['idc', 'guarantee_date', 'status', 'brand', 'model', 'cpu', 'core_num', 'hard_disk', 'memory', 'service_type']
list_filter = ['idc', 'guarantee_date', 'status', 'brand', 'model',
'cpu', 'core_num', 'hard_disk', 'memory', 'service_type']

list_bookmarks = [{'title': "Need Guarantee", 'query': {'status__exact': 2}, 'order': ('-guarantee_date',), 'cols': ('brand', 'guarantee_date', 'service_type')}]

show_detail_fields = ('idc',)
list_editable = ('name', 'idc', 'guarantee_date', 'service_type', 'description')
list_editable = (
'name', 'idc', 'guarantee_date', 'service_type', 'description')
save_as = True

aggregate_fields = {"guarantee_date": "min"}

form_layout = (
Main(
TabHolder(
Tab('Comm Fiels',
Fieldset('Company data',
'name', 'idc',
description="some comm fields, required"
),
'name', 'idc',
description="some comm fields, required"
),
Inline(MaintainLog),
),
),
Tab('Extend Fiedls',
Fieldset('Contact details',
'service_type',
Row('brand', 'model'),
Row('cpu', 'core_num'),
Row(AppendedText('hard_disk', 'G'), AppendedText('memory', "G")),
'guarantee_date'
'service_type',
Row('brand', 'model'),
Row('cpu', 'core_num'),
Row(AppendedText(
'hard_disk', 'G'), AppendedText('memory', "G")),
'guarantee_date'
),
),
),
),
),
Side(
Fieldset('Status data',
'status', 'ssh_port', 'ip'
),
'status', 'ssh_port', 'ip'
),
)
)
inlines = [MaintainInline]
reversion_enable = True



class HostGroupAdmin(object):
list_display = ('name', 'description')
list_display_links = ('name',)

search_fields = ['name']
style_fields = {'hosts': 'checkbox-inline'}


class MaintainLogAdmin(object):
list_display = ('host', 'maintain_type', 'hard_type', 'time', 'operator', 'note')
list_display = (
'host', 'maintain_type', 'hard_type', 'time', 'operator', 'note')
list_display_links = ('host',)

list_filter = ['host', 'maintain_type', 'hard_type', 'time', 'operator']
search_fields = ['note']

form_layout = (
Col("col2",
Col("col2",
Fieldset('Record data',
'time', 'note',
css_class='unsort short_label no_title'
),
'time', 'note',
css_class='unsort short_label no_title'
),
span=9, horizontal=True
),
),
Col("col1",
Fieldset('Comm data',
'host', 'maintain_type'
),
'host', 'maintain_type'
),
Fieldset('Maintain details',
'hard_type', 'operator'
),
'hard_type', 'operator'
),
span=3
)
)
)
reversion_enable = True


class AccessRecordAdmin(object):
def avg_count(self, instance):
return int(instance.view_count/instance.user_count)
return int(instance.view_count / instance.user_count)
avg_count.short_description = "Avg Count"
avg_count.allow_tags = True
avg_count.is_column = True
Expand Down
29 changes: 18 additions & 11 deletions demo_app/app/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models


class IDC(models.Model):
name = models.CharField(max_length=64)
description = models.TextField()
Expand All @@ -8,12 +9,12 @@ class IDC(models.Model):
telphone = models.CharField(max_length=32)
address = models.CharField(max_length=128)
customer_id = models.CharField(max_length=128)

create_time = models.DateField(auto_now=True)

def __unicode__(self):
return self.name

class Meta:
verbose_name = u"IDC"
verbose_name_plural = verbose_name
Expand All @@ -35,6 +36,8 @@ class Meta:
('email', u"Email"),
('mix', u"Mix"),
)


class Host(models.Model):

idc = models.ForeignKey(IDC)
Expand All @@ -47,16 +50,16 @@ class Host(models.Model):
ssh_port = models.IntegerField(blank=True, null=True)
status = models.SmallIntegerField(choices=SERVER_STATUS)

brand = models.CharField(max_length=64, choices=[(i,i) for i in (u"DELL", u"HP", u"Other")])
brand = models.CharField(max_length=64, choices=[(i, i) for i in (u"DELL", u"HP", u"Other")])
model = models.CharField(max_length=64)
cpu = models.CharField(max_length=64)
core_num = models.SmallIntegerField(choices=[(i*2, "%s Cores" % (i*2)) for i in range(1,15)])
core_num = models.SmallIntegerField(choices=[(i * 2, "%s Cores" % (i * 2)) for i in range(1, 15)])
hard_disk = models.IntegerField()
memory = models.IntegerField()

system = models.CharField(u"System OS", max_length=32, choices=[(i,i) for i in (u"CentOS", u"FreeBSD", u"Ubuntu")])
system = models.CharField(u"System OS", max_length=32, choices=[(i, i) for i in (u"CentOS", u"FreeBSD", u"Ubuntu")])
system_version = models.CharField(max_length=32)
system_arch = models.CharField(max_length=32, choices=[(i,i) for i in (u"x86_64", u"i386")])
system_arch = models.CharField(max_length=32, choices=[(i, i) for i in (u"x86_64", u"i386")])

create_time = models.DateField()
guarantee_date = models.DateField()
Expand All @@ -65,11 +68,12 @@ class Host(models.Model):

def __unicode__(self):
return self.name

class Meta:
verbose_name = u"Host"
verbose_name_plural = verbose_name


class MaintainLog(models.Model):
host = models.ForeignKey(Host)
maintain_type = models.CharField(max_length=32)
Expand All @@ -79,18 +83,20 @@ class MaintainLog(models.Model):
note = models.TextField()

def __unicode__(self):
return '%s maintain-log [%s] %s %s' % (self.host.name, self.time.strftime('%Y-%m-%d %H:%M:%S'), \
self.maintain_type, self.hard_type)
return '%s maintain-log [%s] %s %s' % (self.host.name, self.time.strftime('%Y-%m-%d %H:%M:%S'),
self.maintain_type, self.hard_type)

class Meta:
verbose_name = u"Maintain Log"
verbose_name_plural = verbose_name


class HostGroup(models.Model):

name = models.CharField(max_length=32)
description = models.TextField()
hosts = models.ManyToManyField(Host, verbose_name=u'Hosts', blank=True, related_name='groups')
hosts = models.ManyToManyField(
Host, verbose_name=u'Hosts', blank=True, related_name='groups')

class Meta:
verbose_name = u"Host Group"
Expand All @@ -99,6 +105,7 @@ class Meta:
def __unicode__(self):
return self.name


class AccessRecord(models.Model):
date = models.DateField()
user_count = models.IntegerField()
Expand Down
15 changes: 8 additions & 7 deletions demo_app/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import os.path

reload(sys)
sys.setdefaultencoding('utf-8')
sys.setdefaultencoding('utf-8')
gettext = lambda s: s

PROJECT_ROOT = os.path.join(os.path.realpath(os.path.dirname(__file__)), os.pardir)
PROJECT_ROOT = os.path.join(
os.path.realpath(os.path.dirname(__file__)), os.pardir)

DEBUG = True
TEMPLATE_DEBUG = DEBUG
Expand All @@ -20,7 +21,7 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.path.join(PROJECT_ROOT, 'data.db'), # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
Expand Down Expand Up @@ -91,7 +92,7 @@
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
Expand All @@ -101,7 +102,7 @@
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
Expand Down Expand Up @@ -136,7 +137,7 @@
'xadmin',
'crispy_forms',
'reversion',

'app',
)

Expand All @@ -163,7 +164,7 @@
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'console':{
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler'
},
Expand Down
4 changes: 2 additions & 2 deletions demo_app/demo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
xversion.registe_models()

urlpatterns = patterns('',
url(r'', include(xadmin.site.urls)),
)
url(r'', include(xadmin.site.urls)),
)
2 changes: 1 addition & 1 deletion demo_app/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if __name__ == "__main__":
PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(PROJECT_ROOT, os.pardir))

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")

from django.core.management import execute_from_command_line
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
author_email='sshwsfc@gmail.com',
url='http://www.xadmin.io',
download_url='http://github.com/sshwsfc/django-xadmin/archive/master.zip',
packages=['xadmin', 'xadmin.plugins', 'xadmin.templatetags', 'xadmin.tests', 'xadmin.views'],
packages=['xadmin', 'xadmin.plugins', 'xadmin.templatetags',
'xadmin.tests', 'xadmin.views'],
include_package_data=True,
zip_safe=False,
keywords=['admin', 'django', 'xadmin', 'bootstrap'],
Expand Down
5 changes: 3 additions & 2 deletions xadmin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from xadmin.sites import AdminSite, site

VERSION = [0,1,0]
VERSION = [0, 1, 0]


def autodiscover():
"""
Expand Down Expand Up @@ -33,4 +34,4 @@ def autodiscover():
# doesn't have an admin module, we can ignore the error
# attempting to import it, otherwise we want it to bubble up.
if module_has_submodule(mod, 'adminx'):
raise
raise
Loading

0 comments on commit c61d024

Please sign in to comment.