Hi,
I have to classes like so:
CaCert(CertItem):
SignedCerts = MultipleJoin('Cert')
...
Cert(CertItem):
CA = ForeignKey('CaCert')
Type = StringCol()
...
def _set_Type(self, value):
_valid = ['email', 'client', 'object', 'server']
if value not in _valid:
raise ValueError('Type must be one of %s' % _valid)
elif CA.Type not in ['ca_'+value, 'ca_root']:
raise ValueError('CA must support cert type %s.' % type)
self._SO_set_Type(value)
...
But instance creation fails:
server_params = {...
sampleRoot = CaCert.new(**server_params)
client_params = {'Type':'email', 'CN':'foo@bar', 'OU':'B17 Corporation',
'DaysValid':365, 'email':'foo@bar', 'CA':sampleRoot}
Cert.createTable(ifNotExists=True)
Cert.new(**client_params)
Traceback (most recent call last):
File "certs.py", line 212, in ?
testcert = Cert.new(**client_params)
File "certs.py", line 134, in new
obj = super(CertItem, cls).new(**kw)
File "/usr/lib/python2.2/site-packages/SQLObject/SQLObject.py", line 904, in new
setattr(inst, name, value)
File "certs.py", line 148, in _set_Type
elif CA.Type not in ['ca_'+value, 'ca_root']:
NameError: global name 'CA' is not defined
I can access the CaCert instance in new(cls, **kw) through kw['CA'] so I could
do those checks in new but what if one do not need to override new? Is there
another way to access attributes of CA? Generally, is it possible to do checks
in the setter methods which depend on other Columns values?
thanks
Paul
|