X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fdbconn.py;h=020040c98294e4703950adc3aee45e461e8b2f0e;hb=96b4cae49dd5d752de6767a25fb2b3a2b3b4deb1;hp=d81e1ed52177999962333546ba90b342ab0ae546;hpb=7e90e4a630cdbd84b99fe6cf77453fe5f11d03db;p=dak.git diff --git a/daklib/dbconn.py b/daklib/dbconn.py index d81e1ed5..020040c9 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -262,10 +262,31 @@ class ORMObject(object): validation fails. ''' for property in self.not_null_constraints(): + # TODO: It is a bit awkward that the mapper configuration allow + # directly setting the numeric _id columns. We should get rid of it + # in the long run. + if hasattr(self, property + '_id') and \ + getattr(self, property + '_id') is not None: + continue if not hasattr(self, property) or getattr(self, property) is None: raise DBUpdateError(self.validation_message % \ (property, str(self))) + @classmethod + @session_wrapper + def get(cls, primary_key, session = None): + ''' + This is a support function that allows getting an object by its primary + key. + + Architecture.get(3[, session]) + + instead of the more verbose + + session.query(Architecture).get(3) + ''' + return session.query(cls).get(primary_key) + __all__.append('ORMObject') ################################################################################ @@ -2239,7 +2260,8 @@ class DBSource(ORMObject): 'install_date'] def not_null_constraints(self): - return ['source', 'version', 'install_date'] + return ['source', 'version', 'install_date', 'maintainer', \ + 'changedby', 'poolfile', 'install_date'] __all__.append('DBSource') @@ -2780,7 +2802,7 @@ __all__.append('get_suite_src_formats') ################################################################################ -class Uid(object): +class Uid(ORMObject): def __init__(self, uid = None, name = None): self.uid = uid self.name = name @@ -2797,8 +2819,11 @@ class Uid(object): # This signals to use the normal comparison operator return NotImplemented - def __repr__(self): - return '' % (self.uid, self.name) + def properties(self): + return ['uid', 'name', 'fingerprint'] + + def not_null_constraints(self): + return ['uid'] __all__.append('Uid') @@ -3239,7 +3264,8 @@ class DBConn(object): mapper(Uid, self.tbl_uid, properties = dict(uid_id = self.tbl_uid.c.id, - fingerprint = relation(Fingerprint))) + fingerprint = relation(Fingerprint)), + extension = validator) mapper(UploadBlock, self.tbl_upload_blocks, properties = dict(upload_block_id = self.tbl_upload_blocks.c.id,