[Grok-dev] Tramline works!

Souheil CHELFOUH trollfot at gmail.com
Tue Feb 16 11:22:01 EST 2010


You can join the Doc Team, on grok-doc mailing list and participate there :)
I'm glad you got it working.

2010/2/16 Hannes <hannes.flocke at gmx.li>:
> Hi Souheil,
>
> Finally, I got Tramline working!
>
> I can tell you, it was no kindergarden, I was sweating blood and
> tears....I'm having headakes now....
>
> Like I said, I'm going to write a tutorial about it. I would publish it on
> my blog, or can I write it directly "on" the Grok site?
>
>
> thanks,
> Hannes
>>
>> ---------- Forwarded message ----------
>> From: Martijn Faassen <faassen at startifact.com>
>> Date: 2010/2/5
>> Subject: [Grok-dev] tramline hints
>> To: grok-dev at zope.org
>>
>>
>> Hi there,
>>
>> I heard people were asking about how to use tramline. It's been some
>> time since I wrote it and hurry.file, but here are some hints.
>>
>> Here's the tramline README.txt and INSTALL.txt
>>
>> http://codespeak.net/svn/rr/tramline/trunk/README.txt
>>
>> http://codespeak.net/svn/rr/tramline/trunk/INSTALL.txt
>>
>> You set up Apache as in INSTALL.txt. You can tell it there where to
>> store the files on the filesystem.
>>
>> Tramline will magically turn all incoming file uploads in form submits
>> into small ids. These you can just store in the ZODB as if they were a
>> file, or a string, or whatever. Do make sure that after the upload you
>> add a 'tramline_ok' header to confirm things were uploaded all right and
>> accepted by the app server; if you don't (or if it never even gets there
>> due to security checks, etc) it won't be stored on the filesystem
>> either. But as long as you send out tramline_ok in the response header,
>> any file upload will always end up on the filesystem then.
>>
>> The trick is now to use Tramline to turn those ids back into files. To
>> do that, you just serve the id, for instance by doing this:
>>
>> class MyFileDownload(grok.View):
>>    def render(self):
>>         self.response.addHeader('tramline_file', 'ok')
>>         return self.context.the_stored_file_that_is_really_the_id
>>
>> the response header will signal tramline to look up that id in the
>> filesystem.
>>
>> Now hurry.file has machinery to help automate some of this.
>>
>> If you use hurry.file, you need to make sure you define a utility that
>> configures how to actually get the underlying file from the filesystem.
>> For instance:
>>
>> class TramlineFileRetrieval(TramlineFileRetrievalBase,
>>   grok.GlobalUtility):
>>
>>     grok.provides(IFileRetrieval)
>>
>>     def getTramlinePath(self):
>>          return ...
>>
>> where it returns a path to where the tramline file structure is stored.
>> This offers some functionality to be able to mess with files stored by
>> tramline directly from the application.
>>
>> More info on this is here:
>>
>> http://pypi.python.org/pypi/hurry.file
>>
>> and in the interfaces.py of hurry.file should you wish to use
>> IFileRetrieval directly.
>>
>> Once you use the hurry.file widget in your form, and you have tramline
>> configured as a front end, it'll now automatically store fake file
>> objects in the ZODB for you. You can still use these to access the data
>> on the file system, as if it were a Python object. It'll also send
>> tramline_ok. You'll still have to do tramline_file yourself when you
>> send out the file directly.
>>
>> Note that these days it might be easier to use a WSGI middleware to
>> accomplish the same effect as tramline, though I do suspect Tramline
>> probably offers quite a bit of performance.
>>
>> Regards,
>>
>> Martijn
>>
>> _______________________________________________
>> Grok-dev mailing list
>> Grok-dev at zope.org
>> https://mail.zope.org/mailman/listinfo/grok-dev
>>
>>
>
>


More information about the Grok-dev mailing list