Opened 15 years ago

Closed 15 years ago

#9933 closed (fixed)

Problem with FormWizard on last step.

Reported by: patrick Owned by: nobody
Component: contrib.formtools Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi, I'm trying FormWizard but when I submit the last form I get this error:

ValidationError at /riparazioni/nuovo/
[u'Questo campo \xe8 obbligatorio.']

Instead of the page with the form and the errors visualized.
I get this error when the form is badly compiled and when is correctly compiled.
This is the form wizard:

class NewWorkSheetWizard(FormWizard):
    def done(self, request, forms):
        print forms
        
        return HttpResponse('ok')

this is the urlconf:

urlpatterns = patterns('',
    url(r'^nuovo/$', NewWorkSheetWizard([NewCustomerForm, NewCustomerForm]),
                                              name='add_new_worksheet_wizard'),
)

I'm using the same form just for test

This is the form:

class NewCustomerForm(forms.Form):
    first_name = forms.CharField(label=_('Nome'), max_length=30)
    last_name = forms.CharField(label=_('Cognome'), max_length=30)
    address = AddressField(label=_('Indirizzo'))
    
    email = forms.EmailField(label=_('E-mail'), required=False)
    fiscal_code = forms.CharField(label=_('Codice fiscale'),
                                                 max_length=16, required=False)
    vat_number = forms.CharField(label=_('Partita iva'),
                                                 max_length=11, required=False)
    telephone_number = forms.CharField(label=_('Numero di telefono'),
                                                                 max_length=11)
    fax_number = forms.CharField(label=_('Numero di fax'),
                                                 max_length=11, required=False)
    mobile_number = forms.CharField(label=_('Numero di cellulare'),
                                                 max_length=11, required=False)
    group = forms.ChoiceField(label=_('Gruppo'), choices=GROUPS)
    
    def create_username(self):
        n = self.cleaned_data.get('first_name').lower().replace("'", "")
        n = n.replace(' ', '_')
        s = self.cleaned_data.get('last_name').lower().replace("'", "")
        s = s.replace(' ', '_')

        i = 1

        nick_name = '%s_%s' % (n, s)

        while 1:
            try:
                user = User.objects.get(username=nick_name)
            except User.DoesNotExist:
                return nick_name
            
            nick_name = '%s%d' % (nick_name, i)
            i += 1
    
    def clean_fiscal_code(self):
        fiscal_code = self.cleaned_data.get('fiscal_code')
        
        if not fiscal_code:
            return ''
        
        regex = "[a-z]{6}\d{2}[abcdehlmprst]\d{2}[a-z]\d{3}[a-z]"
        pattern = re.compile(regex, re.I)
        
        if re.match(pattern, fiscal_code):
            return fiscal_code
        raise forms.ValidationError(_('Non sembra essere un codice fiscale'))
    
    def clean_vat_number(self):
        vat_number= self.cleaned_data.get('vat_number')
        
        if not vat_number:
            return ''
        
        if len(vat_number) != 11:
            raise forms.ValidationError(_('''La partita iva deve essere di
                                                              11 caratteri'''))
        return vat_number

Thanks for any reply!

Change History (1)

comment:1 by patrick, 15 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top