Fwd: [ZPT] writing data to zope objects

Michael A Rowley os2mac at earthlink.net
Mon May 31 22:04:51 EDT 2004


Ok, this is driving me nuts!  I have fished through the source till I 
am almost cross eye'ed...  I can find no-where in the source calls 
where any reference to REQUEST is made to get the post data, or to any 
method to write the data to the objects... I have read the Formulator 
stuff, and am thinking it may be doing this automatically?  I have no 
idea how that is done....  But I think I can brute force this with 
something like

object.field=REQUEST[field_name] as long as all my field names are 
unique in my archetypes definitions...  I can write a validator to do 
this (I think).

I can't believe I am the first person to want to do this!  Someone with 
more experience at this than me must have visited this before.  I have 
literally been searching for a way to do this for months.  (To be fair, 
I have also been learning Python, archetypes, and zope also... It has 
been an uphill struggle.  I only started this in February...  that is 
why I really believe that there _must_ be a better way to do this...)

When looking through the code, this is the code path I get....

use-macro:"python:object.widget(object, fieldName, mode=mode)"

def widget(self, field_name, mode="view", **kwargs):
	widget=self.Schema()[field_name].widget
	return renderer.render(field_name, mode, widget, self, **kwargs)

class renderer:
	def render(self, field_name, mode, widget, instance=None, field=None, 
accessor=None, **kwargs):
         		if field is None:
             		field = instance.Schema()[field_name]

         		if accessor is None:
             		accessor = field.getAccessor(instance)

         		context = self.setupContext(field_name, mode, widget, 
instance, field, accessor, **kwargs)

         		result = widget(mode, instance, context)

         		del context
         		return result

	def setupContext(self, field_name, mode, widget, instance, field, 
accessor, **kwargs):
         		return {}

Now, I guess "result=widget(mode, instance, context) is calling the 
class widget in lib/python/generator/widget.py?  I still can't see 
where in this mess it is calling the edit macros, which I can find in 
Archetypes field/widget definitions...

What am I missing here?  Please help, for my sanity...

Michael.

Begin forwarded message:

> From: Michael A Rowley <os2mac at earthlink.net>
> Date: Mon May 31, 2004  2:21:44 PM US/Eastern
> To: Michael A Rowley <os2mac at earthlink.net>
> Subject: Re: [ZPT] writing data to zope objects
>
> Ok, more research, widget.postback, and widget.populate are simply 
> archetypes boolean variables.
>
> Now I am back at square one... How is the post information put into 
> the object?
>
> I am becoming unconvinced that an object database is better than a 
> relational db.  At least with a relational db I would know how to do 
> this :|
>
> M
>
> On Monday, May 31, 2004, at 01:12 PM, Michael A Rowley wrote:
>
>> hello all
>>
>> I am still battling this problem...  I have an application that 
>> records a lot of data from user input.  Much of this data is 
>> repetative, but stored independantly.  Specifically, vital signs on 
>> patients.  There are 5 vital signs... pulse, respirations, blood 
>> pressure (stored as systolic and diastolic)height and weight.  Now, 
>> generally all of these are collected everytime a patient comes in, 
>> but occasionally, they will have to be repeated on the same visit, 
>> for example, a repeat temperature, so they are all stored in separate 
>> objects.
>>
>> The problem I have is trying to collect the data on the same page.  
>> Having to select "Save" after each data point entry is not workable. 
>> It just takes to long.  It means having a minimum of 6 mouse clicks 
>> just to store the vital signs.  So, I am trying to write a page 
>> template that will allow the collection of all the data on one page, 
>> then update the individual objects on submission...
>>
>> I have figured out that the *_edit.cpt objects handle the data 
>> collection, and apparently the submission.  The resulting html page 
>> has the form being submitted back to the *_edit zpt... for example 
>> base_edit as an attribute of the object in question.  I think that 
>> the edit macros are using the widget.populate functions to populate 
>> the objects, but I can't find out how this function actually saves 
>> the data....
>>
>> The code looks like :
>>
>> tal:define =" visState....
>> 		   edit_accessor python:field.getEditAccessor(here);
>>                       value python:widget.populate and edit_accessor 
>> and edit_accessor() or '';
>> 		   value python:test(widget.postback and request.has_key(fileName), 
>> request.get(fieldName, value), value);
>> 		   error_id....
>>
>> Now, I am assuming the the postback function gets the data from html 
>> post function, and the populate function, writes the data to the 
>> object....  but I can't locate these two functions to see how the 
>> work, and I still haven't solved this problem....
>>
>> I think that I should be able to use these functions to write the 
>> data to the relative objects... I thought that the edit_macros would 
>> do this automatically, as they are passed the appropriate objects, 
>> they get the accessor data, so I thought that they would write the 
>> field data to the appropriate objects.  But, _nothing_ happens.  here 
>> is the code I am using...
>>
>> 	<table cellpadding="0" cellspacing="0" border="1" width="100%">
>> 	<tr tal:define = "global fileDict 
>> python:here.parentFolderObjsByType()">
>> 	<td>
>> 	    <span tal:repeat="object python:fileDict['Height']">
>> 	    <b metal:use-macro="python:object.widget(object, 'Height', 
>> mode='edit')">content</b><br/>
>> 	    </span>
>> 	</td>
>>         </tr>
>>         </table>
>>
>> This gives me the relevant object data on the page in edit mode, but 
>> when I save it, it is not saved.... parentFoldersObjsByType is an 
>> external method that I wrote, here it is....
>>
>> def parentFolderObjsByType(self):
>>
>>    """
>>    Creates a dicionary of lists of objects in the parent folder by 
>> meta_type.  This should be the name
>>    of the object as it appears in the 'allowed_content_types' in the 
>> archetypes definition, or the registerType name.
>>
>>    Returns the dictionary of lists.
>>    """
>>    filelist = self.getFolderContents()
>>    fileDict = {}
>>    for object in filelist:
>>
>>       typeName = (object.meta_type)
>>
>>       fileDict.setdefault(typeName,[]).append(object)
>>
>>    return fileDict
>>
>>
>>
>> Can anyone help me with this?  Or give me a direction?
>>
>>
>> any help would be appreciated.
>>
>> Michael




More information about the ZPT mailing list