Could you implement a FormValidator subclass which took a table name
as a parameter to __init__? That way you could use the plain old
@validate. (untested code follows)
class TableValidator(FormValidator):
def __init__(self, name, *l, **kw):
real_validator = formsByTable[name]
self.__dict__.update(real_validator.__dict__) # tricky, don't
know if this will work....
On Mar 20, 3:29 pm, "percious" <[EMAIL PROTECTED]> wrote:
> """
> As many of you know I have been working on a project to replace
> both FastData and Catwalk in one fail swoop. Right now we are sort
> of stuck on field validation because we need extra information in our
> validation routines in order to process the table definitions
> generically
> """
>
> import toscawidgets.widgets.forms
> from turbogears.controller import RootController
>
> formsByTable = {'a':TableForm(id='formA'),
> 'b':TableForm(id='formB'),
> 'c':TableForm(id='formC'),
> }
>
> def root(RootController):
>
> @expose(...)
> def addRecordView(self, tableName **kw):
> form = formsByTable[tableName]
> return dict(form=form)
>
> @expose()
> @error_handler(addRecordView)
> @myValidate(formsByTable)
> def add(self, tableName):
> pass
>
> """
> The idea here is that my validate function will take the table name
> from the
> arglist and generate validation on table provided the lookup to the
> formsByTable
> dictionary.
> """
>
> #Here is a first-try at the validate function which fails miserably
>
> def myValidate(forms):
> def wrapper(func):
> def entangle(self, tableName, **kw):
> form=forms[tableName]
> validated = validate(form=form)
> validated = validated(func)
> validated = validated(func, [self, tableName],
> **kw)
> return validated
> return entangle
>
> return wrapper
>
> If anyone has any Idea how to do this it would be great for us, and
> also a bonus to the TG community. For those of you who have been
> following on on the dbmechanic deveopment, the project has been moved
> out of the "pycon" development path on to our own.
>
> cheers.
> -chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---