-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathforms.py
More file actions
95 lines (76 loc) · 2.62 KB
/
forms.py
File metadata and controls
95 lines (76 loc) · 2.62 KB
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
from django.forms import ModelForm, Form, TypedChoiceField, CharField
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, Div, Field
from .models import Item, Identifier, IdentifierType
class SearchForm(Form):
identifier_types = [(i.id, i.name)
for i in IdentifierType.objects.all()]
identifier_types.insert(0, (0, 'Name'))
search_property = TypedChoiceField(
choices=identifier_types,
coerce=int,
empty_value=0
)
search_keyword = CharField()
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Div(
Div(
Field('search_property', css_class='form-helper'),
css_class='col-sm-6'
),
Div(
Field('search_keyword', css_class='form-helper'),
css_class='col-sm-6'
),
css_class='row'
)
)
super(SearchForm, self).__init__(*args, **kwargs)
class ItemForm(ModelForm):
class Meta:
model = Item
fields = ['name', 'desc', 'bucket']
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Div(
Div('name', css_class='col-md-6'),
Div('bucket', css_class='col-md-6'),
css_class='row'
),
Field('desc', rows=2, cols=50)
)
super(ItemForm, self).__init__(*args, **kwargs)
self.fields['bucket'].required = True
class BucketItemForm(ModelForm):
class Meta:
model = Item
fields = ['name', 'desc', 'bucket']
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Field('name'),
Field('desc', rows=2, cols=50),
Field('bucket', type='hidden')
)
super(BucketItemForm, self).__init__(*args, **kwargs)
class IdentifierForm(ModelForm):
class Meta:
model = Identifier
fields = ['type', 'value']
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Div(
Div('type', css_class='col-md-6'),
Div('value', css_class='col-md-6'),
css_class='row'
)
)
super(IdentifierForm, self).__init__(*args, **kwargs)