fixed problem with _listify, thanks Daniel

This commit is contained in:
Massimo Di Pierro
2012-08-24 09:15:34 -05:00
parent c309588ae4
commit eb802838ee
2 changed files with 22 additions and 17 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.0 (2012-08-24 08:56:41) dev
Version 2.00.0 (2012-08-24 09:15:19) dev
+21 -16
View File
@@ -7501,33 +7501,38 @@ class Table(dict):
return self._db._adapter.drop(self,mode)
def _listify(self,fields,update=False):
new_fields = []
new_fields_names = []
new_fields = {} # format: new_fields[name] = (field,value)
# store all fields passed as input in new_fields
for name in fields:
if not name in self.fields:
if name != 'id':
raise SyntaxError, 'Field %s does not belong to the table' % name
raise SyntaxError, \
'Field %s does not belong to the table' % name
else:
field = self[name]
value = fields[name]
if field.filter_in: value = field.filter_in(value)
new_fields.append((field,value))
new_fields_names.append(name)
for ofield in self:
if not ofield.name in new_fields_names:
if not update and not ofield.default is None:
new_fields.append((ofield,ofield.default))
elif update and not ofield.update is None:
new_fields.append((ofield,ofield.update))
if field.filter_in:
value = field.filter_in(value)
new_fields[name] = (field,value)
# check all fields that should be in the self table
for ofield in self:
name = ofield.name
# if field is supposed to be computed, compute it!
if ofield.compute:
try:
new_fields.append((ofield,ofield.compute(Row(fields))))
new_fields[name] = (ofield,ofield.compute(Row(fields)))
except KeyError:
pass
if not update and ofield.required and not ofield.name in new_fields_names:
raise SyntaxError,'Table: missing required field: %s' % ofield.name
return new_fields
# if field is required, check its default value
elif not name in new_fields:
if not update and not ofield.default is None:
new_fields[name] = (ofield,ofield.default)
elif update and not ofield.update is None:
new_fields[name] = (ofield,ofield.update)
# error if field if required, record to be create and field missing
if not update and ofield.required and not name in new_fields:
raise SyntaxError, 'Table: missing required field: %s' % name
return new_fields.values()
def _attempt_upload(self, fields):
for field in self: