On 8/15/07, sime <[EMAIL PROTECTED]> wrote:
>
> >         class MyForm(Form)
> >            field1 = ...
> >            field2 = ...
> >
> >            def generic_clean(self):
> >               # ...
> >
> >            clean_field1 = generic_clean
> >            clean_field2 = generic_clean
>
> The problem here is generic_clean doesn't know which field it is, and
> I can't pass arguments that way? Don't think we have field.name or
> similar either.

If your verification logic wants to know what field is verifying now,
you can use closure.

def generic_clean(field):
    def func(self):
        # ...
    return func

clean_field1 = generic_clean('field1')
clean_field2 = generic_clean('field2')

It is simple, Pythonic and doesn't change core :-)

-- 
Vsevolod S. Solovyov

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

Reply via email to