Hi folks,
I want to make a schema + a form connecting to SQLAlchemy and be able to identify if an username is unique and emails are unique. I am using these as a base:
For example,
class Signup(formencode.Schema):
"""Form fields to render and validate for signup."""
allow_extra_fields=True
filter_extra_fields=True
username = UniqueUsername(not_empty=True)
email = UniqueEmail(resolve_domain=False, not_empty=True)
password = Password(not_empty=True)
confirm = Password(not_empty=True)
chained_validators = [
validators.FieldsMatch(
'password',
'confirm'
)
]
In the example from simpleauth he has a function called get_existing_user that UniqueUsername is calling in the _validate_python method.
I wanted to use what the current Pyramid documentation suggests, which is, having a request.dbsession that you propagate through your code instead of a global variable.
Is there any way to make pyramid_simpleform / formencode receive the request.dbsession?
I couldn't figure out from the docs, tried some parameters like state and extra but no juice. In the end I did something like:
from pyramid.threadlocal import get_current_request
request=get_current_request().dbsession
Which the Pyramid docs tells not to do and I don't want to.
Thanks!
--
Atenciosamente/Regards
André Castelan Prado