Syntax for dtml-in property check?
I'm tripping over what seems like should be fairly straight-forward syntax. Hopefully someone here can point out what I'm overlooking. Situation: I have a folder that contains a bunch of folders, each of which has a property named "coach_id" that I've created and updated programmatically. Task: I have one user who is allowed to see the contents of all folders. All other users are restricted to folders where they are the Coach (i.e., where their AUTHENTICATED_USER== the coach_id of a particular folder). Approach: I have a DTML method that loops over all the folders and displays a list of folder links for each folder the user is authorized to see. That method works fine when I don't try to limit it by authenticated user name. I use a simple <dtml-in> construct for this purpose: <dtml-in expr="objectValues('Folder')" sort=title_or_id> I placed a <dtml-if> statement inside the <dtml-in> construct. That is where the problem is popping up. My if statement should look like this, I think: <dtml-if expr="(AUTHENTICATED_USER.getUserName() == 'Magic User') | (AUTHENTICATED_USER.getUserName() == sequence-var-coach_id)"> But I get an error from Zope indicating the public variable "sequence" isn't defined? I'm in a <dtml-in> so I *believe* sequence should have meaning. Am I wrong? I tried this with only one logic clause in case the problem was the OR syntax or logic. But this: <dtml-if expr="AUTHENTICATED_USER.getUserName() == sequence-item.coach_id"> produces the same "global variable sequence not defined" error. If i hard-code a name into that same sequence, the operation works but, of course, does not filter on the coach_id. <dtml-if expr="AUTHENTICATED_USER.getUserName() == 'Magic User'"> It seems evident that I'm missing something about how <dtml-in> works. I have believed that in the midst of a <dtml-in> I'm iterating over a sequence that is represented by the built-in Zope variable, "sequence." Evidently I'm wrong. Can anyone help? I feel like I'm just guessing at random possibilities now. Obviously time to raise a white flag. (I have to say, this happens so often with Zope that I often wonder if I'm just too dense to get good at this. I try to read and follow docs, but things just always end up slightly out of phase for me.)
On Thu, 2003-08-14 at 18:44, Dan Shafer wrote:
But I get an error from Zope indicating the public variable "sequence" isn't defined? I'm in a <dtml-in> so I *believe* sequence should have meaning. Am I wrong?
You're right, but not in a way that's helpful. :-) In a Python expression, "foo-bar" will evaluate as "foo minus bar" even though there are no spaces around the minus operator. Thus, the "sequence-" variables get misinterpreted when you attempt to use them inside a Python expression... which you are. In this case you need to use the prefix attribute of the dtml-in tag. It replaces "sequence-" with "foo_" (note the underscore) where foo is the value you assign to prefix. Example: <dtml-in my_sequence prefix=seq> <dtml-var seq_item> </dtml-in> You'll also need prefix when you nest one loop inside another. IMO, you may as well use prefix all the time... it's easier than trying to figure out when it will or won't apply. HTH, Dylan
participants (2)
-
Dan Shafer -
Dylan Reinhardt