[Zope-CMF] Changing portal_metadata tool

Tres Seaver tseaver@palladion.com
Mon, 30 Jul 2001 23:32:01 -0400


Dan Keshet wrote:

> Hi,
> 
> I want to add an Element to the portal_metadata tool.  Are there plans to make
> metadata Elements configurable?


Products.CMFDefault.MetadataTool.MetadataTool actually has methods for
adding and removing "element specs" (which is what you want).  The DTML
does not (yet) have any UI which uses these methods, although adding such
UI is pretty trivial.  *hacks for about 15 minutes*.  Yep, I can now add
and remove element specs on the "Properties" tab of the tool.  I will check
the changes in shortly;  in the meantime, see the diffs below.

>  Right now, is it possible to change the
> metadata tool without creating a whole new CMF site?   I can't seem to add or
> delete a portal_metadata tool...


You should be able to delete it freely in the ZMI;  adding one is trickier,
as you have to know that it is contained in the "CMFDefault Tool" "jumbo
factory."


> So I tried playing with MetadataTool.py, and adding to the list of
> DEFAULT_ELEMENT_SPECS, but that doesn't seem to have an effect. 
> 
> Also, I noticed later down that each Element has it's own listAllowed function. 
> Why not make listAllowedVocabulary public and pass the Element type in?  Would
> this make it easier to add Elements?


There was a private method, '_listAllowedVocabulary';  I made it
public, removing the '_'.  Thanks for the suggestion!


diff -u -r1.6 MetadataTool.py
--- CMFDefault/MetadataTool.py  4 Jun 2001 10:53:02 -0000       1.6
+++ CMFDefault/MetadataTool.py  31 Jul 2001 03:29:01 -0000
@@ -462,7 +462,7 @@

      security.declareProtected( CMFCorePermissions.ManagePortal
                               , 'addElementSpec' )
-    def addElementSpec( self, element, is_multi_valued ):
+    def addElementSpec( self, element, is_multi_valued, REQUEST=None ):
          """
              Add 'element' to our list of managed elements.
          """
@@ -472,14 +472,26 @@

          self.element_specs[ element ] = ElementSpec( is_multi_valued )

+        if REQUEST is not None:
+            REQUEST[ 'RESPONSE' ].redirect( self.absolute_url()
+               + '/propertiesForm'
+               + '?manage_tabs_message=Element+' + element + '+added.'
+               )
+
      security.declareProtected( CMFCorePermissions.ManagePortal
                               , 'removeElementSpec' )
-    def removeElementSpec( self, element ):
+    def removeElementSpec( self, element, REQUEST=None ):
          """
              Remove 'element' from our list of managed elements.
          """
          del self.element_specs[ element ]

+        if REQUEST is not None:
+            REQUEST[ 'RESPONSE' ].redirect( self.absolute_url()
+               + '/propertiesForm'
+               + '?manage_tabs_message=Element+' + element + '+removed.'
+               )
+
      security.declareProtected( CMFCorePermissions.ManagePortal, 
'listPolicies' )
      def listPolicies( self, typ=None ):
          """
@@ -513,8 +525,8 @@
          """
          return self.publisher

-    security.declarePrivate( '_listAllowedVocabulary' )
-    def _listAllowedVocabulary( self, element, content=None ):
+    security.declarePublic( 'listAllowedVocabulary' )
+    def listAllowedVocabulary( self, element, content=None ):
          """
              List allowed keywords for a given meta_type, or all
              possible keywords if none supplied.
@@ -529,7 +541,7 @@
              List allowed keywords for a given meta_type, or all
              possible keywords if none supplied.
          """
-        return self._listAllowedVocabulary( 'Subject', content )
+        return self.listAllowedVocabulary( 'Subject', content )

      security.declarePublic( 'listAllowedFormats' )
      def listAllowedFormats( self, content=None ):
@@ -537,14 +549,14 @@
              List the allowed 'Content-type' values for a particular
              meta_type, or all possible formats if none supplied.
          """
-        return self._listAllowedVocabulary( 'Format', content )
+        return self.listAllowedVocabulary( 'Format', content )

      security.declarePublic( 'listAllowedLanguages' )
      def listAllowedLanguages( self, content=None ):
          """
              List the allowed language values.
          """
-        return self._listAllowedVocabulary( 'Language', content )
+        return self.listAllowedVocabulary( 'Language', content )

      security.declarePublic( 'listAllowedRights' )
      def listAllowedRights( self, content=None ):
@@ -553,7 +565,7 @@
              selection list;  this gets especially important where
              syndication is involved.
          """
-        return self._listAllowedVocabulary( 'Rights', content )
+        return self.listAllowedVocabulary( 'Rights', content )

      security.declarePrivate( 'setInitialMetadata' )
      def setInitialMetadata( self, content ):


diff -u -r1.1 metadataProperties.dtml
--- CMFDefault/dtml/metadataProperties.dtml     28 Apr 2001 22:57:00 
-0000      1.1
+++ CMFDefault/dtml/metadataProperties.dtml     31 Jul 2001 03:29:01 -0000
@@ -4,17 +4,68 @@
  <h3> Update Metadata Tool Properties </h3>

  <form action="editProperties" method="POST">
-<table class="FormLayout">
+<table>

- <tr>
-  <th> Publisher: </th>
+ <tr valign="middle">
+  <th width="100" align="right"> Publisher: </th>
    <td> <input type="text" name="publisher"
                value="&dtml-getPublisher;" size="40"> </td>
   </tr>

- <tr>
+ <tr valign="middle">
    <td> <br> </td>
    <td> <input type="submit" value=" Change "> </td>
+ </tr>
+
+</table>
+</form>
+
+<h3> Add Metadata Element </h3>
+
+<form action="&dtml-absolute_url;/addElementSpec" method="POST">
+<input type="hidden" name="is_multi_valued:int:default" value="0">
+<table>
+
+ <tr valign="middle">
+  <th width="100" align="right"> Element: </th>
+  <td> <input type="text" name="element" size="20"> </td>
+ </tr>
+
+ <tr valign="middle">
+  <th width="100" align="right"> Multi-valued? </th>
+  <td> <input type="checkbox" name="is_multi_valued:boolean"> </td>
+ </tr>
+
+ <tr valign="middle">
+  <td> <br> </td>
+  <td> <input type="submit" value=" Add "> </td>
+ </tr>
+
+</table>
+</form>
+
+<h3> Remove Metadata Element </h3>
+
+<form action="&dtml-absolute_url;/removeElementSpec" method="POST">
+<table>
+
+ <tr valign="middle">
+  <th width="100" align="right"> Element: </th>
+  <td> <dtml-in listElementSpecs>
+       <dtml-if sequence-start>
+       <select name="element">
+       </dtml-if>
+       <option value="&dtml-sequence-key;"> &dtml-sequence-key; </option>
+       <dtml-if sequence-end>
+       </select>
+       </dtml-if>
+       </dtml-in>
+  </td>
+ </tr>
+
+ <tr valign="middle">
+  <td> <br> </td>
+  <td> <input type="submit" value=" Remove "> </td>
   </tr>

  </table>

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