This table's name will be circles_table.
For attributes, see Section 4.1.3, “Attributes of the circles table”.
circles_table = schema.Table('circles', meta,
schema.Column('lat', types.CHAR(4)),
schema.Column('lon', types.CHAR(5)),
schema.Column('water', types.CHAR(1)),
schema.Column('odd', types.CHAR(1)),
schema.Column('cir_name', types.VARCHAR(80), nullable=False),
schema.PrimaryKeyConstraint('lat', 'lon'))
Instances of class Circle will represent
these rows in SQLAlchemy.
class Circle(object):
def __init__(self, lat, lon, water, odd, cir_name):
self.lat = lat
self.lon = lon
self.water = water
self.odd = odd
self.cir_name = cir_name
def __repr__(self):
return ( "<Circle(%sn %sw %s)>" %
(self.lat, self.lon, self.cir_name) )
def __cmp__(self, other):
return cmp(self.cir_name, other.cir_name)
The .fullName() function returns a string
representation with the region codes filled in. Note that the
region codes are available only through the .regions attribute that is added in Section 6.13, “Object-relational mapping”. Just the region part is available as
.allRegions(), and a Unicode rendering of the
full name, with degree and prime symbols, is available as
.unicode().
def allRegions(self):
return '-'.join ( [ reg.reg_code
for reg in self.regions ] )
def fullName(self):
return ( "%sn %sw %s: %s" %
(self.lat, self.lon, self.allRegions(),
self.cir_name) )
def unicode(self):
return ( u"%s%s%s%sN %s%s%s%sW %s: %s" %
(self.lat[:2], DEGREE, self.lat[2:], PRIME,
self.lon[:3], DEGREE, self.lon[3:], PRIME,
self.allRegions(), self.cir_name) )