request object usage in wtforms with alchemy's scaffold in pyramid 1.7

66 views
Skip to first unread message

Jérôme Pigeot

unread,
Aug 8, 2016, 1:35:42 PM8/8/16
to pylons-discuss
Hello, 

I'm using the new sqlalchemy scaffold introduced in pyramid 1.7 and wtforms to handle my forms. 
with this configuration, you have to get the dbsession from the request object. 
In previous versions, you just had to import the DBSession object to use it in modules.

Here's an example of a pyramid 1.6 usage: 

in choices.py:
    from myapp.models import DBSession, Country 

    def country_choices() 
        countries = DBSession.query(Country).order_by(Country.name) 

in forms.py:
    from wtforms.form import Form 
    from wtforms_sqlalchemy.fields import QuerySelectField 

    class MyForm(Form) 
       name = TextField(u"name") 
       country = QuerySelectField(u'country', query_factory=country_choices) 

As you can see, my country_choices method doesn't have access to the request object. 
My question is:
How to handle that kind of usage with the new dbsession management in alchemy's scaffold?

Thanks,
Jérôme.
Reply all
Reply to author
Forward
0 new messages