Skip to content

Commit 4a3bec7

Browse files
authored
Merge pull request #346 from y2kconnect/master
增加python3.4的支持。
2 parents 673d7cc + 568c340 commit 4a3bec7

46 files changed

Lines changed: 590 additions & 376 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ xadmin/static/xadmin/bower_components/
4343
.idea
4444
*~
4545
demo_app/data.db
46+
47+
TAGS*
48+
*.swp

demo_app/app/adminx.py

Lines changed: 108 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from __future__ import absolute_import
12
import xadmin
23
from xadmin import views
3-
from models import IDC, Host, MaintainLog, HostGroup, AccessRecord
4+
from .models import IDC, Host, MaintainLog, HostGroup, AccessRecord
45
from xadmin.layout import Main, TabHolder, Tab, Fieldset, Row, Col, AppendedText, Side
56
from xadmin.plugins.inline import Inline
67
from xadmin.plugins.batch import BatchChangeAction
@@ -9,12 +10,11 @@ class MainDashboard(object):
910
widgets = [
1011
[
1112
{"type": "html", "title": "Test Widget", "content": "<h3> Welcome to Xadmin! </h3><p>Join Online Group: <br/>QQ Qun : 282936295</p>"},
12-
{"type": "chart", "model": "app.accessrecord", 'chart': 'user_count', 'params': {'_p_date__gte': '2013-01-08', 'p': 1, '_p_date__lt': '2013-01-29'}},
13-
{"type": "list", "model": "app.host", 'params': {
14-
'o':'-guarantee_date'}},
13+
{"type": "chart", "model": "app.accessrecord", "chart": "user_count", "params": {"_p_date__gte": "2013-01-08", "p": 1, "_p_date__lt": "2013-01-29"}},
14+
{"type": "list", "model": "app.host", "params": {"o":"-guarantee_date"}},
1515
],
1616
[
17-
{"type": "qbutton", "title": "Quick Start", "btns": [{'model': Host}, {'model':IDC}, {'title': "Google", 'url': "http://www.google.com"}]},
17+
{"type": "qbutton", "title": "Quick Start", "btns": [{"model": Host}, {"model":IDC}, {"title": "Google", "url": "http://www.google.com"}]},
1818
{"type": "addform", "model": MaintainLog},
1919
]
2020
]
@@ -30,134 +30,160 @@ class BaseSetting(object):
3030
class GlobalSetting(object):
3131
global_search_models = [Host, IDC]
3232
global_models_icon = {
33-
Host: 'fa fa-laptop', IDC: 'fa fa-cloud'
33+
Host: "fa fa-laptop", IDC: "fa fa-cloud"
3434
}
35-
menu_style = 'default'#'accordion'
35+
menu_style = "default"#"accordion"
3636
xadmin.sites.site.register(views.CommAdminView, GlobalSetting)
3737

3838

3939
class MaintainInline(object):
4040
model = MaintainLog
4141
extra = 1
42-
style = 'accordion'
42+
style = "accordion"
4343

4444

4545
class IDCAdmin(object):
46-
list_display = ('name', 'description', 'create_time')
47-
list_display_links = ('name',)
46+
list_display = ("name", "description", "create_time")
47+
list_display_links = ("name",)
4848
wizard_form_list = [
49-
('First\'s Form', ('name', 'description')),
50-
('Second Form', ('contact', 'telphone', 'address')),
51-
('Thread Form', ('customer_id',))
52-
]
49+
("First's Form", ("name", "description")),
50+
("Second Form", ("contact", "telphone", "address")),
51+
("Thread Form", ("customer_id",))
52+
]
5353

54-
search_fields = ['name']
55-
relfield_style = 'fk-select'
54+
search_fields = ["name"]
55+
relfield_style = "fk-select"
5656
reversion_enable = True
5757

5858
actions = [BatchChangeAction, ]
59-
batch_fields = ('contact', 'groups')
59+
batch_fields = ("contact", "groups")
6060

6161

6262
class HostAdmin(object):
6363
def open_web(self, instance):
64-
return "<a href='http://%s' target='_blank'>Open</a>" % instance.ip
64+
return """<a href="http://%s" target="_blank">Open</a>""" % instance.ip
6565
open_web.short_description = "Acts"
6666
open_web.allow_tags = True
6767
open_web.is_column = True
6868

69-
list_display = ('name', 'idc', 'guarantee_date', 'service_type',
70-
'status', 'open_web', 'description')
71-
list_display_links = ('name',)
69+
list_display = (
70+
"name", "idc", "guarantee_date", "service_type", "status", "open_web",
71+
"description",
72+
)
73+
list_display_links = ("name",)
7274

73-
raw_id_fields = ('idc',)
74-
style_fields = {'system': "radio-inline"}
75+
raw_id_fields = ("idc",)
76+
style_fields = {"system": "radio-inline"}
7577

