1+ from __future__ import absolute_import
12import xadmin
23from xadmin import views
3- from models import IDC , Host , MaintainLog , HostGroup , AccessRecord
4+ from . models import IDC , Host , MaintainLog , HostGroup , AccessRecord
45from xadmin .layout import Main , TabHolder , Tab , Fieldset , Row , Col , AppendedText , Side
56from xadmin .plugins .inline import Inline
67from 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):
3030class 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"
3636xadmin .sites .site .register (views .CommAdminView , GlobalSetting )
3737
3838
3939class MaintainInline (object ):
4040 model = MaintainLog
4141 extra = 1
42- style = ' accordion'
42+ style = " accordion"
4343
4444
4545class 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
6262class 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
131157class 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
139165class 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 },
0 commit comments