[Zope] overriding __str__ method?

Seb Bacon sebbacon@email.com
Mon, 9 Oct 2000 09:48:06 +0100


Thanks for the reply,

> Either I don't understand the problem or you're making it too
> complicated. <g>

I think both, but mostly the latter ;)

Explanation MK II:

I know how to create a form that does what I want (update properties,
whatever).  What I don't know is how to include it as part of the rendered
content programmatically.  At the moment users have to go to
www.widgets.com/manage_content, log in, and see a set of forms loosely based
on the Zope manage interface.  Instead, I'd like them to go to the same url,
and see exactly the same website as someone who's not logged in, except they
have these lovely little "edit this" buttons next to each editable content
element (by which I mean image, text snippet, etc).

Now I *could* do a

  <dtml-if "AUTHENTICATED_USER.has_role('content manager')">
    <a href="edit_this">edit this</a>
  </dtml-if>

in each content element. But I'd much rather be able to subclass or mixin an
'editable' class for each content element in question.  The question is,
what methods should I be providing to manipulate how the content is
rendered?  For example, I can provide a new 'view' method in the 'views' tab
for a ZClass, but this does not get called when an object is rendered as
part of another document.  The reason I was going on about __str__ is
because that seems to be the only place that you can interfere with how the
content is rendered inline?

Hope that's clearer,

seb.





>
> You have a form to edit the properties.
> ...
> <input type="text" name="last_name" value="&dtml-last_name;">
> ...
>
> The action method of this form sets the REQUEST variables to the
> property names:
> ...
> <dtml-call "REQUEST.set('last_name', REQUEST['last_name'])">
> ...
> (I generally use the same names for form vars and property names
> to avoid confusing myself)
>
> then:
> <dtml-call "manage_changeProperties(REQUEST)">
>
> Does this help?
> >
>
> Seb Bacon wrote:
>
> > My strategy:
> > Each element that I want the user to be able to edit is a ZClass with a
> > manage_content method.  This provides the custom management view (e.g.
> > combines properties and title/data into a single form).
> > Now I want a way to give the user access to this screen.  I
> could do a new
> > version of the folders tree view (manage_menu), but what I'd
> really like to
> > do is have a button next to each of these elements ("edit
> this") which calls
> > its manage_content method.  The button would only appear when
> the user was
> > authenticated / authorised.
> >
> > My problem:
> > The only place I can think of doing this is in each object's
> __str__ method.
> > But AFAIK there's no convenient way of overriding its default behaviour.
> > What I'd like to do is override it in the ZClass views interface.  I can
> > override the 'View' method (from the ZClass 'views' tab), but
> that doesn't
> > get called in the course of rendering a component in a page.
> The problem
> > would seem to be that there's no equivalent of the __str__
> method available
> > to override...  Or is there?