Arrggh! I'm getting very frustrated trying to accomplish something that should be easy. I'm stepping through all of the files in a LocalFS directory, and I want to dynamically create a <table> that displays all of the sub-directories of the current directory. I want to inject a "</tr><tr>" every so often, so I need to count the number of directories I've found so far to see whether I need to start a new row or not. I've spent a few hours digging through the list archives, so I know that creating a manually managed counter variable is not a straightforward affair. Here's the code that I have: <table> <dtml-call "REQUEST.set('ctr', 0)"> <dtml-in "fileValues(REQUEST.get('spec', _.None))"> <dtml-if "type == 'directory'"> <dtml-if "ctr % num_dir_columns == 0"> <tr> </dtml-if> <a href="<dtml-var URL1>/<dtml-var url>"><dtml-var "id"></a><br> <dtml-if "ctr % num_dir_columns == num_dir_columns - 1"> </tr> </dtml-if> <dtml-call "REQUEST.set('ctr', _.int(ctr) + 1)"> </dtml-if> </dtml-in> <dtml-comment> In case we end in the middle of a row... </dtml-comment> <dtml-if "ctr % num_dir_columns != 0"> </tr> </dtml-if> </table> The error I get, running Zope in debug mode, is this: Error Type: AttributeError Error Value: 'string' object has no attribute 'set' This is referring to the <dtml-call> line in the middle of the loop, the one that actually does the incrementing. It thinks that REQUEST is a string, which of course doesn't have a "set" attribute. I've been banging my head on this all day and can't come up with an way to accomplish this trivial task. I don't want to push this into Python; this is simple UI code, not business logic, so it doesn't belong there. Besides, it's absurd to think that I would need to write an external method or some other Python method to do something as simple as this. (It may end up being true, but it's still absurd... ;-) ) Any help would be greatly appreciated. thanks for your time, rob
I couldn't reproduce this. The following code works for me in Zope 2.1.6, verbatim. <dtml-var standard_html_header> <dtml-call "REQUEST.set('spec', '*')"> <dtml-call "REQUEST.set('num_dir_columns', 3)"> <table> <dtml-call "REQUEST.set('ctr', 0)"> <dtml-in "local.fileValues(REQUEST.get('spec', _.None))"> <dtml-if "type == 'directory'"> <dtml-if "ctr % num_dir_columns == 0"> <tr> </dtml-if> <td><a href="<dtml-var URL1>/<dtml-var url>"><dtml-var "id"></a><br> <dtml-if "ctr % num_dir_columns == num_dir_columns - 1"> </tr> </dtml-if> <dtml-call "REQUEST.set('ctr', _.int(ctr) + 1)"> </dtml-if> </dtml-in> <dtml-comment> In case we end in the middle of a row... </dtml-comment> <dtml-if "ctr % num_dir_columns != 0"> </tr> </dtml-if> </table> <dtml-var standard_html_footer> Maybe you can play with this as a starting point. I added a couple of REQUEST.set() calls at the top to simulate variables passed from a form, I assume. 'local' is my LocalFS object. Are you using this code in a <dtml-with> statement or are you actually serving it as a .dtml file from the local file system? --jfarr "Perl is worse than Python because people wanted it worse." Larry Wall, 14 Oct 1998
On Mon, 24 Jul 2000, Jonothan Farr wrote:
I couldn't reproduce this. The following code works for me in Zope 2.1.6, verbatim.
Ah-ha! It was on 2.2.0 that this code failed. And.. sure enough, a quick check on the Zope 2.1.6 install I still have around shows that the code works there for me as well. Thank goodness; I was pulling my hair out trying to figure out what I was doing wrong, but it seems likely to be a bug in the new release that was causing my problem.
<dtml-var standard_html_header> <dtml-call "REQUEST.set('spec', '*')"> <dtml-call "REQUEST.set('num_dir_columns', 3)"> <table> <dtml-call "REQUEST.set('ctr', 0)"> <dtml-in "local.fileValues(REQUEST.get('spec', _.None))"> <dtml-if "type == 'directory'"> <dtml-if "ctr % num_dir_columns == 0"> <tr> </dtml-if> <td><a href="<dtml-var URL1>/<dtml-var url>"><dtml-var "id"></a><br> <dtml-if "ctr % num_dir_columns == num_dir_columns - 1"> </tr> </dtml-if> <dtml-call "REQUEST.set('ctr', _.int(ctr) + 1)"> </dtml-if> </dtml-in> <dtml-comment> In case we end in the middle of a row... </dtml-comment> <dtml-if "ctr % num_dir_columns != 0"> </tr> </dtml-if> </table> <dtml-var standard_html_footer>
Maybe you can play with this as a starting point.
I added a couple of REQUEST.set() calls at the top to simulate variables passed from a form, I assume.
'local' is my LocalFS object. Are you using this code in a <dtml-with> statement or are you actually serving it as a .dtml file from the local file system?
It may be academic now, but I'm using it in a .dtml file that is called as a method by a python product. Actually, what I'm doing is hacking LocalFS to be an image gallery, so that all I have to do is drop a bunch of image files in a certain directory on my hard drive and they'll show up on the www all thumbnailed and prettified, via the magic of Zope. The code that you saw is from my replacement for the 'methodBrowse.dtml' file in the LocalFS product. I know that there are some other PhotoAlbum type products out there that do something similar, but I wanted the exercise. Thanks for your help... I guess now I report this as a bug. I've seen some mention of a "Collector" for this sort of thing; I'll go dig around zope.org (as soon as it comes back up) to find out what that is and how to use it. Unless of course any Zen masters notice this thread and decide to tackle the problem straightaway... ;-] rob
participants (2)
-
Jonothan Farr -
Rob Miller