[Zope] How to apply arbitrary methods to objects?

seb sebbacon@email.com
Mon, 25 Sep 2000 13:40:37 +0100


Hi,

I'm trying to create an inline interface to manage_edit.  If a user is
authenticated, instead of seeing the default views of each snippet of
content, they get a textarea with a submit button for each snippet.

I'm still new to all this, so I'm not sure how I should be going about
it: a zclass with the content as a property?  a product that subclasses
DTMLDocument and overrides the __call__ method? I settled on creating a
DTML method, "editable", which works fine if you call it from the url
(code included at bottom of mail):

	http://mysite.com/snippet/editable

Inside "editable", when I call <dtml-var __str__> the content of the
parent object is returned, which is what I wanted.  The plan was,
whenever I had a snippet which I wanted to be editable, I would call it
inside my dtml thus:

	<dtml-var snippet/editable>

which of course doesn't work.  Eventually I found I had to do...

	<dtml-var "snippet.editable(REQUEST)">

...because the editable method doesn't inherit the context of snippet
like it does when you call it from the URL, and I needed to authenticate
the user.  But now I'm finding that the <dtml-var __str__> inside the
editable method is actually rendering the content of the page that the
snippet is in, rather than the snippet itself.

How should I call the editable method of snippet in such a way that it
inherits the context of snippet rather than the context of its parent? 
I've tried <dtml-with snippet><dtml-var editable></dtml-with> but then
editable can't access any other objects, e.g. update_content, in the
folder.  Perhaps I should be going about this completely differently?

Thanks

Seb

------------------------------
editable is a DTML method:

<dtml-if "AUTHENTICATED_USER.has_role('Manager')">
	<form action="update_content">
	<input type="text" name="title:text" value="<dtml-var title_or_id>">
	<textarea name="data:text" cols="30" rows="20">
	<dtml-var __str__>
	</textarea>
	<input type="submit">
	</form>
<dtml-else>
	<dtml-var __str__>
</dtml-if>

update_content is an external method:

def update_content(self,REQUEST):
	self.manage_edit(data=REQUEST.form["data"],title=REQUEST.form["title"])
	return REQUEST.form["data"]