[Twisted-web] freeform and adbapi
Stephan Cieszynski
darkblue.mail at gmx.net
Sun Apr 17 16:35:10 MDT 2005
Tommi Virtanen wrote:
> coerce cannot defer. To do that, move your validation into e.g. the
> start of an autocallable and do something like
>
> def foo(self, ctx, foo, bar):
> if not valid(foo):
> raise annotate.ValidateError(
> {'foo': 'Foo is bad.' },
> partialForm=ctx.locate(inevow.IRequest).args)
> ...
> foo = annotate.autocallable(foo)
>
> where the dict is variablename->errormessage. See ValidateError for
> more.
Sorry, but the following description lead me to use a deferred:
formless/iformless.py:
def coerce(self, val, configurable):
"""Coerce the input 'val' from a string into a value suitable
for the type described by the implementor. If coercion fails,
coerce should raise InputError with a suitable error message
to be shown to the user. 'configurable' is the configurable object
in whose context the coercion is taking place.
May return a Deferred.
-----------------------^
"""
Your example not working:
First, if 'foo' is a deferred the callback isn't fired at this time and
validating isn't possible. Second, raising an exception in a
autocallable like this
def foo(self, ctx, bar):
def _cb(r):
if not valid(r):
raise annotate.ValidateError(...)
bar.addCallback(_cb)
take no effect at rendering time and the slot('error') isn't filled with
our errormessage.
Stephan
More information about the Twisted-web
mailing list