The arrangement of Zope objects required for a large website can get somewhat messy and end up looking disorganized. Fortunately, you can use the plethora of Zope Products available to give you a hand, or you can create your own, if there are none that perfectly suit your needs. This article shows you how easy it is to create a Zope Product.
The first thing we'll need to do is create an __init__ method. The purpose of this is to accept attributes when an instance of our Product is created. In this example, we'll accept the attributes id, title and nickname:
...
def __init__(self, id, title, nickname): "Initialization." self.id = id self.title = title self.nickname = nickname
We can now add actual content to our Product. The methods that we create will be available as separate pages in our Product. These pages can be accessed by attaching the associated method's name to the id of the Product instance in a request (for example, http://localhost/instance/methodOne). We'll start with index_html, the default page that's called when nothing is specifically requested:
...
def index_html(self): "Default page." out = '<html><head><title>' + self.title + '</title></head><body>' out = out + 'Hello, I am ' + self.title + ', but my friends call me ' + self.nickname + '.' out = out + '</body></html>' return out
In the above method, we return a page that displays the instance's title and the value of the nickname attribute we accepted in the __init__ method earlier. Let's add one more method that lists data about an instance:
...
def list_info(self): "A list of information." out = '<html><head><title>' + self.title + '</title></head><body>' out = out + '<b>ID:</b> ' + self.id out = out + '<br /><b>Name:</b> ' + self.title out = out + '<br /><b>Nickname:</b> ' + self.nickname out = out + '</body></html>' return out