Here's another brainstorm that's sort of a combination.  :)  It's a
Form that handles confirmation validation, but does so at the field
level.  Code will help illuminate what I mean:

class ConfirmForm(forms.Form):
    """
    ...
    """
    def __init__(self, *args, **kwargs):
        super(ConfirmForm2,self).__init__(*args,**kwargs)

        for name in self.fields.keys():
            if name.startswith('confirm_'):
                compare_field = name.replace('confirm_','')
                setattr(self,'clean_%s' % name,
                        self._make_confirmation_method(compare_field,
name))

    def _make_confirmation_method(self, field_name,
confirm_field_name):
        return lambda: self._confirm_fields_match(field_name,
                                                  confirm_field_name)
    def _confirm_fields_match(self, field_name, confirm_field_name):
        if self[field_name].data != self[confirm_field_name].data:
            raise ValidationError('This field must match the %s field'
\
                                  % field_name)
        return self.clean_data.get(confirm_field_name)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to