Hi everybody, I'm trying to write an external method that returns different HTML snippets (actually structured text) depending on which role the person requesting the page has. The idea is to give different info to the viewer if the user happens to be a manager (or some other role) vs anonymous. This way, one could for instance include extra hyperlinks (for example to 'manage this page'). Is something like this possible at all? Perhaps such info isn't sent to anonymous pages. And if it's possible, how does one do it? The goal behind this question is to produce pages which have content that is very easy to change. The anonymous user would see the normal page, and a user that has a special 'editor' role would instead see (if the user first logged in as editor) extra hyperlinks. Clicking on such a link would bring up a page with a textarea field, where the editor can change the text (in structured text format). All texts would be stored in properties of the folder, or possibly in other documents. The external method would look somewhat like this: def editable(self, id, REQUEST=None): """Completely fictional and nonfunctional code, based on misconceptions. """ # we know of no such id, so give error if not hasattr(self, id): return "[error] No such id: %s" % id if REQUEST.AUTHENTICATED_USER.has_role("editor"): # if we are the editor, we want to show a hyperlink to edit_<id here> # or something similar edit_hyperlink = "<a href=\"edit_%s\">%s</a>" % (id, id) # hyperlink gets prefixed to actual text return edit_hyperlink + structured_text(getattr(self, id)) else: # just return the text, formatted in structured text format return structured_text(getattr(self, id)) Would this be a good idea? Can one get this working at all? Regards, Martijn
On 17 Feb 99, at 16:31, Martijn Faassen wrote:
I'm trying to write an external method that returns different HTML snippets (actually structured text) depending on which role the person requesting the page has. The idea is to give different info to the viewer if the user happens to be a manager (or some other role) vs anonymous. This way, one could for instance include extra hyperlinks (for example to 'manage this page').
Is something like this possible at all? Perhaps such info isn't sent to anonymous pages. And if it's possible, how does one do it?
My standard_html_header has this line <!--#call "REQUEST.set('isManager',AUTHENTICATED_USER.hasRole(_.None,['Manager']))"--> My standard_html_footer has this: <!--#if isManager--> <br><p align="right" class="HotLink"> <a class="HotLink" href="<!--#var URL0-->/manage_main">Edit This Page</a> <!--#endif--> This is stolen from the www.zope.org site. You can use their dhtml viewer to see pages that don't have a "show DHTML" hyperlink on them by typing in the appropriate URL directly. Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com ICQ: 14856937
Brad Clements wrote:
On 17 Feb 99, at 16:31, Martijn Faassen wrote: [I wanted role information]
My standard_html_header has this line
<!--#call "REQUEST.set('isManager',AUTHENTICATED_USER.hasRole(_.None,['Manager']))"-->
My standard_html_footer has this:
<!--#if isManager--> <br><p align="right" class="HotLink"> <a class="HotLink" href="<!--#var URL0-->/manage_main">Edit This Page</a> <!--#endif-->
Cool! Looks like it is what I need. Thanks!
This is stolen from the www.zope.org site. You can use their dhtml viewer to see > pages that don't have a "show DHTML" hyperlink on them by typing in the > appropriate URL directly.
Ah, I didn't know one could do that. Studying their 'show DTML' link tells me how. Thanks again. I should study www.zope.org's DTML more often, I see. Regards, Martijn
Hmmm... [userobject].hasRole doesn't need the _.None. The definition actually is: hasRole(list_of_roles) Returns true if user has one or more roles from list_of_roles. So yo ucan test on AUTHENTICATED_USER.has_role(['Manager', 'Editor']), for example. -- M.J. Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-6254545 Fax: +31-35-6254555 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
Well, the original worked for me but taking out the _.None made it show up for annonymous users as well. Beats me what is going on here, I just glean the list for things that look useful to me and cut and paste, while I wait for a decent DTML reference. Speaking of which, is there a list of attributes for things anywhere? Like where would someone come up with AUTHENTICATED_USER.has_role() if not swiped from the www.zope.org site? I thought AUTHENTICATED_USER was just the name of the user and here it has attributes! Phil.
Hmmm...
[userobject].hasRole doesn't need the _.None. The definition actually is:
hasRole(list_of_roles) Returns true if user has one or more roles from list_of_roles.
So yo ucan test on AUTHENTICATED_USER.has_role(['Manager', 'Editor']), for example.
----------------------------------------------------------- Philip Aylesworth mailto:purple@mnsi.net
At 20:05 17-2-99 , you wrote:
Well, the original worked for me but taking out the _.None made it show up for annonymous users as well.
Woops. That's my testing style for you.
Beats me what is going on here, I just glean the list for things that look useful to me and cut and paste, while I wait for a decent DTML reference.
Speaking of which, is there a list of attributes for things anywhere? Like where would someone come up with AUTHENTICATED_USER.has_role() if not swiped from the www.zope.org site? I thought AUTHENTICATED_USER was just the name of the user and here it has attributes!
I am playing with the idea of setting up a documentation project. I know python has this wonderful selfdocumentation feature built right in, but the Zope Help interface only gives docs on a limited number of objects, and the sourcecode docs are incomplete. The documentation should include a DTML reference, an object reference, a HOWTO section and a tutorial section. Using Zope user folders we can also include Product documentation, brought to you by the authors themselves. If someone gives me some space on a Zope server (our company is completely behind a firewall, and I don't have any external serverspace to do this on right now), we can work out a structure and fill in all the blanks we have now. I believe DigiCool mentioned something on their site about hosting community projects? We can make zope.org the Zope equivalent of Mozilla.org.
participants (5)
-
Brad Clements -
Martijn Faassen -
Martijn Pieters -
Martijn Pieters -
Philip Aylesworth