Using deform and filedepot together in a Pyramid app

16 views
Skip to first unread message

Luke Tunmer

unread,
Sep 30, 2020, 8:09:02 AM9/30/20
to pylons-discuss

Hi,

I'm struggling to get a form which uses a FileUploadWidget to cooperate with a model that uses filedepot's UploadedFileField as a column type. It works fine on Windows, but fails on a "posix" like platform - both Linux and Mac.

The problems seems to be that when I extract the "fp" entry from the value of my particular widget it seems to be a different thing between the two platforms. On Windows this is a tempfile._TemporaryWrapper, which contains a _io.BufferedRandom in it's 'file' attribute. On Posix the 'fp' entry is the io.BufferedRandom object directly.

Down in the guts of depot this object (called 'content') is then expected to have a 'filename' attribute, or failing that 'name' attribute. It happens to have a 'name' attribute, but this is the integer value of the socket descriptor and not any file name. The code is expecting to have a str at this point, and so an exception is raised.

I'm sure that combining these two technologies is quite common, so I must be doing something wrong.

I have also had to patch another "impedance mismatch" between these two libraries - the FileData that is passed to the colandar.SchemaNode has to be overridden to fix the lack of 'uid' attribute in the data that is being serialized. Is there something I have to do in the deserialize method as well?

Many thanks for any help.
Regards
Luke

Andreas Kaiser

unread,
Sep 30, 2020, 9:10:27 AM9/30/20
to pylons-discuss

Hi Luke,

unfortunately I don’t have the time to look up the details right now, but Kotti (https://github.com/Kotti/Kotti/) has been using Deform and Filedepot for years. It has an additional layer (for historical reasons) with its File resource type, so that may not translate 1:1 to your use case, but you might find some information in its sources, especially https://github.com/Kotti/Kotti/blob/master/kotti/resources.py#L721.

HTH,
Andreas

Luke Tunmer

unread,
Sep 30, 2020, 1:25:09 PM9/30/20
to pylons-...@googlegroups.com
Thanks, Andreas, for the pointer to kotti. I tried to use the FileUploadTempStore implementation that kotti uses with the deform upload widget instead of the standard from one from pyramid_deform.SessionFileUploadTempStore, hoping that it's __getitem__ and __setitem__ were going to change how this works. Sadly it didn't - the problem seems to be closer to the depot side of things rather than the deform.

Has someone got an example of a working combo of these two libraries? I can add more detail about the form schema that I used to connect this all up. As I said, it works on Windows, but fails on Posix platforms, so I can't be too wrong.

Thanks again,
Luke


--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/85F70C79-E652-4E0C-8ACE-B72C83BF9617%40binary-punks.com.
Reply all
Reply to author
Forward
0 new messages