[Zope] how to search (or act) in subobjects?

andreas.kahnert@de.abb.com andreas.kahnert@de.abb.com
Tue, 18 Sep 2001 14:59:20 +0200


Hi Folks,

I am struggeling with the following problem. I want people to create there
own contributions to a thing what we named knowledgebase. If somebody wants
to share his knowledge he press the "Add new Contribution"  link. Then he
will be asked to fill out a form. He can enter keywords, headlines, texts,
images and files as attachments. A DTML Methode creates a new folder with a
unique Id. Within this folder I want to store all text elements in a DTML
Document, the images and the attachments.

Here is the code I wrote (a form delivers all the desired variables):

<dtml-var standard_html_header>

<dtml-call "REQUEST.set('ts', ZopeTime())">
<dtml-call "REQUEST.set('autoId', _.str(_.int(ts)))">
<dtml-call expr="manage_addFolder(autoId, title=firstHeadline )">

<dtml-let content="' '" newfolder="_.getitem(autoId)" doc="'document'">
   <dtml-call "newfolder.manage_addDTMLDocument(doc, title=firstHeadline
)">
   <dtml-let document="newfolder.getitem(doc)">
      <dtml-call expr="document.manage_addProperty
('author',AUTHENTICATED_USER.getUserName(),'string')">
      <dtml-call expr="document.manage_addProperty('creationDate',ts,
'string')">
      <dtml-call expr="document.manage_addProperty('visible','1',
'boolean')">
      <dtml-call expr="document.manage_addProperty
('validUntil',validUntil,'string')">
      <dtml-call expr="document.manage_addProperty
('knowledgeCategory',knowledgeCategory,'string')">
      <dtml-call expr="document.manage_addProperty
('keywords',keywords,'string')">
      <dtml-call expr="document.manage_addProperty
('accessRights',accessRights,'string')">
   </dtml-let>
   <dtml-if imageOne>
      <dtml-call "newfolder.manage_addImage(id='image_1', file=imageOne)">
   </dtml-if>
   <dtml-if imageTwo>
      <dtml-call "newfolder.manage_addImage(id='image_2', file=imageTwo)">
   </dtml-if>
   <dtml-if imageThree>
      <dtml-call "newfolder.manage_addImage(id='image_3',
file=imageThree)">
   </dtml-if>
</dtml-let>


<h1>Your contribution with the title
<dtml-var "bindContent(autoId, AUTHENTICATED_USER.getUserName(), ts,
firstHeadline, firstParagraph, imageOne, secondHeadline, secondParagraph,
imageTwo, thirdHeadline, thirdParagraph, imageThree)">
was added to the system!</h1>
<p><a href="<dtml-var URL1>">Return</a> to the folder listing.</p>

<dtml-var standard_html_footer>

*********************

The problem is that it creates the folder, creates the DTML Document
'document' and the images 1-3 but it does not adds any properties to the
DTML Document "doc" because of an error called

Zope has encountered an error while publishing this resource.
Error Type: AttributeError
Error Value: getitem

What have I done wrong?


Then I tried to write that as a script, but I don't know to access the doc
from the context:
"""
addDocument         Python Script        Parameter: newfolder
"""
for object in context.newfolder.objectValues('DTML Document'):
   if object.getId == 'document':
      doc=getattr(newfolder, 'document')
      doc.manage_addProperty('author',AUTHENTICATED_USER.getUserName
(),'string')
      doc.manage_addProperty('creationDate',ts,'string')
      doc.manage_addProperty('validUntil',validUntil,'string')
      doc.manage_addProperty('visible','1','boolean')
      doc.manage_addProperty
('knowledgeCategory',knowledgeCategory,'string')
      doc.manage_addProperty('keywords',keywords,'string')
      doc.manage_addProperty('accessRights',accessRights,'string')

******
or
*****

for object in context.objectValues('Folder'):
   folder = object.getId()
   if folder == newfolder:
      for docObject in context.folder.objectValues('DTML Document'):
         if docObject.getId() == 'document':
            doc=getattr(newfolder, 'document')
            doc.manage_addProperty('author',AUTHENTICATED_USER.getUserName
(),'string')
            doc.manage_addProperty('creationDate',ts,'string')
            doc.manage_addProperty('validUntil',validUntil,'string')
            doc.manage_addProperty('visible','1','boolean')
            doc.manage_addProperty
('knowledgeCategory',knowledgeCategory,'string')
            doc.manage_addProperty('keywords',keywords,'string')
            doc.manage_addProperty('accessRights',accessRights,'string')
            print 'I added the properties!'
return printed

Regards and thank you very much
Andreas