Up | Next Section | Contents

Factories


Factories provide the connection between objects in a product and the Zope Folder Add List. An entry appears in the Add List for each factory defined in a product. A product may have any number of factory objects. The factory's method, typically a DTML Method, is invoked when the factory's entry is selected from the Add List.

Creating a factory for our InstantSite product would enable our product to be duplicated simply by selecting the factory from the Add List. Before creating the factory for our product, we need to copy the Home folder and the configuration DTML Methods, Designer and Builder, into the InstantSite product using the Zope copy and paste mechanisms. After copying and renaming these objects, the product appears as in Figure 29 .

To create a factory, simply select the "Factory" entry in the Add List and click the "Add" button. The "Create an object factory" form is presented, as shown in Figure 30 .. The "Add List Name" is the name of the factory to appear in the Add List. In our example, we entered Instant Web Site as the "Add List Name" and selected "Designer" as the method to be invoked when the factory is added. Thus, when "Instant Web Site" is selected from the Add List, the Designer DTML Method prompting for the configuration information is rendered.

InstantSite product with template and configuration objects

 

Add factory form

 

There is one problem with the product. When a new website is created, the destination folder's Contents view is not displayed as one might expect. Instead, a rather odd view of the factory management is shown (Figure 31 ). Note the odd URL shown in the management view.

Output after a new website is added to the Plutonia Folder using the original Builder script.

 

Placing the template object and configuration DTML Methods in a product folder made it unnecessary for the objects to be in the destination folder. When an object is added, however, these objects must be somehow accessed. When a new website is added to a destination folder, the Designer script is accessed by the effective address:

manage_addProduct/product_name/factory_name/object_name

Once the Designer script calls the Builder, the Builder script redirects the browser to the manage_main view of the address above. Thus, the odd view is displayed. To redirect the browser to the contents view of the destination folder, the Builder's redirect method needs to be modified using function DestinationURL. This modification can be seen in Figure 32 .

Source of the modified Builder DTML Method

<!--#var standard_html_header-->

 

<!--#with "manage_clone(Home,REQUEST['id'],REQUEST)"-->

<!--#call "manage_changeProperties(

title=REQUEST['new_name'],

company_name=REQUEST['new_name'],

message=REQUEST['new_message'],

contact_phone=REQUEST['new_phone'],

)"-->

<!--#call "logo.manage_upload(REQUEST['new_logo'])"-->

<!--#/with-->

 

<!--#call "RESPONSE.redirect(DestinationURL()+'manage_main?update_menu=1')"-->

 

Congratulations!

 

<!--#var standard_html_footer-->

 

Up | Next Section | Contents