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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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?