BYTE.com > Tangled in the Threads > 2001 > June
Examples Of Acquisition
By Jon Udell
June 14, 2001
(Nature vs. Nurture
: Page 2 of 3 )
Some simple examples of acquisition can been seen in an application I wrote to help a team of editors collaborate on the production of a magazine. The application uses ZODB (Zope's object database) to store a tree of contents that looks like this:
2001-08
article_1
draft_1
draft_2
image_A
image_B
article_2
2001-07
article_1
article_2
The bolded items are Folders. There's a Folder for each month's issue and, within that, a Folder for each article in the issue, containing one or more Files or Images. The user interface of the application is based on Zope's tree tag. Here's a simplified view of the DTML logic that expresses the containment hierarchy in HTML:
<dtml-tree branches_expr="objectValues(['Folder',
'File','Image'])" reverse sort=id>
<dtml-if "meta_type=='Folder'">
<dtml-if "isIssueFolder(_['title_or_id'])==0">
[<a href="<dtml-var tree-item-url>
/addFile">add file</a>]
[<a href="<dtml-var tree-item-url>
/addImage">add image</a>]
</dtml-if>
</dtml-if>
</dtml-tree>
The isIssueFolder() method is called once for each Folder in the containment hierarchy, and passed an argument that picks out the title_or_id property of the current object. The convention here is that when that property doesn't match the regular expression 20\d\d\-\d\d (which is the test implemented by isIssueFolder), the Folder represents an article. In these cases, the DTML logic decorates the emitted HTML node with links used to add files, or images, to that folder, like so:
2001-08
article_1 [add file] [add image]
draft_1
draft_2
image_A
image_B
article_2 [add file] [add image]
2001-07
article_1 [add file] [add image]
article_2 [add file] [add image]
The addresses of these links are formed by means of the expression <dtml-var tree-item-url>, which yields URLs like these:
2001-08/article_1/addFile
2001-07/article_2/addImage
addFile and addImage are DTML Documents that present HTML forms used to upload files or images.
BYTE.com > Tangled in the Threads > 2001 > June
|