mid-level architecture question -- populating forms
I am putting together a site with that accesses and updates a database. The essential structure is this: the web-user is presented with a form and provides enough information for the web application to find the desired information in the data base. This key information is passed to a External Method that accesses the data base and determine which of a number of forms are needed to manage the update. The External Method then has a number of choices vis-a-vis how to publish the form. Based on the key provided by the application and the data in the database, it can computed the name of a static form. It can then 1) construct a URL for the form with parameters to fill in the blanks, e.g., specialised_form_1?field1=somedata&field2=moredata and so forth. I'm not sure how one would invoke this as I suspect getitem() would be confused. 2) evaluate the data values and put them in the REQUEST object, then pass down the string 'specialized_form' to the page where the form is to appear, generate the form with a <dtml-var expr="getitem(form-name,1)"> and have the form look up the fill-in-the-blanks data in the REQUEST object. 3) generate the form on the fly (probably from a home-grown template) and fill in the data directly. 4) .... I'm leaning towards 2) but am still not really sure it's the best approach. Comments? -d PS: Zope 2.5, dtml-ish site not templates.
[Dennis Allison]
I am putting together a site with that accesses and updates a database. The essential structure is this:
the web-user is presented with a form and provides enough information for the web application to find the desired information in the data base. This key information is passed to a External Method that accesses the data base and determine which of a number of forms are needed to manage the update.
The External Method then has a number of choices vis-a-vis how to publish the form. Based on the key provided by the application and the data in the database, it can computed the name of a static form. It can then
1) construct a URL for the form with parameters to fill in the blanks, e.g., specialised_form_1?field1=somedata&field2=moredata and so forth. I'm not sure how one would invoke this as I suspect getitem() would be confused.
2) evaluate the data values and put them in the REQUEST object, then pass down the string 'specialized_form' to the page where the form is to appear, generate the form with a <dtml-var expr="getitem(form-name,1)"> and have the form look up the fill-in-the-blanks data in the REQUEST object.
3) generate the form on the fly (probably from a home-grown template) and fill in the data directly.
Use an external method to compute and a page template to compose the HTML. That's the best rule. So consider having your external method return a dictionary of name:value pairs for the form that the user will eventually see. Then create the HTML page using DTML based on the dictionary returned by the external method. Don't use the external method to create HTML - DTML is better for that. You shouldn't have to stuff them into the REQUEST object at all. Cheers, Tom P
Dennis Allison writes:
... dispatching from controling external method to template ... When the External Method and the template are in the same folder, then you can simply return the rendered template.
Zope templates accept keyword parameters. Thus, your External Method may end in something like: return chosen_template(self,self.REQUEST,arg1=val1,....) for a DTML template or return chosen_template(arg1=val1,...) for a Page Template. If External Method and the template are not in the same folder, relative links in your template may get wrong. Your options: * redirect to the template * use my "emulateRedirect" <http://www.dieter.handshake.de/pyprojects/zope> * set the base tag correctly Dieter
participants (3)
-
Dennis Allison -
Dieter Maurer -
Thomas B. Passin