Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

root/trunk/zoo.py

Revision 51 (checked in by fumanchu, 8 years ago)

1. Changed arena.roster to ._registered_classes. Dropped containers.Prism and .Index
2. First attempt at arena.migrate (migrate class data from one store to another).
3. Fixed weakref bug in db pooling.
4. db.SM.reserve() now writes all data, not just ID.
5. Various store bugs (adapters, mostly).

Line 
1 import datetime
2 try:
3     import fixedpoint
4 except ImportError:
5     fixedpoint = None
6
7 try:
8     import decimal
9 except ImportError:
10     decimal = None
11
12 import dejavu
13 from dejavu import Unit, UnitProperty, associate
14
15
16 class Zoo(Unit):
17     Name = UnitProperty()
18     Founded = UnitProperty(datetime.date)
19     Opens = UnitProperty(datetime.time)
20     LastEscape = UnitProperty(datetime.datetime)
21    
22     if fixedpoint:
23         Admission = UnitProperty(fixedpoint.FixedPoint)
24     else:
25         Admission = UnitProperty(float)
26
27
28 class EscapeProperty(UnitProperty):
29     def post(self, unit, value):
30         z = unit.first(Zoo)
31         if z:
32             z.LastEscape = unit.LastEscape
33
34 class Animal(Unit):
35     Name = UnitProperty()
36     ZooID = UnitProperty(int, index=True)
37     Legs = UnitProperty(int)
38     PreviousZoos = UnitProperty(list)
39     LastEscape = EscapeProperty(datetime.datetime)
40     Lifespan = UnitProperty(float, hints={'bytes': 4})
41
42 associate(Zoo, 'ID', Animal, 'ZooID')
43
44
45 class Exhibit(Unit):
46     # Make this a string to help test vs unicode.
47     Name = UnitProperty(str)
48     ZooID = UnitProperty(int)
49     Animals = UnitProperty(list)
50     PettingAllowed = UnitProperty(bool)
51     if decimal:
52         Acreage = UnitProperty(decimal.Decimal)
53     else:
54         Acreage = UnitProperty(float)
55
56 associate(Zoo, 'ID', Exhibit, 'ZooID')
57
58 arena = dejavu.Arena()
59 arena.register_all(globals())
Note: See TracBrowser for help on using the browser.