restrictedTraverse() and encapsulated image Codesource with VMH

Heiko Besemann <[email protected]> Mon, 13 Jul 2009 10:52:28 +0200
Newsgroups gmane.comp.web.zope.silva.devel
Message-ID <9a2f462a07463f17958857f315b8411c@localhost>
Hi all,

my name is Heiko and I am the technical maintainer of www.noordsee.de, a
small website running Silva 2.1. Currently I am migrating content from an
older legacy website to a new publication within noordsee.de's root folder
and found a problem with code source encapsulated image using
restrictedTraverse().

For the setup (all absolute paths beginning from the Silva root:

(1) /cms        # This is the noordsee.de's Silva root (virtual host
monstered as www.noordsee.de)
(2) /cms/watt   # This is the new publications root folder (currently
vhm'ed as beta.noordsee.de, the folder is marked as virtual host within
Silva)
(3) /cms/watt/pictures/test.jpg  # Here is my image object located
(4) /cms/watt/watt_allgemein/gezeiten/sturmflut # Here I want to
encapsulate an image found in (3)

The problem I run into is when I want to link a code source encapsulated
image found in (3) to a Silva document found in (4). Code source stores
only "/pictures/test.jpg" as the image_path, whereas restrictedTraverse()
called from "/watt_allgemein/gezeiten/sturmflut" would need the absolute
path (3).
This happends only for virtual hosts. When I put as a workaound the image
file within the same folder where the document is located it works ok.
Nevertheless to get a more structured website a separate pictures folder
would be good.

So my question to the folks the at silva-dev is how can I modify
encapsulated image code source to get the full absolute path needed by
restrictedTraverse()? Funny thing is that linking an image with the
standard image koopu menu function Silva returns the full absolute path.

On the code source site the fomulator view uses the following call to
launch Silva object browser:

(onclick event fired)

reference.getReference(
function(path, id, title) {
document.getElementsByName('%(field_id)s')[0].value = path;;
}, '%(url)s', 'Silva Image', true)

Would it be clever to change the onclick function to use the same function
the standard image selector uses? Or would it be clever to modify the
template file used by code source encapsulated image? There I found the
following line...

...
imagepath    options/image_path;
image        python: context.restrictedTraverse(str(imagepath));
...

And last but not least: What tweak do I need to write into the template or
onclick function to fix the path?

Cheers and thanks in advance,
Heiko