How could I alter the code of this method (from the Book of Zope, p. 122) so as to add multiple users from a list? Where I have 'abc' (adds one user abc) I want to add more than one user simultaneously (abc, xyz etc.), all with the same PW, role and domain. I tried inserting <dtml-in expr="['abc','xyz']"> where the 'abc' is and put </dtml-in> in the second last line but that generated a Parse Error <dtml-var standard_html_header> <h2><dtml-var title_or_id></h2> <dtml-call expr="REQUEST.set('roles',['noRole'])"> <dtml-call expr="REQUEST.set('name','abc')"> <dtml-call expr="REQUEST.set('password','change')"> <dtml-call expr="REQUEST.set('confirm','change')"> <dtml-call expr="REQUEST.set('domains',[])"> <dtml-call expr="acl_users.manage_users('Add',REQUEST,RESPONSE)"> The user <dtml-var name="name"> has been added. <dtml-var standard_html_footer> -- Bill
"Bill" == Bill Kerr <kerrb@senet.com.au> writes:
Bill> How could I alter the code of this method (from the Book of Bill> Zope, p. 122) so as to add multiple users from a list? Bill> Where I have 'abc' (adds one user abc) I want to add more Bill> than one user simultaneously (abc, xyz etc.), all with the Bill> same PW, role and domain. I tried inserting <dtml-in Bill> expr="['abc','xyz']"> where the 'abc' is and put </dtml-in> Bill> in the second last line but that generated a Parse Error The loop has to be outside the dtml-calls, and you can refer to the individual items with sequence-item, or in the case below, with 'user_item' (I prefer to use prefixes with my dtml-in tags because I think it makes the code more readable and easier to integrate with python calls) <dtml-var standard_html_header> <h2><dtml-var title_or_id></h2> <dtml-in "('abc', 'pdq', 'someuser')" prefix=user> <dtml-call "REQUEST.set('name', user_item)"> <dtml-call "REQUEST.set('password','change')"> <dtml-call "REQUEST.set('confirm','change')"> <dtml-call "REQUEST.set('domains',[])"> <dtml-call "REQUEST.set('roles',['noRole'])"> <dtml-call "acl_users.manage_users('Add',REQUEST,RESPONSE)"> The user <dtml-var user_item> has been added. </dtml-in> <dtml-var standard_html_footer> Hope this helps, John Hunter
From: "John Hunter"
The loop has to be outside the dtml-calls, and you can refer to the individual items with sequence-item, or in the case below, with 'user_item' (I prefer to use prefixes with my dtml-in tags because I think it makes the code more readable and easier to integrate with python calls)
<dtml-var standard_html_header> <h2><dtml-var title_or_id></h2> <dtml-in "('abc', 'pdq', 'someuser')" prefix=user> <dtml-call "REQUEST.set('name', user_item)"> <dtml-call "REQUEST.set('password','change')"> <dtml-call "REQUEST.set('confirm','change')"> <dtml-call "REQUEST.set('domains',[])"> <dtml-call "REQUEST.set('roles',['noRole'])"> <dtml-call "acl_users.manage_users('Add',REQUEST,RESPONSE)"> The user <dtml-var user_item> has been added. </dtml-in> <dtml-var standard_html_footer>
I think the list should be in square brackets not round brackets ie. <dtml-in "['abc', 'pdq', 'someuser']" prefix=user> not <dtml-in "('abc', 'pdq', 'someuser')" prefix=user> I've just tried your suggestion, John, but no joy, unfortunately (tried round brackets too but still didn't work) Error Type: NameError Error Value: global name 'user' is not defined Also tried <dtml-var standard_html_header> <h2><dtml-var title_or_id></h2> <dtml-in expr="['def','ghk','lmn']"> <dtml-call expr="REQUEST.set('roles',['noRole'])"> <dtml-call expr="REQUEST.set('name',sequence-item)"> <dtml-call expr="REQUEST.set('password','change')"> <dtml-call expr="REQUEST.set('confirm','change')"> <dtml-call expr="REQUEST.set('domains',[])"> <dtml-call expr="acl_users.manage_users('Add',REQUEST,RESPONSE)"> The user <dtml-var sequence-item> has been added. </dtml-in> <dtml-var standard_html_footer> This generated a similar sort of error message: Error Type: NameError Error Value: global name 'sequence' is not defined -Bill Kerr
Hope this helps, John Hunter
Hi John, Try this: <dtml-in expr="['def','ghk','lmn']"> <dtml-call expr="REQUEST.set('name',_['sequence-item'])"> The _ trick prevents zope from trying to subtract item from sequence. Cheers, Paz -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of Bill Kerr Sent: Monday, May 13, 2002 10:31 PM To: John Hunter Cc: zope@zope.org Subject: Re: [Zope] addng a list of users From: "John Hunter"
The loop has to be outside the dtml-calls, and you can refer to the individual items with sequence-item, or in the case below, with 'user_item' (I prefer to use prefixes with my dtml-in tags because I think it makes the code more readable and easier to integrate with python calls)
<dtml-var standard_html_header> <h2><dtml-var title_or_id></h2> <dtml-in "('abc', 'pdq', 'someuser')" prefix=user> <dtml-call "REQUEST.set('name', user_item)"> <dtml-call "REQUEST.set('password','change')"> <dtml-call "REQUEST.set('confirm','change')"> <dtml-call "REQUEST.set('domains',[])"> <dtml-call "REQUEST.set('roles',['noRole'])"> <dtml-call "acl_users.manage_users('Add',REQUEST,RESPONSE)"> The user <dtml-var user_item> has been added. </dtml-in> <dtml-var standard_html_footer>
I think the list should be in square brackets not round brackets ie. <dtml-in "['abc', 'pdq', 'someuser']" prefix=user> not <dtml-in "('abc', 'pdq', 'someuser')" prefix=user> I've just tried your suggestion, John, but no joy, unfortunately (tried round brackets too but still didn't work) Error Type: NameError Error Value: global name 'user' is not defined Also tried <dtml-var standard_html_header> <h2><dtml-var title_or_id></h2> <dtml-in expr="['def','ghk','lmn']"> <dtml-call expr="REQUEST.set('roles',['noRole'])"> <dtml-call expr="REQUEST.set('name',sequence-item)"> <dtml-call expr="REQUEST.set('password','change')"> <dtml-call expr="REQUEST.set('confirm','change')"> <dtml-call expr="REQUEST.set('domains',[])"> <dtml-call expr="acl_users.manage_users('Add',REQUEST,RESPONSE)"> The user <dtml-var sequence-item> has been added. </dtml-in> <dtml-var standard_html_footer> This generated a similar sort of error message: Error Type: NameError Error Value: global name 'sequence' is not defined -Bill Kerr
Hope this helps, John Hunter
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
"Paul" == Paul Zwarts <paz@oratrix.com> writes:
Paul> Try this: <dtml-in expr="['def','ghk','lmn']"> <dtml-call Paul> expr="REQUEST.set('name',_['sequence-item'])"> Hi Paul. I know the namespace dictionary lookup _['sequence-item'] syntax, but don't like it. That's why I used the prefix=user option above. I find <dtml-in "('abc', 'pdq', 'someuser')" prefix=user> <dtml-call "REQUEST.set('name', user_item)"> </dtml-in> more readable than <dtml-in "('abc', 'pdq', 'someuser')"> <dtml-call "REQUEST.set('name', _['sequence-item'])"> </dtml-in> Both are perfectly valid; it's a question of style. I also like the prefix syntax because it makes nested dtml loops easier, preserving the ability to refer to the items in the outer loops. <dtml-in "Sections.objectValues('Section')" prefix="section" sort="id"> <dtml-in "section_item.objectValues('Student')" prefix="student" sort="talk_datetime"> <dtml-comment> Make table rows alternate color based on section </dtml-comment> <dtml-if section_even> <tr bgcolor=<dtml-var color_section_even>> <dtml-else> <tr bgcolor=<dtml-var color_section_odd>> </dtml-if> <td>Blah></td> </tr> </dtml-in> </dtml-in> Thanks, John Hunter
"Bill" == Bill Kerr <kerrb@senet.com.au> writes:
Bill> I think the list should be in square brackets not round Bill> brackets ie. <dtml-in "['abc', 'pdq', 'someuser']" Bill> prefix=user> not <dtml-in "('abc', 'pdq', 'someuser')" Bill> prefix=user> I've just tried your suggestion, John, but no Bill> joy, unfortunately (tried round brackets too but still Bill> didn't work) Error Type: NameError Error Value: global name Bill> 'user' is not defined Parentheses, or 'round brackets', are for tuples, and square brackets are for lists. One of the important differences between tuples and lists is that lists are mutable, tuples not. y = [1, 2, 3] # list print y[1] # fine, read access permitted y[1] = 1 # ok, lists are mutable x = (1,2,3) # tuple print x[1] # also fine x[1] = 1 # not ok, tuples are immutable. raises TypeError So in my view, tuples are the natural structures to use for 'read only' sequences, as in the example of a list of users above. But either will work fine. I tested the example code I posted and it worked as expected on Zope-2.5. Cheers, John Hunter
participants (3)
-
Bill Kerr -
John Hunter -
Paul Zwarts