def validateType(self, value): #print value for toTable in self._toTables: if isinstance(value, toTable._instanceClass): return raise DataVeto("%r is not a %s instance" % \ (value,toTable.getTableName()))
def commit(self, unlock=False): #if not self.isDirty(): # return #print "writeToStore()", self for a in self._dirtyRowAttrs.values(): a.trigger(self) if self._new: self._store.setAutoRowId(self) for rowattr in self._store.getTable()._mandatoryColumns: if self.getFieldValue(rowattr.name) is None: raise DataVeto( "Column '%s.%s' is mandatory"\ % (self._store.getTable().getTableName(), rowattr.name)) try: self.validate() except DataVeto, e: raise DataVeto(repr(self) + ': ' + str(e))
def _readFromStore(self): """ make this row complete using a single database lookup """ assert not self._pseudo,\ "%s : readFromStore() called for a pseudo row" \ % repr(self) assert not self._complete,\ "%s : readFromStore() called a second time" % repr(self) assert not self._isCompleting #assert not self._new # but what if atoms2row() causes __getattr__ to be called # again? maybe a switch _isCompleting to check this. self.__dict__["_isCompleting"] = True # print "makeComplete() : %s" % repr(self) id = self.getRowId() if self._new: ## atomicRow = self._query._store.executePeek( ## self._query._store._peekQuery,id) ## if atomicRow is not None: ## raise DataVeto("Cannot create another %s row %s" \ ## % (self.__class__.__name__, id)) for attrname in self._store.getTable().getAttrList(): self._values.setdefault(attrname, None) else: atomicRow = self._store.executePeek(self._store._peekQuery, id) if atomicRow is None: raise DataVeto( "Cannot find %s row %s" \ % (self._store.getTable().getTableName(), id)) self._store._peekQuery.atoms2row(atomicRow, self) """maybe a third argument `fillMode` to atoms2dict() which indicates whether existing (known) values should be overwritten, checked for equality or ignored... """ self.__dict__['_complete'] = True self.__dict__["_isCompleting"] = False
def setCellValue(self, row, value): raise DataVeto("not allowed")
def validate(self, value): if self.allowedClasses is None: return if value.__class__ in self.allowedClasses: return raise DataVeto("%r is not a valid %s" % (value, self))
def validate(self, value): if not isinstance(value, datetime.timedelta): #raise DataVeto(repr(value)+" is not a timedelta") raise DataVeto("not a timedelta")
def validate(self, value): if not isinstance(value, datetime.date): #raise repr(value)+" is not a date" raise DataVeto("not a date")
def validate(self, value): if value.__class__ in (types.FloatType, types.IntType): return raise DataVeto("not a date")
def validate(self, value): AsciiType.validate(self, value) if not ispure(value): raise DataVeto("%r is not pure" % value)
def validate(self, value): Type.validate(self, value) if len(value) == 0: raise DataVeto("Cannot store empty string.") if value.endswith(' '): raise DataVeto("%r ends with a space" % value)
def setAutoRowId(self, row): "set auto-incrementing row id" autoIncCol = self._peekQuery._pkColumns[-1] ## if autoIncCol.rowAttr.type is not ROWID: ## return ## if self._table.getTableName() == "Invoices": ## print autoIncCol.rowAttr.type ## raise "foo" #assert isinstance(autoIncCol.rowAttr.type,AutoIncType) assert len(autoIncCol._atoms) == 1 autoIncAtom = autoIncCol._atoms[0] if not isinstance(autoIncAtom.type, datatypes.AutoIncType): return ## if self._table.getTableName() == "Partners": ## print repr(autoIncAtom.type) ## raise "foo" pka = self._table.getPrimaryAtoms() id = row.getRowId() #id = atomicRow[:len(pka)] #print "area.py:%s" % repr(id) front, tail = id[:-1], id[-1] if None in front: raise DataVeto("Incomplete primary key %s for table %s" % (repr(id), self._table.getTableName())) #tailAtomicName = pka[-1][0] #tailType = pka[-1][1] # get or set self._lastId if len(front): # self._lastId is a dict x = self._lastId for i in front[:-1]: try: x = x[i] except KeyError: x[i] = {} x = x[i] # x is now the bottom-level dict i = front[-1] if not x.has_key(i): x[i] = self._connection.executeGetLastId(self._table, front) if x[i] is None: x[i] = 0 if tail is None: x[i] += 1 id[-1] = x[i] elif tail > x[i]: x[i] = tail else: if self._lastId is None: self._lastId = self._connection.executeGetLastId( self._table, front) if self._lastId is None: self._lastId = 0 if tail is None: if type(self._lastId) == type(''): self._lastId = str(int(self._lastId) + 1) else: self._lastId += 1 id[-1] = self._lastId elif tail > self._lastId: self._lastId = tail if tail is None: #row.setAtomicValue(pka[-1][0],id[-1]) #atomicRow[len(pka)-1] = id[-1] autoIncCol.setCellValue(row, id[-1])