-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
197 lines (174 loc) · 8.11 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# -*- coding: utf-8 -*-
from django.forms import *
from inv.models import *
#from wolf.utils.dell import sn2esc
class SupplierForm(ModelForm):
class Meta:
model = Supplier
fields = ['name', 'seller', 'address', 'phone', 'email', 'notes']
widgets = {
'name': TextInput(attrs={'class': 'form-control'}),
'seller': TextInput(attrs={'class': 'form-control'}),
'address': TextInput(attrs={'class': 'form-control'}),
'phone': TextInput(attrs={'class': 'form-control'}),
'email': EmailInput(attrs={'class': 'form-control'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
class ServerCPUForm(ModelForm):
class Meta:
model = ServerCPU
fields = ['name', 'manufacturer', 'cores', 'speed', 'l3cache', 'notes']
widgets = {
'name': TextInput(attrs={'class': 'form-control'}),
'manufacturer': Select(attrs={'class': 'form-control'}),
'cores': NumberInput(attrs={'class': 'form-control'}),
'speed': NumberInput(attrs={'class': 'form-control'}),
'l3cache': NumberInput(attrs={'class': 'form-control'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
class ServerMemoryForm(ModelForm):
class Meta:
model = ServerMemory
fields = ['memory_type', 'speed', 'size', 'notes']
widgets = {
'memory_type': Select(attrs={'class': 'form-control'}),
'speed': NumberInput(attrs={'class': 'form-control'}),
'size': NumberInput(attrs={'class': 'form-control'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
class ServerHDForm(ModelForm):
class Meta:
model = ServerHD
fields = ['name', 'manufacturer', 'hd_type', 'speed', 'size', 'capacity', 'notes']
widgets = {
'name': TextInput(attrs={'class': 'form-control'}),
'manufacturer': TextInput(attrs={'class': 'form-control'}),
'hd_type': Select(attrs={'class': 'form-control'}),
'speed': NumberInput(attrs={'class': 'form-control'}),
'size': Select(attrs={'class': 'form-control'}),
'capacity': NumberInput(attrs={'class': 'form-control'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
class ServerRaidLevelForm(ModelForm):
class Meta:
model = ServerRaidLevel
fields = ['name', 'min_hds', 'max_hds', 'notes']
widgets = {
'name': TextInput(attrs={'class': 'form-control'}),
'min_hds': NumberInput(attrs={'class': 'form-control'}),
'max_hds': NumberInput(attrs={'class': 'form-control'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
class ServerRaidCardForm(ModelForm):
class Meta:
model = ServerRaidCard
fields = ['name', 'manufacturer', 'cache', 'battery', 'support_raids', 'notes']
widgets = {
'name': TextInput(attrs={'class': 'form-control'}),
'manufacturer': TextInput(attrs={'class': 'form-control'}),
'cache': NumberInput(attrs={'class': 'form-control'}),
'battery': CheckboxInput(attrs={'class': 'form-control'}),
'support_raids': CheckboxSelectMultiple(attrs={'class': 'form-control'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
class ServerNICForm(ModelForm):
class Meta:
model = ServerNIC
fields = ['name', 'manufacturer', 'speed', 'eom', 'notes']
widgets = {
'name': TextInput(attrs={'class': 'form-control'}),
'manufacturer': TextInput(attrs={'class': 'form-control'}),
'speed': NumberInput(attrs={'class': 'form-control'}),
'eom': CheckboxInput(attrs={'class': 'form-control'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
class ServerAssetTemplateForm(ModelForm):
class Meta:
model = ServerAssetTemplate
fields = ['name', 'manufacturer', 'height', 'exterior', 'suppliers',
'cpu', 'cpu_number', 'max_cpu_number',
'memory', 'memory_number', 'max_memory_number',
'notes',
]
widgets = {
'name': TextInput(attrs={'class': 'form-control'}),
'manufacturer': TextInput(attrs={'class': 'form-control'}),
'height': NumberInput(attrs={'class': 'form-control'}),
'exterior': ClearableFileInput(attrs={'class': 'form-control'}),
'suppliers': CheckboxSelectMultiple(attrs={'class': 'form-control'}),
'cpu': Select(attrs={'class': 'form-control'}),
'cpu_number': NumberInput(attrs={'class': 'form-control'}),
'max_cpu_number': NumberInput(attrs={'class': 'form-control'}),
'memory': Select(attrs={'class': 'form-control'}),
'memory_number': NumberInput(attrs={'class': 'form-control'}),
'max_memory_number': NumberInput(attrs={'class': 'form-control'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
def clean_cpu_number(self):
cpu_number = int(self.data.get('cpu_number'))
max_cpu_number = int(self.data.get('max_cpu_number'))
if cpu_number > max_cpu_number:
self._errors['cpu_number'] = self.error_class([u'CPU鏁扮洰瓒呰繃鏈�澶ф敮鎸佺殑CPU鏁�'])
return cpu_number
def clean_memory_number(self):
memory_number = int(self.data.get('memory_number'))
max_memory_number = int(self.data.get('max_memory_number'))
if memory_number > max_memory_number:
self._errors['memory_number'] = self.error_class([u'鍐呭瓨鏁扮洰瓒呰繃鏈�澶ф敮鎸佺殑鍐呭瓨鏁�'])
return memory_number
class SwitchAssetTemplateForm(ModelForm):
class Meta:
model = SwitchAssetTemplate
fields = ['name', 'manufacturer', 'height', 'exterior', 'suppliers',
'notes',
]
widgets = {
'name': TextInput(attrs={'class': 'form-control'}),
'manufacturer': TextInput(attrs={'class': 'form-control'}),
'height': NumberInput(attrs={'class': 'form-control'}),
'exterior': FileInput(attrs={'class': 'form-control'}),
'suppliers': CheckboxSelectMultiple(attrs={'class': 'form-control'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
class ServerTemplateHDSForm(ModelForm):
class Meta:
model = ServerTemplateHDS
exclude = ['server']
widgets = {
'hd_type': Select(attrs={'class': 'form-control'}),
}
class ServerTemplateNICSForm(ModelForm):
class Meta:
model = ServerTemplateNICS
exclude = ['server']
widgets = {
'nic_type': Select(attrs={'class': 'form-control'}),
}
class ServerAssetForm(ModelForm):
class Meta:
model = ServerAsset
fields = ['template', 'supplier', 'sn', 'esc', 'purchase_date', 'notes']
widgets = {
'template': Select(attrs={'class': 'form-control'}),
'supplier': Select(attrs={'class': 'form-control'}),
'sn': TextInput(attrs={'class': 'form-control'}),
'esc': TextInput(attrs={'class': 'form-control', 'placeholder': u'鑷姩鐢熸垚(浠呴檺DELL璁惧)', 'disabled': ''}),
'purchase_date': DateInput(attrs={'class': 'form-control', 'type': 'Date'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}
def clean_esc(self):
sn = self.cleaned_data.get('sn')
#ecs = sn2esc(sn)
return sn
#return ecs
class SwitchAssetForm(ModelForm):
class Meta:
model = SwitchAsset
fields = ['template', 'supplier', 'sn', 'purchase_date', 'notes']
widgets = {
'template': Select(attrs={'class': 'form-control'}),
'supplier': Select(attrs={'class': 'form-control'}),
'sn': TextInput(attrs={'class': 'form-control'}),
'purchase_date': DateInput(attrs={'class': 'form-control', 'type': 'Date'}),
'notes': Textarea(attrs={'class': 'form-control'}),
}