[Zope-CMF] Additional property to portal_type

Jeffrey Franks jfranks@quik.com
Sun, 04 Aug 2002 09:45:06 -0500


Tres Seaver wrote:
> 
> On Sun, 2002-08-04 at 09:23, Jeffrey Franks wrote:
> > Tres Seaver wrote:
> > >
> > > On Thu, 2002-08-01 at 19:44, Pawel Lewicki wrote:
> > >
> > > > Is there any simpler way to add an extra property to default CMFDocument
> > > > (e.g.) than overriding the whole class?
> > >
> > > ScriptableTypeInfo is your friend:
> > >
> > > http://cmf.zope.org/Members/tseaver/how_tos/using_scriptable_type_info
> > >
> > > You can add properties after creating the object using
> > > 'manage_addProperty', e.g.::
> > >
> > >   product.manage_addProperty( 'some_prop', 'initial value', 'string' )
> > >
> >
> > I'm applying this to a portal_type of 'File' with meta_type 'Portal File'
> >
> > I've added one attribute but can't view or edit it. I'm thinking that I
> > need to create a new meta type and add view/edit scripts.
> >
> > Is that what's needed?
> > How can I get view and edit of these added attributes?
> 
> You will need to customize the skin methods (ZPT,Python Script,DTML)
> which you use to render you objects.  For instance, if you have replaced
> the "stock" File type with your own, then you would need to customize
> the 'file_view' and 'file_edit_form' templates (ZPT in 'zpt_content'
> skin diretory; DTML in 'content') and the 'file_edit' script (in
> 'content') to handle your new property.
> 
> If your extended file type does *not* replace the standard File, then
> you probably want to create new skin methods for the view, edit form,
> and edit script (starting from the File versions).
> 
> Tres.
> --

The extended file type does *not* replace the standard File. It's just a
customized file with additional attributes. I did't get to the skinning
of this before I ran into another problem.

I've added the MyFile content type that has one new attribute from the
addMyFile python script that includes the lines:

	# Add a document number property
	product.manage_addProperty( 'docNumber', '', 'string' )

The problem is that I can now only add MyFile content type only once.
The second time I get an error 

	Error Type: Bad Request
	Error Value: Invalid or duplicate property id

The offending line is the product.manage_addProperty( 'docNumber', '', 'string' )
and so I guess I'm missing something either in application or implementation.

What did I do wrong?

-- jlf