3 Representation of a row in a database table. To use, optionally
4 instantiate with a dict of values. Update as you would a
5 dict. Commit to the database with sync().
8 # Set this to a dict of the valid fields of this object. Not all
9 # fields (e.g., joined fields) may be updated via sync().
12 def __init__(self, fields):
15 def update(self, fields):
16 for key, value in fields.iteritems():
17 self.__setitem__(key, value)
19 def __setitem__(self, key, value):
21 Magically takes care of aggregating certain variables into
25 if key in self.fields:
26 dict.__setitem__(self, key, value)
30 Validates values. Will validate a value with a custom function
31 if a function named 'validate_[key]' exists.
34 # Validate values before committing
35 # XXX Also truncate strings that are too long
36 for key, value in self.iteritems():
37 if value is not None and hasattr(self, 'validate_' + key):
38 validate = getattr(self, 'validate_' + key)
39 self[key] = validate(value)
41 def sync(self, commit = True):
43 Flush changes back to the database.
50 Representation of row(s) in a database table.
53 def sync(self, commit = True):
55 Flush changes back to the database.
58 for row in self.values():