if value is not None and hasattr(self, 'validate_' + key):
validate = getattr(self, 'validate_' + key)
self[key] = validate(value)
if value is not None and hasattr(self, 'validate_' + key):
validate = getattr(self, 'validate_' + key)
self[key] = validate(value)
- """
- Separate a list of different typed objects.
- Return a list for each type (ints, strs and dicts)
- """
-
- if isinstance(items, (list, tuple, set)):
- ints = filter(lambda x: isinstance(x, (int, long)), items)
- strs = filter(lambda x: isinstance(x, StringTypes), items)
- dicts = filter(lambda x: isinstance(x, dict), items)
- return (ints, strs, dicts)
- else:
- raise PLCInvalidArgument, "Can only separate list types"
-
+ """
+ Separate a list of different typed objects.
+ Return a list for each type (ints, strs and dicts)
+ """
+
+ if isinstance(items, (list, tuple, set)):
+ ints = filter(lambda x: isinstance(x, (int, long)), items)
+ strs = filter(lambda x: isinstance(x, StringTypes), items)
+ dicts = filter(lambda x: isinstance(x, dict), items)
+ return (ints, strs, dicts)
+ else:
+ raise PLCInvalidArgument, "Can only separate list types"
+
- if len(args) < 3:
- raise PLCInvalidArgumentCount, "auth, field, value must be specified"
- elif hasattr(self, 'associate_' + args[1]):
- associate = getattr(self, 'associate_'+args[1])
- associate(*args)
- else:
- raise PLCInvalidArguemnt, "No such associate function associate_%s" % args[1]
+ if len(args) < 3:
+ raise PLCInvalidArgumentCount, "auth, field, value must be specified"
+ elif hasattr(self, 'associate_' + args[1]):
+ associate = getattr(self, 'associate_'+args[1])
+ associate(*args)
+ else:
+ raise PLCInvalidArguemnt, "No such associate function associate_%s" % args[1]
def validate_timestamp (self, timestamp):
return Timestamp.sql_validate(timestamp)
def validate_timestamp (self, timestamp):
return Timestamp.sql_validate(timestamp)
assert isinstance(obj, classobj)
assert isinstance(obj, Row)
assert obj.primary_key in obj
assert isinstance(obj, classobj)
assert isinstance(obj, Row)
assert obj.primary_key in obj
assert isinstance(self, Row)
assert self.primary_key in self
assert join_table in self.join_tables
assert isinstance(self, Row)
assert self.primary_key in self
assert join_table in self.join_tables
assert isinstance(obj, Row)
assert obj.primary_key in obj
assert join_table in obj.join_tables
assert isinstance(obj, Row)
assert obj.primary_key in obj
assert join_table in obj.join_tables
self.api.db.do("DELETE FROM %s WHERE %s = %s AND %s = %s" % \
(join_table,
self.primary_key, self.api.db.param('self_id', self_id),
self.api.db.do("DELETE FROM %s WHERE %s = %s AND %s = %s" % \
(join_table,
self.primary_key, self.api.db.param('self_id', self_id),
def tag_fields (self, obj=None):
"""
Return the fields of obj that are mentioned in tags
"""
if obj is None: obj=self
def tag_fields (self, obj=None):
"""
Return the fields of obj that are mentioned in tags
"""
if obj is None: obj=self
# takes as input a list of columns, sort native fields from tags
# returns 2 dicts and one list : fields, tags, rejected
@classmethod
# takes as input a list of columns, sort native fields from tags
# returns 2 dicts and one list : fields, tags, rejected
@classmethod
raise Exception, 'WARNING: class %s needs to set view_tags_name'%cls.__name__
table_name=cls.table_name
raise Exception, 'WARNING: class %s needs to set view_tags_name'%cls.__name__
table_name=cls.table_name
- 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):
-
- # If primary key id is a serial int and it isnt included, get next id
- if self.fields[self.primary_key].type in (IntType, LongType) and \
- self.primary_key not in self:
- pk_id = self.api.db.next_id(self.table_name, self.primary_key)
- self[self.primary_key] = pk_id
- db_fields[self.primary_key] = pk_id
- keys = db_fields.keys()
- values = [self.api.db.param(key, value) for (key, value) in db_fields.items()]
+
+ # If primary key id is a serial int and it isnt included, get next id
+ if self.fields[self.primary_key].type in (IntType, LongType) and \
+ self.primary_key not in self:
+ pk_id = self.api.db.next_id(self.table_name, self.primary_key)
+ self[self.primary_key] = pk_id
+ db_fields[self.primary_key] = pk_id
+ keys = db_fields.keys()
+ values = [self.api.db.param(key, value) for (key, value) in db_fields.items()]
# Insert new row
sql = "INSERT INTO %s (%s) VALUES (%s)" % \
(self.table_name, ", ".join(keys), ", ".join(values))
else:
# Update existing row
columns = ["%s = %s" % (key, value) for (key, value) in zip(keys, values)]
# Insert new row
sql = "INSERT INTO %s (%s) VALUES (%s)" % \
(self.table_name, ", ".join(keys), ", ".join(values))
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]))