Hello! I’m just looking into Zine as I need a publishing platform that fits into our python-based infrastructure. I am currently taking Zine 0.1.2, since I need something stable atm. I am currently looking into using Zine as a publishing platform to create web/print versions of articles. My approach is to format articles in reST and write a plugin that offers a PDF version of each article. I already managed to connect to 'after-post-saved' and create a PDF version of reST formatted articles. Now I just need to hook into the post display and add a download link for each article. But I’m a bit stuck here. So I’m asking for any kind of help, be it someone already created such a plugin, or you can give me advice on how to add a download link to the posts dynamically, or even if you would advise a different approach altogether. Thanks in advance, Frederik
On Sat, Jul 31, 2010 at 12:45, Frederik Elwert <frederik.elwert@web.de>wrote: > or even if you would advise a different approach > altogether. > Frederik, I don't have the source in front of me right now, but some comments on your approach that might get you started. It sounds like you are generating a PDF in the local filesystem whenever a post is saved/updated. If this is the case, then you could either serve them from a static HTTP media server (if you have this setup), or setup a separate view function that will handle URL requests for them. The view could setup to listen for urls beginning with '/pdf/' or whatever you choose (this is done in the plugin init function). Then the rest of the URL will tell your view how to locate the post/item for which the user is requesting a PDF. I assume you have some sort of mapping from post_id or date to PDF file. Then just place a link into your post template that provides this mapping. Either create a macro that is available to the template to handle a lookup for this like 'pdf_url_for' or mirror the post's url with a pdf prefix (i.e. /pdf/blog/2010/08/02/hello-world/). A request would then go something like this: 1. Request for /pdf/blog/2010/08/02/hello-world/ 2. pdf_view( ) is called and a lookup is done on /blog/2010/08/02/hello-world/ to determine which post that is associated with. 3. Take this post's id, and lookup the file location of the PDF document that you wish to serve. 4. Somehow you need to tell Werkzeug/Zine that you're sending a PDF and not text/html and then write the PDF file to it. I'm not sure how this happens in Zine, but here's how it works in Django (note that this is dynamic): http://docs.djangoproject.com/en/dev/howto/outputting-pdf/ 5. ... That's it. I think this would be a lot easier if you serve from a static location and just build a link dymanically. It's been a while since I've dug through the weeds of Zine on this stuff. Hopefully others will comment and fill in the gaps or tell me how wrong I am ;-) -- Derek http://nethedz.org
Hey Derek,
thanks for your ideas and for pointing me in the right direction.
I did now manage to implement the basic mechanism, just needs some
polishing. I did now follow this road (but there might be better ways):
1. Create a filename from the slug.
2. Add a shared export for the PDF folder using
add_shared_exports('pdf', PDF_FILES)
3. On 'after_post_saved', create a PDF file in the PDF folder.
4. On 'before_entry_rendered', add a link for the PDF file to the
entry text using url_for('pdf/shared', filename=pdf_file_name)
Cheers,
Frederik
Frederik, that's awesome. That's even better, because one of the future goals of zine is to serve /_shared/ statically (if I remember the roadmap/notes correctly). Will you release this plugin when you are done? -- Derek Ditch derek.ditch@gmail.com Sent from a mobile device. On Aug 4, 2010, at 3:18 PM, Frederik Elwert <frederik.elwert@web.de> wrote: > Hey Derek, > > thanks for your ideas and for pointing me in the right direction. > > I did now manage to implement the basic mechanism, just needs some > polishing. I did now follow this road (but there might be better > ways): > > 1. Create a filename from the slug. > 2. Add a shared export for the PDF folder using > add_shared_exports('pdf', PDF_FILES) > 3. On 'after_post_saved', create a PDF file in the PDF folder. > 4. On 'before_entry_rendered', add a link for the PDF file to the > entry text using url_for('pdf/shared', filename=pdf_file_name) > > Cheers, > Frederik > >
Am Mittwoch, den 04.08.2010, 18:15 -0500 schrieb Derek Ditch: > Frederik, that's awesome. That's even better, because one of the > future goals of zine is to serve /_shared/ statically (if I remember > the roadmap/notes correctly). Glad to hear I didn’t make any obvious nonsense. ;-) Regarding static sharing: Yes, the comments in zine/application.py say something in that direction, too. > Will you release this plugin when you are done? /If/ it’s done, I’d be happy to release it. Currently, it’s more of a proof of concept, because we evaluate the use of Zine for a small online journal. If we decide to go that way and actually turn that plugin into something useful, I’ll release it somewhere. Cheers, Frederik