[Zope-CMF] metadata elements

Dan Keshet dkesh@channel1.com
Fri, 10 Aug 2001 10:57:13 -0400 (EDT)


Norbert Marrale  <norbert@attira.com> wrote:
 
> Dan posted someting to this list, before Tres' update of the
> portal_metadata tool, about being successful in customizing the
> metadata_edit_form, could you or others who also managed to do so
> share this knowledge?

Here's all the steps I did to add my new metadata element.

1) Added it using portal_metadata TTW
2) Updated metadata_edit_form

My DTML is different because I don't use the portal_metadata tool to
determine my "allowedCategories".  Looking over Norman's, I noticed some
inconsistency in variable names and some other problems.  DTML, comments,
at bottom.

3) Updated metadata_edit script (python)

Added my new metadata element in the same style as all the rest.

4) Updated DublinCore.py in CMFDefault

Added my new metadata element in the same style: added a setCategory()
method; added a "category=''" parameter to _editMetadata; added a
self.setCategory( category ) line in _editMetadata.

This is the only way I could think of to add this to all content types
without subclassing every single one.

Hope this helps,

Dan

--------------

My DTML from Step 2:

<select name="category">
     <option value=""> None </option>
     <dtml-let AllowedCategory="GetCategory()" SelectedCategory="category">
     <dtml-in AllowedCategory>
     <dtml-let item=sequence-key sel="item == SelectedCategory and 'selected'
or ''">
      <option value="&dtml-sequence-key;" &dtml-sel;> &dtml-title;
</option>
     </dtml-let>
     </dtml-in>
     </dtml-let>
</select>

GetCategory() is a method acquired from somewhere else.  Note that you can
only be in one category at a time using what I wrote.

Norman's DTML from Step 2 (slightly re-formatted):

<dtml-let contentCategory=Category 
allowedSubjects="portal_metadata.listAllowedCategory( this() )">

<dtml-in Category>
<dtml-let item=sequence-item>
<dtml-unless expr="item in allowedCategory">
<dtml-var sequence-item>
</dtml-unless></dtml-let></dtml-in></textarea>

<br>
<select name="category:list" multiple>
     <dtml-in allowedCategory>
     <dtml-let item=sequence-item
               sel="item in contentCategory and 'selected' or ''">
      <option value="&dtml-sequence-item;"
              &dtml-sel;> &dtml-sequence-item; </option>
     </dtml-let>
     </dtml-in>
</select>
</dtml-let>

A few problems here: 

- I don't understand why you have the textarea stuff, followed by a select
list.

- You're setting category, but looking for Category.  Note the case. (This
is the one that's generating the error right now, I think.)

- listAllowedCategory is not a free method.  You need to add it to your
MetadataTool in CMFDefault in the style of listAllowedSubject if you want
to use it. Alternately, you could make listAllowedVocabulary() public in
your MetadataTool, and pass in the metadata element.

-