76-
search_fields = ['name', 'ip', 'description']
77-
list_filter = ['idc', 'guarantee_date', 'status', 'brand', 'model',
78-
'cpu', 'core_num', 'hard_disk', 'memory', ('service_type',xadmin.filters.MultiSelectFieldListFilter)]
78+
search_fields = ["name", "ip", "description"]
79+
list_filter = [
80+
"idc", "guarantee_date", "status", "brand", "model", "cpu", "core_num",
81+
"hard_disk", "memory", (
82+
"service_type",
83+
xadmin.filters.MultiSelectFieldListFilter,
84+
),
85+
]
7986

80-
list_quick_filter = ['service_type',{'field':'idc__name','limit':10}]
81-
list_bookmarks = [{'title': "Need Guarantee", 'query': {'status__exact': 2}, 'order': ('-guarantee_date',), 'cols': ('brand', 'guarantee_date', 'service_type')}]
82-
83-
show_detail_fields = ('idc',)
87+
list_quick_filter = ["service_type",{"field":"idc__name","limit":10}]
88+
list_bookmarks = [{
89+
"title": "Need Guarantee",
90+
"query": {"status__exact": 2},
91+
"order": ("-guarantee_date",),
92+
"cols": ("brand", "guarantee_date", "service_type"),
93+
}]
94+
95+
show_detail_fields = ("idc",)
8496
list_editable = (
85-
'name', 'idc', 'guarantee_date', 'service_type', 'description')
97+
"name", "idc", "guarantee_date", "service_type", "description",
98+
)
8699
save_as = True
87100

88101
aggregate_fields = {"guarantee_date": "min"}
89-
grid_layouts = ('table', 'thumbnails')
102+
grid_layouts = ("table", "thumbnails")
90103

91104
form_layout = (
92105
Main(
93106
TabHolder(
94-
Tab('Comm Fields',
95-
Fieldset('Company data',
96-
'name', 'idc',
97-
description="some comm fields, required"
98-
),
107+
Tab(
108+
"Comm Fields",
109+
Fieldset(
110+
"Company data", "name", "idc",
111+
description="some comm fields, required",
112+
),
99113
Inline(MaintainLog),
100114
),
101-
Tab('Extend Fields',
102-
Fieldset('Contact details',
103-
'service_type',
104-
Row('brand', 'model'),
105-
Row('cpu', 'core_num'),
106-
Row(AppendedText(
107-
'hard_disk', 'G'), AppendedText('memory', "G")),
108-
'guarantee_date'
109-
),
115+
Tab(
116+
"Extend Fields",
117+
Fieldset(
118+
"Contact details",
119+
"service_type",
120+
Row("brand", "model"),
121+
Row("cpu", "core_num"),
122+
Row(
123+
AppendedText("hard_disk", "G"),
124+
AppendedText("memory", "G")
125+
),
126+
"guarantee_date"
127+
),
110128
),
129+
),
111130
),
112-
),
113131
Side(
114-
Fieldset('Status data',
115-
'status', 'ssh_port', 'ip'
116-
),
132+
Fieldset("Status data", "status", "ssh_port", "ip"),
133+
)
117134
)
118-
)
119135
inlines = [MaintainInline]
120136
reversion_enable = True
121137

122-
data_charts = {
123-
"host_service_type_counts": {'title': u"Host service type count", "x-field": "service_type", "y-field": ("service_type",),
124-
"option": {
125-
"series": {"bars": {"align": "center", "barWidth": 0.8,'show':True}},
126-
"xaxis": {"aggregate": "count", "mode": "categories"},
127-
},
128-
},
129-
}
138+
data_charts = {"host_service_type_counts": {
139+
"title": u"Host service type count",
140+
"x-field": "service_type",
141+
"y-field": ("service_type",),
142+
"option": {
143+
"series": {
144+
"bars": {
145+
"align": "center",
146+
"barWidth": 0.8,
147+
"show": True,
148+
},
149+
},
150+
"xaxis": {
151+
"aggregate": "count",
152+
"mode": "categories",
153+
},
154+
},
155+
}}
130156

131157
class HostGroupAdmin(object):
132-
list_display = ('name', 'description')
133-
list_display_links = ('name',)
158+
list_display = ("name", "description")
159+
list_display_links = ("name",)
134160

135-
search_fields = ['name']
136-
style_fields = {'hosts': 'checkbox-inline'}
161+
search_fields = ["name"]
162+
style_fields = {"hosts": "checkbox-inline"}
137163

138164

139165
class MaintainLogAdmin(object):
140166
list_display = (
141-
'host', 'maintain_type', 'hard_type', 'time', 'operator', 'note')
142-
list_display_links = ('host',)
167+
"host", "maintain_type", "hard_type", "time", "operator", "note")
168+
list_display_links = ("host",)
143169

144-
list_filter = ['host', 'maintain_type', 'hard_type', 'time', 'operator']
145-
search_fields = ['note']
170+
list_filter = ["host", "maintain_type", "hard_type", "time", "operator"]
171+
search_fields = ["note"]
146172

