Skip to content

Commit

Permalink
合并主线,适配python3
Browse files Browse the repository at this point in the history
  • Loading branch information
wgbbiao committed May 27, 2017
2 parents af19a85 + 4a3bec7 commit 8d4047d
Show file tree
Hide file tree
Showing 46 changed files with 570 additions and 372 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ xadmin/static/xadmin/bower_components/
.idea
*~
demo_app/data.db

TAGS*
*.swp
148 changes: 82 additions & 66 deletions demo_app/app/adminx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import
import xadmin
from xadmin import views
from models import IDC, Host, MaintainLog, HostGroup, AccessRecord
from .models import IDC, Host, MaintainLog, HostGroup, AccessRecord
from xadmin.layout import Main, TabHolder, Tab, Fieldset, Row, Col, AppendedText, Side
from xadmin.plugins.inline import Inline
from xadmin.plugins.batch import BatchChangeAction
Expand All @@ -11,12 +12,11 @@ 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": "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": "qbutton", "title": "Quick Start", "btns": [{'model': Host}, {'model': IDC}, {'title': "Google", 'url': "http://www.google.com"}]},
{"type": "qbutton", "title": "Quick Start", "btns": [{"model": Host}, {"model": IDC}, {"title": "Google", "url": "http://www.google.com"}]},
{"type": "addform", "model": MaintainLog},
]
]
Expand All @@ -32,92 +32,108 @@ class BaseSetting(object):
class GlobalSetting(object):
global_search_models = [Host, IDC]
global_models_icon = {
Host: 'fa fa-laptop', IDC: 'fa fa-cloud'
Host: "fa fa-laptop", IDC: "fa fa-cloud"
}
menu_style = 'default' # 'accordion'


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


@xadmin.sites.register(IDC)
class IDCAdmin(object):
list_display = ('name', 'description', 'create_time')
list_display_links = ('name',)
list_display = ("name", "description", "create_time")
list_display_links = ("name",)
wizard_form_list = [
('First\'s Form', ('name', 'description')),
('Second Form', ('contact', 'telphone', 'address')),
('Thread Form', ('customer_id',))
("First's Form", ("name", "description")),
("Second Form", ("contact", "telphone", "address")),
("Thread Form", ("customer_id",))
]

search_fields = ['name']
relfield_style = 'fk-select'
search_fields = ["name"]
relfield_style = "fk-select"
reversion_enable = True

actions = [BatchChangeAction, ]
batch_fields = ('contact', 'groups')
batch_fields = ("contact", "groups")


@xadmin.sites.register(Host)
class HostAdmin(object):

def open_web(self, instance):
return "<a href='http://%s' target='_blank'>Open</a>" % instance.ip
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_links = ('name',)
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"}
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', xadmin.filters.MultiSelectFieldListFilter)]
search_fields = ["name", "ip", "description"]
list_filter = [
"idc", "guarantee_date", "status", "brand", "model", "cpu", "core_num",
"hard_disk", "memory", (
"service_type",
xadmin.filters.MultiSelectFieldListFilter,
),
]

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

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

aggregate_fields = {"guarantee_date": "min"}
grid_layouts = ('table', 'thumbnails')
grid_layouts = ("table", "thumbnails")

