LJ Archive

Listing 2. smallhello/smallhello.py

import OFS.SimpleItem          # Basic acquisition
from Globals import HTMLFile   # Lets us bring in an
                               # HTML file

class smallhello(OFS.SimpleItem.SimpleItem):
   """This is the class that defines our smallhello
   product.  We have a method for initialization
   (__init__), another that displays a brief HTML
   message by default, and a third that displays
   output from a DTML file."""

   meta_type = 'smallhello'

   def __init__(self, id, title):
       "initialize a new instance of Smallhello"
       self.id = id
       self.title = title

   def index_html(self):
       "Show us some basic content!"
       return """
       <html>
       <head><title>Hello, world!</title></head>
       <body>
       <h1>Hello, world!</h1>
       <p>Welcome to my 'smallhello' Zope product</p>
       </body>
       </html>"""

   def other_html(self):
       "More basic content"
       return """
       <html>
       <head><title>More content!</title></head>
       <body>
       <h1>More content!</h1>
       <p>You can define lots of methods if
          you want...</p>
       </body>
       </html>"""

   def foo_file(self):
       "Demonstrate returning content from a file"
       return HTMLFile('foo', globals())

def manage_smallhello(self, RESPONSE):
   "Add a Smallhello to a folder."
   self._setObject('smallhello_id',
   smallhello('smallhello_id', 'smallhello_title'))
   RESPONSE.redirect('index_html')
LJ Archive