[Zope] Getting role information
Martijn Faassen
M.Faassen@vet.uu.nl
Wed, 17 Feb 1999 16:31:38 +0100
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