-# $Id$
-# $URL$
from types import StringTypes, IntType, LongType
import time
import calendar
for this object, and are not marked as a read-only Parameter.
"""
- if obj is None: obj = self
+ if obj is None:
+ obj = self
db_fields = self.api.db.fields(self.table_name)
- return dict ( [ (key,value) for (key,value) in obj.items()
+ return dict ( [ (key, value) for (key, value) in obj.items()
if key in db_fields and
- Row.is_writable(key,value,self.fields) ] )
+ Row.is_writable(key, value, self.fields) ] )
def tag_fields (self, obj=None):
"""
y = self.db_fields(y)
return dict.__eq__(x, y)
- def sync(self, commit = True, insert = None):
+ # validate becomes optional on sept. 2010
+ # we find it useful to use DeletePerson on duplicated entries
+ def sync(self, commit = True, insert = None, validate=True):
"""
Flush changes back to the database.
"""
# Validate all specified fields
- self.validate()
+ if validate: self.validate()
# Filter out fields that cannot be set or updated directly
db_fields = self.db_fields()
else:
# Update existing row
columns = ["%s = %s" % (key, value) for (key, value) in zip(keys, values)]
- sql = "UPDATE %s SET " % self.table_name + \
- ", ".join(columns) + \
- " WHERE %s = %s" % \
- (self.primary_key,
- self.api.db.param(self.primary_key, self[self.primary_key]))
+ sql = "UPDATE {} SET {} WHERE {} = {}"\
+ .format(self.table_name,
+ ", ".join(columns),
+ self.primary_key,
+ self.api.db.param(self.primary_key, self[self.primary_key]))
self.api.db.do(sql, db_fields)