diff options
Diffstat (limited to 'ishtar/furnitures/forms.py')
-rw-r--r-- | ishtar/furnitures/forms.py | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index f152d27e4..536c1c037 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -35,6 +35,7 @@ from django.db.models import Max from django import forms from django.forms.formsets import formset_factory, BaseFormSet, \ DELETION_FIELD_NAME +from django.contrib.auth.models import User from formwizard.forms import NamedUrlSessionFormWizard @@ -129,6 +130,8 @@ class Wizard(NamedUrlSessionFormWizard): form_datas.append(("", "", "spacer")) for key in cleaned_data: lbl = None + if key.startswith('hidden_'): + continue if hasattr(base_form, 'fields') and key in base_form.fields: lbl = base_form.fields[key].label if not lbl: @@ -184,7 +187,7 @@ class Wizard(NamedUrlSessionFormWizard): obj = self.get_current_object(request, storage) if obj: for k in dct: - if k == 'pk': + if k.startswith('pk'): continue setattr(obj, k, dct[k]) else: @@ -384,7 +387,7 @@ class PersonForm(forms.Form): validators=[name_validator]) name = forms.CharField(label=_(u"Name"), max_length=30, validators=[name_validator]) - email = forms.CharField(label=_(u"Email"), max_length=40, + email = forms.CharField(label=_(u"Email"), max_length=40, required=False, validators=[validators.validate_email]) person_type = forms.ChoiceField(label=_("Person type"), choices=models.PersonType.get_types()) @@ -402,6 +405,60 @@ person_creation_wizard = PersonWizard([ ('final-person_creation', FinalForm)], url_name='person_creation',) +class AccountWizard(Wizard): + model = User + def get_formated_datas(self, forms): + datas = super(AccountWizard, self).get_formated_datas(forms) + for form in forms: + if not hasattr(form, "cleaned_data"): + continue + for key in form.cleaned_data: + if key == 'hidden_password' and form.cleaned_data[key]: + datas[-1][1].append((_("New password"), "*"*8)) + + return datas + +class PersonFormSelection(forms.Form): + form_label = _("Person") + associated_models = {'pk':models.Person} + currents = {'pk':models.Person} + pk = forms.IntegerField(label=_("Person"), + widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person'), + associated_model=models.Person), + validators=[models.valid_id(models.Person)]) + +class AccountForm(forms.Form): + form_label = _("Account") + pk = forms.IntegerField(widget=forms.HiddenInput, required=False) + username = forms.CharField(label=_(u"Account"), max_length=30) + email = forms.CharField(label=_(u"Email"), max_length=75, + validators=[validators.validate_email]) + hidden_password = forms.CharField(label=_(u"New password"), max_length=128, + widget=forms.PasswordInput, required=False, + validators=[validators.MinLengthValidator(4)]) + hidden_password_confirm = forms.CharField( + label=_(u"New password (confirmation)"), max_length=128, + widget=forms.PasswordInput, required=False) + + def clean(self): + cleaned_data = self.cleaned_data + password = cleaned_data.get("hidden_password") + if password and password != cleaned_data.get("hidden_password_confirm"): + raise forms.ValidationError(_(u"Your password and confirmation " +"password do not match.")) + if not cleaned_data.get("pk"): + models.is_unique(User, 'username')(cleaned_data.get("username")) + if not password: + raise forms.ValidationError(_(u"You must provide a correct \ +password.")) + return cleaned_data + +account_management_wizard = AccountWizard([ + ('selec-account_management', PersonFormSelection), + ('account-account_management', AccountForm), + ('final-account_management', FinalForm)], + url_name='account_management',) + class FileWizard(Wizard): model = models.File @@ -517,7 +574,7 @@ class FileFormGeneralRO(FileFormGeneral): numeric_reference = forms.IntegerField(label=_("Numeric reference"), widget=forms.TextInput(attrs={'readonly':True})) internal_reference = forms.CharField(label=_(u"Internal reference"), - widget=forms.TextInput(attrs={'readonly':True})) + widget=forms.TextInput(attrs={'readonly':True},)) class FileFormAddress(forms.Form): form_label = _("Address") |