The two functions do not take the set of arguments.

insert(...) expects values after validation
validate_and_insert(....) expects values before validation

notice that validation is a transformation that changes the value. So given:

​db.define_table('myperson', 
                Field('name'),
                Field('password','password', requires=CRYPT()),
                )​

There are equivalent:
​
​def newperson1():
    db.myperson.insert(name="Smith1", password=CRYPT()("abc")[0])    

​​def newperson2():
    db.myperson.validate_and_insert(name="Smith2", password="abc")

On Saturday, 20 September 2014 01:44:19 UTC-5, mweissen wrote:
>
>
> This is my modeL
>
> ​db.define_table('myperson', 
>                 Field('name'),
>                 Field('password','password', requires=CRYPT()),
>                 )​
>
> ​And here are the functions:
> ​
> ​def newperson1():
>     db.myperson.insert(name="Smith1", password=CRYPT()("abc")[0])    
>
> ​​def newperson2():
>     db.myperson.validate_and_insert(name="Smith2", 
> password=CRYPT()("abc")[0])
>
> If there is no requires=CRYPT() in the model both functions work.
> With requires=CRYPT() only newperson1 is ok.
> The result of newpersion2 is:
>
> Ticket ID 
>
> 127.0.0.1.2014-09-20.08-39-58.b3a05144-6dcd-4374-895b-b217b56483f0
> <type 'exceptions.TypeError'> 'LazyCrypt' object has no attribute 
> '__getitem__' Version  web2py™ Version 
> 2.9.11-stable+timestamp.2014.09.15.23.35.11  Traceback 
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
>
> Traceback (most recent call last):
>   File "D:\Downloads\web2py_src299\web2py\gluon\restricted.py", line 224, in 
> restricted
>     exec ccode in environment
>   File 
> "D:/Downloads/web2py_src299/web2py/applications/test1/controllers/default.py" 
> <http://127.0.0.1:8001/admin/default/edit/test1/controllers/default.py>, line 
> 84, in <module>
>   File "D:\Downloads\web2py_src299\web2py\gluon\globals.py", line 392, in 
> <lambda>
>     self._caller = lambda f: f()
>   File 
> "D:/Downloads/web2py_src299/web2py/applications/test1/controllers/default.py" 
> <http://127.0.0.1:8001/admin/default/edit/test1/controllers/default.py>, line 
> 14, in newperson
>     db.myperson.validate_and_insert(name="Smith2", password=CRYPT()("abc")[0])
>   File "D:\Downloads\web2py_src299\web2py\gluon\dal.py", line 9328, in 
> validate_and_insert
>     value, error = self[key].validate(value)
>   File "D:\Downloads\web2py_src299\web2py\gluon\dal.py", line 10319, in 
> validate
>     (value, error) = validator(value)
>   File "D:\Downloads\web2py_src299\web2py\gluon\validators.py", line 2954, in 
> __call__
>     value = value and value[:self.max_length]
> TypeError: 'LazyCrypt' object has no attribute '__getitem__'
>
>
> ​​
> ​Regards, Martin​
>
>
> 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to