[Zope-CMF] Re: Easiest way to make my own portal_type that is like CMFDocument but with extra properties

Tres Seaver tseaver@zope.com
Wed, 22 Aug 2001 08:25:17 -0400


Lynn Walton wrote:

> Tres, your answer's helped me greatly, particularly realizing where inheritance does NOT
> come into play.  Now I have one more thing I want to confirm.
> 
> After doing what I described earlier,  (made my own product, made a zclass in it  using
> CMFDocument as a Base class, gave that zclass some new properties,
> customized some skins for viewing/editing/editing metadata, here is how I ended up
> getting my properties to be saved. It seems to be working but I'm not sure if it is
> really the "right or best" way?
> 
> I made a custom skin, based on the document_edit that is in content which had:
> ------content's document_edit ------
> parameters: text_format, text, file='',  SafetyBelt=''
> 
> context.edit(text_format,
>              text,
>              file,
>              safety_belt=SafetyBelt)
> 
> qst='?portal_status_message=Document+changed.'
> context.REQUEST.RESPONSE.redirect( context.absolute_url() + '/document_edit_form' + qst
> )
> ------------------------
> 
> and I made my custom one take the extra 3 parameters for my 3 properties
> like:
> text_format, text, file='', topMenuExpand='', secondMenuExpand='', highlightMenu='',
> SafetyBelt=''
> 
> and added
> context.propertysheets.FU_CMFDocumentPropertySheet.manage_changeProperties({'topMenuExpand':topMenuExpand,'secondMenuExpand':secondMenuExpand,'highlightMenu':highlightMenu})
> 
> after the
> context.edit(text_format,
>              text,
>              file,
>              safety_belt=SafetyBelt)
> 
> and changed the return to be my custom edit_form skin
> context.REQUEST.RESPONSE.redirect( context.absolute_url() + '/FUDocument_edit_form' +
> qst )
> 
> 
> Does that sound right? Is there a better way to get the properties saved than calling
> manage_changeProperties and
> explicitly building the dict with the arguments?  Can you get it to get them from the
> request and if so how?


You can:


   - Call 'manage_changeProperties', passing the REQUEST object (which
     "smells like" a dictionary)::

      ps = context.propertysheets.FU_CMFDocumentPropertySheet
      ps.manage_changeProperties( context.REQUEST )

   - Call it with keyword arguments (this lets Python build the dictionary
     for you)::

      ps.manage_changeProperties( topMenuExpand=topMenuExpand
                                , seconMenuExpand=secondMenuExpand
                                , highlightMenu=highlightMenu
                                )

I favor the second version, as it is more explicit about what you
are passing.

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com