-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathforms.py
More file actions
348 lines (293 loc) · 11 KB
/
forms.py
File metadata and controls
348 lines (293 loc) · 11 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
from django import forms
from django.conf import settings
from django.contrib.auth.forms import UserCreationForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from stdnum.ar import cbu
from events.models import (
BankAccountData,
Event,
Invoice,
InvoiceAffect,
Organizer,
OrganizerRefund,
Payment,
Provider,
ProviderExpense,
Sponsor,
SponsorCategory,
Sponsoring,
SponsorshipDiscounts,
)
def validate_cbu(cbu_number, form):
if not cbu_number.isdigit():
form._errors["cbu"] = form.error_class(['El CBU tiene que tener sólo dígitos'])
elif len(cbu_number) != 22:
form._errors["cbu"] = form.error_class(['El CBU tiene que tener 22 dígitos'])
elif not cbu.is_valid(cbu_number):
form._errors["cbu"] = form.error_class(['El CBU especificado no es un CBU válido'])
class OrganizerUserSignupForm(UserCreationForm):
email = forms.EmailField(label=_('Correo Electrónico'), max_length=200, help_text='Required')
username = forms.CharField(label=_('Nombre de Usuario'))
def __init__(self, *args, **kwargs):
super(OrganizerUserSignupForm, self).__init__(*args, **kwargs)
self.fields['password1'].required = False
self.fields['password2'].required = False
# If one field gets autocompleted but not the other, our 'neither
# password or both password' validation will be triggered.
self.fields['password1'].widget.attrs['autocomplete'] = 'off'
self.fields['password2'].widget.attrs['autocomplete'] = 'off'
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
# TODO: ver layout para solo tener los campos requeridos.
self.helper.layout = Layout(
'username',
'email',
)
def clean_password2(self):
password1 = self.cleaned_data.get("password1")
password2 = super(OrganizerUserSignupForm, self).clean_password2()
if bool(password1) ^ bool(password2):
raise forms.ValidationError("Fill out both fields")
return password2
class Meta:
model = User
fields = ('username', 'email')
class EventUpdateForm(forms.ModelForm):
start_date = forms.DateField(
label=_('Fecha de inicio'),
input_formats=settings.DATE_INPUT_FORMATS, help_text=_('Formato: DD/MM/AAAA'),
widget=forms.widgets.DateInput(format=settings.DATE_INPUT_FORMATS[0]),
required=False
)
def __init__(self, *args, **kwargs):
super(EventUpdateForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.fields['name'].disabled = True
self.fields['commission'].disabled = True
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
class Meta:
model = Event
fields = ['name', 'commission', 'category', 'start_date', 'place']
class OrganizerUpdateForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(OrganizerUpdateForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
class Meta:
model = Organizer
fields = ['first_name', 'last_name']
class SponsorCategoryForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SponsorCategoryForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
class Meta:
model = SponsorCategory
fields = ['name', 'amount']
class SponsorshipDiscountForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SponsorshipDiscountForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
class Meta:
model = SponsorshipDiscounts
fields = ['name', 'description', 'discount', 'event']
class BankAccountDataForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(BankAccountDataForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
class Meta:
model = BankAccountData
fields = [
'organization_name', 'document_number', 'bank_entity',
'account_type', 'account_number', 'cbu'
]
def clean(self):
super(BankAccountDataForm, self).clean()
cbu_number = self.cleaned_data.get('cbu')
validate_cbu(cbu_number=cbu_number, form=self)
return self.cleaned_data
class SponsorForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SponsorForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-3"
self.helper.field_class = "col-sm-9"
class Meta:
model = Sponsor
fields = [
'organization_name',
'document_number',
'vat_condition',
'other_vat_condition_text',
'address',
'contact_info',
]
widgets = {
'contact_info': forms.Textarea(attrs={'rows': 4, 'cols': 40}),
}
class SponsoringForm(forms.ModelForm):
def __init__(self, event, *args, **kwargs):
super(SponsoringForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
# Pre-filter sponsorcategory by event
self.fields['sponsorcategory'].queryset = SponsorCategory.objects.filter(event=event)
self.fields['sponsor'].queryset = Sponsor.objects.filter(enabled=True)
self.fields['sponsorship_discount'].queryset = \
SponsorshipDiscounts.objects.filter(event=event)
class Meta:
model = Sponsoring
fields = [
'sponsorcategory',
'sponsor',
'sponsorship_discount',
'comments',
]
widgets = {
'comments': forms.Textarea(attrs={'rows': 4, 'cols': 40}),
}
class InvoiceForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(InvoiceForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
class Meta:
model = Invoice
fields = [
'amount',
'observations',
'document',
]
class InvoiceAffectForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(InvoiceAffectForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
class Meta:
model = InvoiceAffect
fields = [
'category',
'amount',
'observations',
'document',
]
class ProviderForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ProviderForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
self.fields['bank_entity'].required = False
self.fields['account_type'].required = False
self.fields['account_number'].required = False
self.fields['cbu'].required = False
class Meta:
model = Provider
fields = [
'organization_name',
'document_number',
'bank_entity',
'account_type',
'account_number',
'cbu',
]
def clean(self):
super(ProviderForm, self).clean()
cbu_number = self.cleaned_data.get('cbu')
if len(cbu_number) > 0:
validate_cbu(cbu_number=cbu_number, form=self)
return self.cleaned_data
class ProviderExpenseForm(forms.ModelForm):
invoice_date = forms.DateField(
label=_('Fecha factura'),
input_formats=settings.DATE_INPUT_FORMATS, help_text=_('Formato: DD/MM/AAAA'),
widget=forms.widgets.DateInput(format=settings.DATE_INPUT_FORMATS[0]),
required=True
)
def __init__(self, *args, **kwargs):
super(ProviderExpenseForm, self).__init__(*args, **kwargs)
# Pre-filter sponsorcategory by event
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
class Meta:
model = ProviderExpense
fields = [
'provider',
'amount',
'invoice_type',
'invoice_date',
'invoice',
'description',
]
class OrganizerRefundForm(forms.ModelForm):
invoice_date = forms.DateField(
label=_('Fecha factura'),
input_formats=settings.DATE_INPUT_FORMATS, help_text=_('Formato: DD/MM/AAAA'),
widget=forms.widgets.DateInput(format=settings.DATE_INPUT_FORMATS[0]),
required=True
)
def __init__(self, event, *args, **kwargs):
super(OrganizerRefundForm, self).__init__(*args, **kwargs)
# Pre-filter sponsorcategory by event
self.fields['organizer'].queryset = event.organizers.all()
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
class Meta:
model = OrganizerRefund
fields = [
'organizer',
'amount',
'invoice_type',
'invoice_date',
'invoice',
'description',
]
class PaymentForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PaymentForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = "col-sm-2"
self.helper.field_class = "col-sm-10"
class Meta:
model = Payment
fields = [
'document',
]