[Zope-CMF] 'portal_metadata' tool in CVS
Tres Seaver
tseaver@digicool.com
Sun, 06 May 2001 09:05:22 -0400
marc lindahl wrote:
> This tool is the BOMB!
Thanks!
> A key TO-DO is hooking it into the UI (obviously, it's brand new). I think
> that the 'subject' field is a prime candidate for organizing the content on
> a site, but to work right, the list of subjects has to be enforced. To see
> how well this might work, I modified metadata_edit_form.dtml (in generic
> skin) to multiple-select the subject from a list defined with the
> portal_metadata tool. I'll put the code at the end of the message - to try
> it:
> 1. just 'cusomize' metadata_edit_form (from basic/content skin) into, say,
> custom, and paste this code in.
> 2. add a portal_metadata tool to your portal if you don't already have one.
> 3. in the portal metadata tool, under the 'elements' tab, pick 'subject' and
> put some stuff into the 'vocabulary' list. E.G.: member, homepage, photo,
> essay, diatribe, former cia. Now update. Notice how you can make different
> lists for different content types. Way cool!
> 4. pick 'metadata' from the actions box, for some document or file, and you
> should see this list presented, instead of the usual blank box.
>
> The cool thing about this is, then I can use PortalTopics to give me
> meaningful directories in my site.
That was the plan.
> One thing occured to me. That is, it might be nice to have a different (or
> concatenated) vocabulary based on ROLE. In other words, in the above
> example, to allow only Managers the choice of 'former cia' and 'diatribe'.
We'd have to write software for that (e.g., extend or replace the
CMFDefault.MetadataToolMetadataTool class).
> This DTML is just an illustration, it should at least have stuff to handle
> the case of no portal_metadata tool around or an empty list.
>
> I put this file on
> http://cmf.zope.org/Members/bowerymarc/metadata_edit_form.dtml/view
> once it goes public you can download it from there. Until then, here's a
> page of DTML:
>
> <dtml-var standard_html_header>
>
> <div class="Desktop">
>
> <dtml-if message>
> <p>&dtml-message;</p>
> <hr>
> </dtml-if>
>
> <div class="Metadata">
>
> <h2>Standard Resource Metadata </h2>
>
> <form action="metadata_edit" method="post">
> <table class="FormLayout">
> <tr valign="top">
> <th align="right"> Identifier
> </th>
> <td>
> <dtml-var Identifier>
> </td>
> <td colspan="2" align="right">
> <a href="full_metadata_edit_form"> Edit all metadata </a>
> </td>
> </tr>
> <tr valign="top">
> <th align="right"> Title
> </th>
> <td colspan="3">
> <input type="text"
> name="title"
> value="&dtml-Title;"
> size="65">
> </td>
> </tr>
> <tr valign="top">
> <th align="right"> Description
> </th>
> <td colspan="3">
> <textarea name="description:text" rows="5"
> cols="65">&dtml-Description;</textarea>
> </td>
> </tr>
> <tr valign="top">
> <th align="right"> Subject <br> <font
> size="-1"><br>(multiple<br>selection)</font>
> </th>
> <dtml-comment> Support portal_metadata limiting of subjects
> </dtml-comment>
> <td>
> <select name="subject:list" multiple size="<dtml-var
> "_.len(portal_metadata.listAllowedSubjects())">">
> <dtml-in "portal_metadata.listAllowedSubjects()">
> <option <dtml-if "Subject() and (_['sequence-item'] in
> Subject())">
> SELECTED</dtml-if>>
> <dtml-var sequence-item>
> </option>
> </dtml-in>
> </select>
> <dtml-comment>
> <textarea name="subject:lines" rows="5"
> cols="30"><dtml-in Subject><dtml-var sequence-item>
> </dtml-in></textarea>
> </dtml-comment>
> </td>
> <th align="right"> Format
> </th>
> <td> <input type="text" name="format" value="&dtml-Format;">
> <br> <input type="submit" name="change_and_edit" value=" Change & Edit ">
> <br> <input type="submit" name="change_and_view" value=" Change & View ">
> </td>
> </tr>
> </table>
> </form>
>
> </div>
>
> </div>
>
> <dtml-var standard_html_footer>
I've patched it to accomplish a couple of goals:
- Pass the content object to the tool, so that types which have
customized vocabularies get them.
- Bound the size of the selection element.
- Use the 'let' tag to remove nesting of "elements" (this is purely
personal taste).
We probably still need to deal with the case that the tool *has*
a Subject vocabulary for the object, but doesn't enforce it; fixing
the DTML probably requires adding more methods to the tool's interface.
Here is the patch:
--------------------------------------------------------------
$ diff -u lindahl.dtml.org lindahl.dtml
--- lindahl.dtml.org Sun May 6 08:33:22 2001
+++ lindahl.dtml Sun May 6 09:02:46 2001
@@ -48,21 +48,25 @@
<dtml-comment> Support portal_metadata limiting of subjects
</dtml-comment>
<td>
- <select name="subject:list" multiple size="<dtml-var
- "_.len(portal_metadata.listAllowedSubjects())">">
- <dtml-in "portal_metadata.listAllowedSubjects()">
- <option <dtml-if "Subject() and (_['sequence-item'] in
-Subject())">
- SELECTED</dtml-if>>
- <dtml-var sequence-item>
+ <dtml-let allowed="portal_metadata.listAllowedSubjects( this() )"
+ raw_size="_.len( allowed )"
+ min_size="raw_size < 5 and 5 or raw_size"
+ max_size="min_size > 10 and 10 or min_size"
+ size=max_size
+ subject=Subject
+ >
+ <select name="subject:list" multiple size="&dtml-size;">
+ <dtml-in allowed>
+ <dtml-let item=sequence-item
+ sel="item in subject and 'selected' or ''"
+ >
+ <option value=&dtml-sequence-item; &dtml-sel;>
+ &dtml-item;
</option>
+ </dtml-let>
</dtml-in>
- </select>
-<dtml-comment>
- <textarea name="subject:lines" rows="5"
- cols="30"><dtml-in Subject><dtml-var sequence-item>
- </dtml-in></textarea>
-</dtml-comment>
+ </select>
+ </dtml-let>
</td>
<th align="right"> Format
</th>
--------------------------------------------------------------
Thanks for pitching in!
Tres.
--
===============================================================
Tres Seaver tseaver@digicool.com
Digital Creations "Zope Dealers" http://www.zope.org