Django

Code

Ticket #9933 (closed: fixed)

Opened 6 months ago

Last modified 6 months ago

Problem with FormWizard on last step.

Reported by: patrick91 Assigned to: nobody
Milestone: Component: django.contrib.formtools
Version: 1.0 Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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!

Attachments

Change History

12/30/08 11:56:28 changed by patrick91

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to fixed.
  • needs_tests changed.
  • needs_docs changed.

Add/Change #9933 (Problem with FormWizard on last step.)




Change Properties
Action