[ZPT] ZPT retrieval of plone object data

michael rowley os2mac at earthlink.net
Mon Mar 22 14:49:23 EST 2004


Hello!

having difficulty retrieving data from an object with a python script. 

I am trying to pull data from an object and put it on another objects 
view, so that I can see both objects data at the same time..

to be complete:

zope setup

members
        EHR
            Encounter
                 Temp
                 BP
                 Pulse
                 Resp
                 Height
                 Weight
                 Exam

Now, exam allows the entry of data about an examination, typed text, and 
each of the other objects hold what you would think they would hold, 
with other data, like what position the person was in, id, and table.

Now, what I want to do is pull the data from the Temp, Pulse, ... 
objects, and display it on the Exam objext so it can be viewed without 
having to visit all the other objects...  Sounds easy enough!  Would be 
crazy easy with a relational db.....  but, it is giving me screaming 
fits with zope, plone, zpt.

I have a script that will get all of the objects in the Encoutner 
folder, and return their objectIds() :)  Then another script to go out 
and get the fields from the objects...  Now, from the current object, 
(exam) the following zpt works

      <div tal:repeat="field python: 
here.Schema().filterFields(isMetadata=0)">
            <h3 tal:content = "python:field.getName()">fieldname</h3>
        <span metal:use-macro="python: here.widget(field.getName(), 
mode='view')"/>
      </div>

and the following python script will get the object reference from the 
object ID passed to it ( in a dictionary, then pulled out by what field 
you want, and what object type you are looking for...)

"""
   recieves fieldname and dictionary of data, provably returned from 
getObjectIdsParent()
   accesses object and pulls out needed data

   returns field data
"""

1import Acquisition

2objectID = dictionary[fieldname]

3#  to do :wild goose check.  If there is no objectID corresponding to 
this typename, bail

4object = getattr(context,objectID)


5# try to get the object directly from the objectID

6for fields in (object.Schema().filterFields(isMetadata=0)):
   
7   if fieldname == fields.getName():
8        return fieldname + "apples and oranges baby!"
9        fieldData = (object.widget(fields.getName(), mode = 'view'))
10      return fieldData
  
11return "----"
_____________________________________________________________________________-

Now, line 6 works great, I can test this script and get the field ID 
back, the field name, but not the data from the field widget.  This was 
buildt with Archetypes, I don't know if that makes a difference...

Any help with this?

Michael.




More information about the ZPT mailing list