147173
form_layout = (
148174
Col("col2",
149-
Fieldset('Record data',
150-
'time', 'note',
151-
css_class='unsort short_label no_title'
175+
Fieldset("Record data",
176+
"time", "note",
177+
css_class="unsort short_label no_title"
152178
),
153179
span=9, horizontal=True
154180
),
155181
Col("col1",
156-
Fieldset('Comm data',
157-
'host', 'maintain_type'
182+
Fieldset("Comm data",
183+
"host", "maintain_type"
158184
),
159-
Fieldset('Maintain details',
160-
'hard_type', 'operator'
185+
Fieldset("Maintain details",
186+
"hard_type", "operator"
161187
),
162188
span=3
163189
)
@@ -172,20 +198,20 @@ def avg_count(self, instance):
172198
avg_count.allow_tags = True
173199
avg_count.is_column = True
174200

175-
list_display = ('date', 'user_count', 'view_count', 'avg_count')
176-
list_display_links = ('date',)
201+
list_display = ("date", "user_count", "view_count", "avg_count")
202+
list_display_links = ("date",)
177203

178-
list_filter = ['date', 'user_count', 'view_count']
204+
list_filter = ["date", "user_count", "view_count"]
179205
actions = None
180-
aggregate_fields = {"user_count": "sum", 'view_count': "sum"}
206+
aggregate_fields = {"user_count": "sum", "view_count": "sum"}
181207

182208
refresh_times = (3, 5, 10)
183209
data_charts = {
184-
"user_count": {'title': u"User Report", "x-field": "date", "y-field": ("user_count", "view_count"), "order": ('date',)},
185-
"avg_count": {'title': u"Avg Report", "x-field": "date", "y-field": ('avg_count',), "order": ('date',)},
186-
"per_month": {'title': u"Monthly Users", "x-field": "_chart_month", "y-field": ("user_count", ),
210+
"user_count": {"title": u"User Report", "x-field": "date", "y-field": ("user_count", "view_count"), "order": ("date",)},
211+
"avg_count": {"title": u"Avg Report", "x-field": "date", "y-field": ("avg_count",), "order": ("date",)},
212+
"per_month": {"title": u"Monthly Users", "x-field": "_chart_month", "y-field": ("user_count", ),
187213
"option": {
188-
"series": {"bars": {"align": "center", "barWidth": 0.8,'show':True}},
214+
"series": {"bars": {"align": "center", "barWidth": 0.8,"show":True}},
189215
"xaxis": {"aggregate": "sum", "mode": "categories"},
190216
},
191217
},

demo_app/app/models.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.db import models
22
from django.contrib.auth.models import Group
33
from django.conf import settings
4+
from django.utils.encoding import python_2_unicode_compatible
45

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

@@ -22,7 +23,7 @@
2223
('mix', u"Mix"),
2324
)
2425

25-
26+
@python_2_unicode_compatible
2627
class IDC(models.Model):
2728
name = models.CharField(max_length=64)
2829
description = models.TextField()
@@ -35,14 +36,15 @@ class IDC(models.Model):
3536

3637
create_time = models.DateField(auto_now=True)
3738

38-
def __unicode__(self):
39+
def __str__(self):
3940
return self.name
4041

4142
class Meta:
4243
verbose_name = u"IDC"
4344
verbose_name_plural = verbose_name
4445

4546

47+
@python_2_unicode_compatible
4648
class Host(models.Model):
4749
idc = models.ForeignKey(IDC)
4850
name = models.CharField(max_length=64)
@@ -72,14 +74,15 @@ class Host(models.Model):
7274

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

75-
def __unicode__(self):
77+
def __str__(self):
7678
return self.name
7779

7880
class Meta:
7981
verbose_name = u"Host"
8082
verbose_name_plural = verbose_name
8183

8284

85+
@python_2_unicode_compatible
8386
class MaintainLog(models.Model):
8487
host = models.ForeignKey(Host)
8588
maintain_type = models.CharField(max_length=32)
@@ -88,7 +91,7 @@ class MaintainLog(models.Model):
8891
operator = models.CharField(max_length=16)
8992
note = models.TextField()
9093

91-
def __unicode__(self):
94+
def __str__(self):
9295
return '%s maintain-log [%s] %s %s' % (self.host.name, self.time.strftime('%Y-%m-%d %H:%M:%S'),
9396
self.maintain_type, self.hard_type)
9497

@@ -97,6 +100,7 @@ class Meta:
97100
verbose_name_plural = verbose_name
98101

99102

103+
@python_2_unicode_compatible
100104
class HostGroup(models.Model):
101105

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

111-
def __unicode__(self):
115+
def __str__(self):
112116
return self.name
113117

114118

119+
@python_2_unicode_compatible
115120
class AccessRecord(models.Model):
116121
date = models.DateField()
117122
user_count = models.IntegerField()
@@ -121,5 +126,5 @@ class Meta:
121126
verbose_name = u"Access Record"
122127
verbose_name_plural = verbose_name
123128

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

0 commit comments

Comments
 (0)