On Fri, Apr 06, 2012 at 08:54:40AM +0200, tonthon wrote: > 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 ?
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 -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
