Bobo and Principia (Web Techniques, Feb 1999)



January 01, 2002
URL:http://www.drdobbs.com/bobo-and-principia-web-techniques-feb-19/184414028

import DietCenter
DietCenter.clients.amos.eat (food='spam', servings=3)
Web Techniques: Figure 1

Figure 1


Interaction of the major components of the platform. The publisher manages the server processes and passes requests between the Web server and the ORB. The ORB decodes the request, finds the recipient object in the published module, and calls it. The ORB passes the response back up to the publisher, which passes it back to the Web server. The recipient object relies on the object database to manage state and uses templates to generate HTML.

Figure 1


# Acquisition of a phone number

import Acquisition

# define empty classes that use acquisition
class Location(Acquisition.Implicit): pass
class Individual(Acquisition.Implicit): pass

# create home, work and me objects
home=Location()
home.phone="555-1212"
work=Location()
work.phone="123-4567"
me=Individual()

# locate me at home
home.resident=me
print home.resident.phone  # prints "555-1212"

# locate me at work
work.worker=me
print work.worker.phone  # prints "123-4567"


<html>
<p>Food: SPAM</p>
<p>Calories: 250</p>
<p><blink>Warning: Do NOt Eat! </blink></p>
</html>
Web Techniques: Figure 2

Figure 2


The ORB traverses the objects in the DietCenter module to locate the recipient object. The ORB examines the recipient object and passes it a message with arguments culled from the environment. In our example, the ORB calls the amos object's eat method with the arguments food="spam" and servings=3.

Figure 2


# Basic persistence and object database use

import BoboPOS

class Customer(BoboPOS.Persistent):
    "A persistent class"

    def __init__(self,name):
        self.name=name

    def set_favorite(self,food):
        self.favorite_food=food

# open the object store
db=BoboPOS.PickleDictionary("customers.bbb")

# if amos is not already in the object store
if not db.has_key("amos"):

    # create a Customer instance in the object store
    db["amos"]=Customer("Amos")

    # change an attribute of the persistent object
    db["amos"].set_favorite("spam")

    # commit the change
    get_transaction().commit()

# prints "Amos' favorite food is spam"	
print "Amos' favorite food is", db["amos"].favorite_food


Web Techniques: Figure 3

Figure 3


The platform's management GUI. The left frame displays a collapsible outline of folders. The right frame lets you manage the currently selected object. The tabs along the top of the right frame show the available management functions.

Figure 3


# Templates are used to display an object in HTML

import DocumentTemplate

class Food:
    "Something edible"
    def __init__(self,name,calories):
        self.name=name
        self.calories=calories
	
    def is_fattening(self):
        if self.calories > 100:
            return 1

    index_html=DocumentTemplate.HTML("""\
<html>
<p>Food: <!--#var name--></p>
<p>Calories: <!--#var calories--></p>
<!--#if is_fattening-->
<p><blink>Warning: Do Not Eat!</blink></p>
<!--#/if-->
</html>""")

# create a Food object, spam
spam=Food("SPAM",250)

# display it with its template
print spam.index_html(spam)
Web Techniques: Figure 4

Figure 4


Templates can be edited through the Web. The bulk of this template was created automatically by Tabula using its report-generation abilities. You can edit the report template to exert finer control over its display.

Figure 4


Web Techniques: Figure 5

Figure 5


The completed news page with a listing of the most recent news items.

Figure 5


Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.