form_layout = (
Main(
TabHolder(
Tab('Comm Fields',
Fieldset('Company data',
'name', 'idc',
description="some comm fields, required"
),
Inline(MaintainLog),
Tab(
"Comm Fields",
Fieldset(
"Company data", "name", "idc",
description="some comm fields, required",
),
Tab('Extend Fields',
Fieldset('Contact details',
'service_type',
Row('brand', 'model'),
Row('cpu', 'core_num'),
Row(AppendedText(
'hard_disk', 'G'), AppendedText('memory', "G")),
'guarantee_date'
),
Inline(MaintainLog),
),
Tab(
"Extend Fields",
Fieldset(
"Contact details",
"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'
),
Fieldset("Status data", "status", "ssh_port", "ip"),
)
)
inlines = [MaintainInline]
Expand All @@ -135,36 +151,36 @@ def open_web(self, instance):

@xadmin.sites.register(HostGroup)
class HostGroupAdmin(object):
list_display = ('name', 'description')
list_display_links = ('name',)
list_display = ("name", "description")
list_display_links = ("name",)

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


@xadmin.sites.register(MaintainLog)
class MaintainLogAdmin(object):
list_display = (
'host', 'maintain_type', 'hard_type', 'time', 'operator', 'note')
list_display_links = ('host',)
"host", "maintain_type", "hard_type", "time", "operator", "note")
list_display_links = ("host",)

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

form_layout = (
Col("col2",
Fieldset('Record data',
'time', 'note',
css_class='unsort short_label no_title'
Fieldset("Record data",
"time", "note",
css_class="unsort short_label no_title"
),
span=9, horizontal=True
),
Col("col1",
Fieldset('Comm data',
'host', 'maintain_type'
Fieldset("Comm data",
"host", "maintain_type"
),
Fieldset('Maintain details',
'hard_type', 'operator'
Fieldset("Maintain details",
"hard_type", "operator"
),
span=3
)
Expand All @@ -181,12 +197,12 @@ def avg_count(self, instance):
avg_count.allow_tags = True
avg_count.is_column = True

list_display = ('date', 'user_count', 'view_count', 'avg_count')
list_display_links = ('date',)
list_display = ("date", "user_count", "view_count", "avg_count")
list_display_links = ("date",)

list_filter = ['date', 'user_count', 'view_count']
list_filter = ["date", "user_count", "view_count"]
actions = None
aggregate_fields = {"user_count": "sum", 'view_count': "sum"}
aggregate_fields = {"user_count": "sum", "view_count": "sum"}

refresh_times = (3, 5, 10)
data_charts = {
Expand Down
17 changes: 11 additions & 6 deletions demo_app/app/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.contrib.auth.models import Group
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible

AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')

Expand All @@ -22,7 +23,7 @@
('mix', u"Mix"),
)


@python_2_unicode_compatible
class IDC(models.Model):
name = models.CharField(max_length=64)
description = models.TextField()
Expand All @@ -35,14 +36,15 @@ class IDC(models.Model):

create_time = models.DateField(auto_now=True)

def __unicode__(self):
def __str__(self):
return self.name

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


@python_2_unicode_compatible
class Host(models.Model):
idc = models.ForeignKey(IDC)
name = models.CharField(max_length=64)
Expand Down Expand Up @@ -72,14 +74,15 @@ class Host(models.Model):

administrator = models.ForeignKey(AUTH_USER_MODEL, verbose_name="Admin")

def __unicode__(self):
def __str__(self):
return self.name

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


@python_2_unicode_compatible
class MaintainLog(models.Model):
host = models.ForeignKey(Host)
maintain_type = models.CharField(max_length=32)
Expand All @@ -88,7 +91,7 @@ class MaintainLog(models.Model):
operator = models.CharField(max_length=16)
note = models.TextField()

def __unicode__(self):
def __str__(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)

Expand All @@ -97,6 +100,7 @@ class Meta:
verbose_name_plural = verbose_name


@python_2_unicode_compatible
class HostGroup(models.Model):

name = models.CharField(max_length=32)
Expand All @@ -108,10 +112,11 @@ class Meta:
verbose_name = u"Host Group"
verbose_name_plural = verbose_name

def __unicode__(self):
def __str__(self):
return self.name


@python_2_unicode_compatible
class AccessRecord(models.Model):
date = models.DateField()
user_count = models.IntegerField()
Expand All @@ -121,5 +126,5 @@ class Meta:
verbose_name = u"Access Record"
verbose_name_plural = verbose_name

def __unicode__(self):
def __str__(self):
return "%s Access Record" % self.date.strftime('%Y-%m-%d')
Loading

0 comments on commit 8d4047d

Please sign in to comment.