On 11/18/05, Chris Withers <[EMAIL PROTECTED]> wrote:
> Alan Warren wrote:
> > single image into a folder.  So, I have a folder called view.  When an
> > image is viewed the URL looks like
> > /some_album/some_pic.jpg/view/?display=large
> >
> > The code looks like this:
> > <span tal:define="imgName python:request['URL2'][len(request['URL3']+1:]">
> >     <span tal:define="global imgObj python:path('here/'+imgName)"></span>
> > </span>
> ouch.

> This is really contorted. Why do you use URL2 and URL3?

To extract just the id of the image being viewed.  The relative path
from the template that presents the image to the image being presented
will always match that pattern.

> Is imgObj not just 'here' anyway?
Not in a manner I could easily work with, view is a folder containing
index_html (the page template in question), and a handful of other
page templates and scripts -- all of which are specific actions a user
may wish to perform on a single image -- rather than on a whole album.

Given the scenario I've outlined, do you have another suggestion?
I agree this isn't aesthetically pleasing, but to me it was quite intuitive.

> What is the page template where this code comes from called?

> Why do you do a global define?
Because I'm godless.

> Why two define statements instead of just one?
So as to not post a massively long line of code to the list that would
be even more spaghetti like.  If it makes you feel any better the
actual code is more in the form:
<div tal:define="long_line here">
<!-- code that works on imgObj properties, -->

The question I was trying to answer wasn't about some coding style
issue, but rather about how to convert a string path to an object at
run-time.  I included the URL manipulation as an illustration of when
I had to use the path method.

Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to