1
|
from django.utils.translation import ugettext as _
|
2
|
from django import forms
|
3
|
|
4
|
from .models import LocalAccount
|
5
|
|
6
|
|
7
|
class LocalAccountForm(forms.ModelForm):
|
8
|
|
9
|
class Meta:
|
10
|
exclude = ('organization', )
|
11
|
model = LocalAccount
|
12
|
widgets = {
|
13
|
'expiration_date': forms.DateInput(attrs={'class': 'datepicker'}),
|
14
|
'password': forms.PasswordInput
|
15
|
}
|
16
|
|
17
|
def save(self):
|
18
|
# save previous password
|
19
|
old_password = self.initial.get('password')
|
20
|
obj = super(LocalAccountForm, self).save(commit=False)
|
21
|
if not self.cleaned_data.get('password'):
|
22
|
obj.password = old_password
|
23
|
obj.save()
|
24
|
return obj
|
25
|
|
26
|
|
27
|
class LocalAccountCreateForm(LocalAccountForm):
|
28
|
accounts_number = forms.IntegerField(_('Number of accounts to create'), required=False)
|
29
|
accounts_number_start = forms.IntegerField(_('First number of multiple accounts'), required=False)
|