Having created the simple website application, it may be advantageous to re-create the application for other companies. We can copy and paste the Home folder, but then we would have to manually edit properties and upload a new image each time we made a copy. A simpler method is to automate this process by creating a configuration interface. A minimal configuration interface consists of a document that displays a form to collect configuration information and a document that uses DTML scripting to copy the folder and apply the new configuration.
Thus, the original application object serves as a template for creating new applications. While scripts could be written to build an object from scratch, it is often easier to start with an existing object, which is used as a template. The use of properties in the original application make the customizing task easier.
To create a configuration interface for our simple website application, we first need to create a DTML Method that displays a form prompting for information about the company. These DTML Method should be created at the root level. Figure 23 shows the source for a DTML Method, Designer, that displays the form in Figure 24. The form collects the configuration information that will be applied to the copied version of the Home folder6.
The action of the Designer form is another DTML Method, Builder, that uses DTML scripting to copy the original home page folder and apply the customization. As shown in Figure 25, the source for Builder sets the properties of the Home folder to the properties defined by Designer.
Let's go through the Builder script step by step. After the insertion of the standard header, there is a with tag that evaluates an expression involving manage_clone. The Folder method manage_clone allows an object to be copied into a folder with a given id. In the expression in Figure 25, the manage_clone method is being invoked on the Folder in which the builder is run. The object being cloned is the template object, Home. Make sure you have created the folder Home under the root folder. You will need to copy the home page (index_html) you developed in the previous exercise.
The new id is given by the expression REQUEST['id']. This expression is used to make sure that the id collected by the Designer form is used, rather than the id of the folder. The manage_clone method returns the object clone, which allows the object to be manipulated within the with tag.
Inside the with tag, the manage_changeProperties method is called on the newly cloned object to replace original property values with values from the request. The manage_upload method of the logo of the cloned object is called to supply a new logo image from the image provided in the Designer form. This completes the configuration of the new home page.
After the with tag, the redirect method is called on the RESPONSE object to redirect the browser to the Contents view of the destination folder. A query string, "?update_menu=1" is provided to cause the navigation pane to be updated too.
Finally, a message is output indicating success. Note that the text of the success message, as well as the text output by the standard header and footer is not output unless, for some reason, the browser ignores the redirection or shows the output followed by the redirection.
To use the simple website application as a template, the original Home folder along with the configuration objects must be accessible by other folders, such as through acquisition. By turning the website application into a Zope product, however, we avoid filling up top-level folders, while at the same time making the website application accessible to all folders. Then, if we could add the product to the Add List, a new website could be added to almost any folder.
Previous Chapter | Next Chapter | Up | Next Section | Contents