import datetime try: import fixedpoint except ImportError: fixedpoint = None try: import decimal except ImportError: decimal = None import dejavu from dejavu import Unit, UnitProperty, associate class Zoo(Unit): Name = UnitProperty() Founded = UnitProperty(datetime.date) Opens = UnitProperty(datetime.time) LastEscape = UnitProperty(datetime.datetime) if fixedpoint: Admission = UnitProperty(fixedpoint.FixedPoint) else: Admission = UnitProperty(float) class EscapeProperty(UnitProperty): def post(self, unit, value): z = unit.first(Zoo) if z: z.LastEscape = unit.LastEscape class Animal(Unit): Name = UnitProperty() ZooID = UnitProperty(int, index=True) Legs = UnitProperty(int) PreviousZoos = UnitProperty(list) LastEscape = EscapeProperty(datetime.datetime) Lifespan = UnitProperty(float, hints={'bytes': 4}) associate(Zoo, 'ID', Animal, 'ZooID') class Exhibit(Unit): # Make this a string to help test vs unicode. Name = UnitProperty(str) ZooID = UnitProperty(int) Animals = UnitProperty(list) PettingAllowed = UnitProperty(bool) if decimal: Acreage = UnitProperty(decimal.Decimal) else: Acreage = UnitProperty(float) associate(Zoo, 'ID', Exhibit, 'ZooID') arena = dejavu.Arena() arena.register_all(globals())