Hello,

I have several forms that I subclass from a subclass of newforms:

# newforms is aliased as forms
class StrippedFieldsForm(forms.Form)
    def strip_field(self, field, error_message):
        if (self.clean_data.get(field)):
            data = self.clean_data[field].strip()
            if (0 == len(data)):
                raise forms.ValidationError(error_message)
            else:
                return data
        else:
            return ''

class DerivedForm(StrippedFieldsForm):
    # ... fields go here ...

    # ... for each field I have to do ...
    def clean_field1(self):
        return self.strip_field('field1', 'Field 1 contains only whitespace.')
    def clean_field2(self):
        return self.strip_field('field2', 'Field 2 contains only whitespace.')

This gets tedious as there are forms with 10 or more fields.

My question is, is there another way to apply strip_field to *all* or
a select list of fields automatically? My last resort is to override
form.clean() for StrippedFieldsForm.
-- 
_nimrod_a_abing_

http://abing.gotdns.com/
http://www.preownedcar.com/

--~--~---------~--~----~------------~-------~--~----~
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