From: Hancock, D. \(DHANCOCK\) <DHA...@ar...> - 2005-05-25 16:19:19
|
First, thanks for all the assistance so far with ZPTKit and FEComponent and FormEncode. We're getting close to understanding things. A developer in our group (not a list member) asked me to post the following questions: The FormEncode documentation and the FEComponent frequently state that we can call validators.to_python, which apparently returns a requestDict that we are in dire need of. After looking at all the source, we noticed that validators.py doesn't have a to_python method but instead has a _to_python() for each validator that inherits from FancyValidator. We tried using the to_python() in the api.py->FancyValidator class but the arguments are different. For example: =20 The to_validator in api.py, FancyValidator.py, etc are all defined as: =20 def to_validator(value, state): =20 The FEComponent.fecomponent.py tries to make a call to validators.to_python(NestedVariables, rawFields), which doesn't exist. The other problem is that NestedVariables is a class in variabledecode.py that is derived from api.FancyValidator() so the to_python here is doing something much different. I guess what I'm trying to say is that this was doing some magic we are unable to reproduce. =20 Do you know if we can find an older version of FormEncode or better yet, point us in a direction where we can see what the above to_python is really doing? =20 One thing to note is that we had to make changes right out of the box to get FormEnocode working since htmlform.py was trying to import something from validator and not validators. Thanks, and Cheers! -- David Hancock | dha...@ar... | 410-266-4384=20 |
From: michelts <mic...@gm...> - 2005-05-25 16:45:15
|
Hum, Sorry david, I think it was my fault, I forgot the update of the formencode, I used the Validator package, it is outdated but I didn't have a time to test it, I will do this test and conversion tomorrow... > The FormEncode documentation and the FEComponent frequently state that we > can call validators.to_python, which apparently returns a requestDict tha= t > we are in dire need of. After looking at all the source, we noticed tha= t > validators.py doesn't have a to_python method but instead has a _to_pytho= n() > for each validator that inherits from FancyValidator. We tried using th= e > to_python() in the api.py->FancyValidator class but the arguments are > different. For example:=20 >=20 > =20 > The to_validator in api.py, FancyValidator.py, etc are all defined as:=20 > =20 > def to_validator(value, state):=20 > =20 > The FEComponent.fecomponent.py tries to make a call to > validators.to_python(NestedVariables, rawFields), which doesn't exist. T= he > other problem is that NestedVariables is a class in variabledecode.py tha= t > is derived from api.FancyValidator() so the to_python here is doing > something much different. I guess what I'm trying to say is that this wa= s > doing some magic we are unable to reproduce.=20 rawFields is a dictionary like this: {'name':'Michel', 'document.id':'415', 'document.date':'2005-02-26', 'action.ok':'Ok'} Validating (converting) it with NestedVariables converts it to: {'name':'Michel', 'document':{'id':'415', 'date':'2005-02-26'}, 'action':{'ok':'Ok'}} Undestand? It comes from the variabledecode module, I don't know the problem know, but maybe is the validator package I using is outdated... > Do you know if we can find an older version of FormEncode or better yet, > point us in a direction where we can see what the above to_python is real= ly > doing?=20 Take a look at the FancyValidator code: def to_python(self, value, state=3DNone): return self.attempt_convert(value, state, self.validate_other,=20 self._to_python, self.validate_python) If you take a look at the attempt_convert code you will understand the usage, I'm not very clear about this but I think may use to_python on your own validators or use the combination of validate_other, _to_python and validate_python... Anyway, any validator extended from FancyValidator has a to_python method. I will upgrade the FEComponent to the last svn FormEncode tomorrow, sorry any mistake :) I didn't have the time to update formencode, I use validator package on a working project... regards, --=20 Michel Thadeu Sabchuk Curitiba - Brasil |
From: Ian B. <ia...@co...> - 2005-05-25 17:34:48
|
michelts wrote: >>Do you know if we can find an older version of FormEncode or better yet, >>point us in a direction where we can see what the above to_python is really >>doing? > > > Take a look at the FancyValidator code: > > def to_python(self, value, state=None): > return self.attempt_convert(value, state, self.validate_other, > self._to_python, self.validate_python) > > If you take a look at the attempt_convert code you will understand the > usage, I'm not very clear about this but I think may use to_python on > your own validators or use the combination of validate_other, > _to_python and validate_python... Anyway, any validator extended from > FancyValidator has a to_python method. .to_python() is the public API; FancyValidator adds some things like ifEmpty, notEmpty, and ifInvalid to that, and calls ._to_python() to do the real validation. -- Ian Bicking / ia...@co... / http://blog.ianbicking.org |