[Zope] String to object ID

Chris McDonough chrism@digicool.com
Sun, 5 Dec 1999 16:43:33 -0500


> >You wanna design your site around string representations of objects.
> >Well, who am I to say no?!
> 
> We are always open to other ideas!
> 
> But consider this (from a website builders point of view and not a
> Zopeista's point of view). I have a website with 2000+ pages and 200+
> folders. I want to have a header displayed with a unique set 
> of graphics
> for each page based on the page name and the parent directory name.
> 
> http://www.mysite.com/firstlevel/firstpage.html
> 
> this page would display a graphic named "firstlevelFirstpage.gif"
> 
> This makes perfect sense from an organizational standpoint, 
> if I need to
> replace one of 1100 images I can find the image just by 
> knowing the page it
> would be displayed on. Conversly I know which image every 
> page requires by
> virtue of knowing the pages location within the website.

Do you want to store all your graphics in a single folder?  Or will
there be multiple folders for images?

> 
> What we are tying to do is write a method that can be sent a string
> constructed from the existing properties of a page (document_id and
> folder_id), then find and display the appropriate graphic.
> 
> This way we can place a single line of common dtml in any 
> page and display
> the proper graphic;
> 
> <dtml-var myimageMethod(Document_id, Folder_id, "some_identifier")>
> 
> Currently Zope is making it very difficult to do this because 
> it will not
> accept a string representation of a Zope object. We have tried many
> different ways, all wrong, all due to our own lack of 
> understanding the
> Zope namespace and python.

The getitem thingy is your savior here... but it doesn't accept a
dot-delimited string.  You have to find the base object first, then go
from there.

> 
> Tools like this would make building large group maintained 
> website much
> easier, reuseable code, templates, universal methods, all 
> combined give you
> the ability to add/subtract/modify pages easily. Dealing with a large
> constantly changing website this is very important to us.  We 
> need to be
> able to give our artist a simple naming scheme for imagry and 
> our designer
> a single tag to use for ALL images.
> 
> It seems the code you sent will do this but I don't think you 
> liked it ;^)

I didn't much like it aesthetically, but it works!  It also doesn't
account for pages with a URL path obtained through acquisition (e.g.
http://mysite.com/a/space/separated/string/a).  But if it works for you,
that's all that really matters... you sort of constrain yourself in a
non-Zope way by using it, but... as you said, looking at it from a site
builders point of view it may make some sort of sense.

I would probably be more apt to put the images directly in the folder
you're displaying.  E.g. put the images for "firstlevel" in "firstlevel"
and name them "firstpage.gif", etc.  Then you could just call them using
getitem once and maniupulating the string.  But tomato, tomatoe, it's
your show!

> . We also went down the same road last night thinking it may 
> be the way to
> do what we wanted (converting the string to a url path and 
> returning the
> image tag to the calling document)

I think it is the way to go.  For now.  Until we figure out how to do
what you really want to do :-).

> 
> But, we are open to any suggestions to solve the problem.
> 
> Thanks for all the help, we'll give your code a try.

No problem, good luck!