i need the "request" for this custom validation in deform to work:
def d_validator(node, value):
if not value:
raise Invalid(node, 'Enter a Password')
if len(value) < 5:
raise Invalid(node, 'Invalid Length')
userid = authenticated_userid(userrequest)
dbsession = DBSession()
userInfo = dbsession.query(User).filter(_and(User.id==userid, User.password == value)).first()
if not userInfo:
raise Invalid(node, 'Invalid password')
so i tried this:
class Form(field.Field):
def __init__(self, schema, **kw):
self.saved_user = kw.pop('userrequest')
log.info(self.saved_user)
super(Form, self).__init__(schema, **kw)
and then:
Form(schema, buttons=('Actualizar',), 'userrequest'=request)
but i get SyntaxError: keyword can't be an expression
i know this could be python related, bear with me, thanks in advance
Keywords are indeed not expressions, but 'userrequest'=request
is. Remove the quotes:
Form(schema, buttons=('Actualizar',), userrequest=request)
Also, why are you basing your custom Form
class on field.Field
? I haven't used deform yet myself, but from a quick glance at the documentation suggest strongly you should be inheriting from deform.Form
instead.
Last but not least, you could fall back to the pyramid thread-local request instead:
def d_validator(node, value):
if not value:
raise Invalid(node, 'Enter a Password')
if len(value) < 5:
raise Invalid(node, 'Invalid Length')
userid = authenticated_userid(get_current_request())
dbsession = DBSession()
userInfo = dbsession.query(User).filter(_and(User.id==userid, User.password == value)).first()
if not userInfo:
raise Invalid(node, 'Invalid password')
Yes, this is often frowned upon, but could be easier in your case to deal with.