Duncan McGreggor wrote:

>
> On Sep 27, 2005, at 11:54 AM, Benji York wrote:
>
>> Duncan McGreggor wrote:
>>
>>> My problem is that I haven't figured out how to point to this image,
>>> as it is part of the content object itself. Ideally, I would like to
>>> be able to refer to it in a ZPT via a URL. Something on the order of
>>> <img tal:attributes="src
>>> string:${context/@@absolute_url}/image_file" />
>>> Any ideas or code to which I could be pointed?
>>
>>
>> You could make the content object traversable, so you could do
>> http://path_to_object/image_file.
>
>
> Man, that sounds perfect...
>
> But! *sheepish grin* I've never done that before... is there someplace
> you could point me (and future readers of the list archives) where I
> could read about doing that (chapter of a book?) or some code in svn
> that shoes an example in a zcml file (I'm assuming this would be done
> in zcml?).
>
> Thanks, man!
>
> d
>

I've done something similar for caching images in a RAM Cache and
accessing them through a url. I simply added a page / BrowserView.

see:
http://svn.nuxeo.org/trac/pub/file/z3lab/cpsskins/branches/jmo-perspectives/browser/caching.py

If you remove the RAM cache part, your code could look like this (not
tested ....):

__init__.py:

from zope.app.file.browser.image import ImageData
from zope.app.file.image import Image
from zope.app.publisher.browser import BrowserView

class ImageView(BrowserView):
    """A view for accessing images.
    """

    def show(self)
        viewer = ImageData()
        viewer.context = Image(context.data)
        viewer.request = self.request
        return viewer()


configure.zcml :

  <pages
      for="zope.app.file.interfaces.IImage"
      class=".ImageView"
      permission="zope.Public">

    <page
        name="show"
        attribute="show"
    />

  </pages>


then access your image with http://path_to_object/image_file/show

/JM
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to