I'm building a FileUploadTempStore to handle file upload with deform and
I'm wondering how to access my beaker session object.
It works using :
session = pyramid.threadlocal.get_current_request().session
But since I ""shouldn't abuse thread locals"", I'm wondering how I
should do ?
Cheers
--
TJEBBES Gaston
Majerti
http://www.majerti.fr
Use a deferred to construct the FileUploadWidget. See
http://docs.pylonsproject.org/projects/colander/en/latest/binding.html
Here's an (untested and incomplete) example:
@colander.deferred
def deferred_upload_widget(field, bindargs):
request = bindargs['request']
session = request.session
tmpstore = MyTmpStore(session)
return deform.widget.FileUploadWidget(tmpstore)
class MyUploadSchema(colander.Schema):
upload = colander.SchemaNode(deform.FileData(),
widget=deferred_upload_widget)
upload_schema = MyUploadSchema()
then, in your view logic (where you have access to the request object):
schema = upload_schema.bind(request=request)
form = Form(schema, ...
Jeff