[Zope] Dynamically generating fielsd in a form

D2 borelan@wanadoo.fr
Tue, 21 Jan 2003 02:31:33 -0400


   Dieter Maurer wrote...
 > I do not yet feel confident...

	So do i ,-) ; my explanation was not clear. Sorry

	Concerning the TREE. You saw it as a tree because
	i described it as a tree. But it's not a tree.

	Despite my bad explanation, you pointed out some points
	i had to verify. I hope my brain has been cleaned enough to let
	me reformulate (hoping that i don't bother you) and verify my
	understanding of some concepts.

	ZPT is dynamic in that it dynamically generates HTML. HTML is
	not dynamic by itself so if i want to have a dynamic HTML page,
	i must use CSS or Javascript.
	With ZPT i can insert/call Javascripts or references to
	Javascripts in my generated HTML so the HTML will behave
	dynamically by itself.

	Form/Action/Response Process (I'm using Plone.)
	1) CALL a method on an Object
	   LOCATE the object by the action associated to the object
	   in portal_actions, or, by using restrictedTraverse to
	   generate a selection form, wich will display a list of
	   objects on wich the method may be called, and wich
	   action will generate an URL of the form :
	   http://.../Located_Object/Method_to_Apply.

	2) SUBMIT the form to an ACTION wich will validate the form and
	    return a status managed by plone's form_properties and
	    navigation_properties.

	My need
	I have to create a document wich must contain n lines
	 - the number is not important - of different TYPES.
	There may be unique or multiple lines of a certain
	type in the document. The repetition is defined in a
	'model'. Lines of the same type are grouped and the TYPE
	order is defined in the 'model'

	The model will contain a 'linestack' property wich will
	be an ordered tuple of dictionaries.
	Each dictionary will contain the following keys:
		LINE_TYPE
		OCCURENCE
		other keys to populate the generated line
	The model will contain an empty 'lines' property wich
	will be used in the generated object and wich will
	contain the generated lines completed by the user.
	=09
	i.e the model 'invoice' will contain a linestack with
		({LINE_TYPE:CUSTOMER_ID, OCCURENCE:UNIQUE},
		 {LINE_TYPE:PRODUCTS, OCCURENCE:MULTIPLE},
		 {LINE_TYPE:TAXES, OCCURENCE:MULTIPLE})
	and so on.

	My solution
	Select the model to use via a form
	the action form will clone the model and will
	redirect to an URL calling a method on the cloned
	object.
	The method will loop over the 'linestack', populate the
	fields of the line, generate fields for user input,
	display only a 'NextStep' button on UNIQUE lines
	and a 'NextLine' and a 'NextStep' buttons on MULTIPLE
	lines.
	The action will append the new generated line to the
	'lines' property.
	On 'NextLine' the action will re-call the method on the
	object.
	On 'NextStep', the action will suppress the first
	dictionary of 'linestack' and will re-call the method
	on the object until 'linestack' will be empty.
	Then the process will be completed.

Andre

Dieter Maurer a =E9crit:
  > D2 wrote at 2003-1-16 15:39 -0400:
  >  > First case : I know the URL of the place to store (ObjectManager ?=
)
  >  > then the URL will be http://...../ObjectManager/FormTemplate
  >  > And inside my form i will use 'context' wich will be the
ObjectManager.
  > I do not expect that you let your form store the object
  > but the corresponding form action.


	That's right and the action will be a Python script

  >
  > But otherwise, this is okay.
  >
  >  > Second case : I don't know the URL of the ObjectManager.
  > This is impossible.


  > When you want to store the object somewhere, you must know where...
  >
  >  > So whatever the
  >  > way it is found, it must be in the REQUEST object.
  > "restrictedTraverse" may help you to locate the object
  > (--> embedded Zope Help System --> Zope Help --> API Reference
  > --> ObjectManagerItem).
  >
  >  > I pass the REQUEST to a Python script and then this script will
generate
  >  > a RESPONSE, redirected to the same URL as mentionned in the first
case.
  > The same seems a bit strange.
  >
  >  > My form will be generalized and populated by the URL or the REQUES=
T.
  > I still think, its the action and not the form....
  >
  >  > Does it make sense ?
  > I do not yet feel confident...
  >
  >
  > Dieter
  >
  > _______________________________________________
  > Zope maillist  -  Zope@zope.org
  > http://lists.zope.org/mailman/listinfo/zope
  > **   No cross posts or HTML encoding!  **
  > (Related lists -
  >  http://lists.zope.org/mailman/listinfo/zope-announce
  >  http://lists.zope.org/mailman/listinfo/zope-dev )
  >


--=20
Andre
PZP Enthusiast