Permalink
Browse files

Fix #79 : default value handling in SequenceWidget's subfields

  • Loading branch information...
1 parent 0928991 commit 6951d3e29f7eaa2d39d2441a98b06da83665328a @tonthon committed Sep 20, 2012
Showing with 23 additions and 8 deletions.
  1. +15 −6 deform/tests/test_widget.py
  2. +8 −2 deform/widget.py
@@ -1235,7 +1235,7 @@ def test_prototype_unicode(self):
schema = DummySchema()
field = DummyField(schema, renderer)
widget = self._makeOne()
- protofield = DummyField()
+ protofield = DummyField(schema)
field.children=[protofield]
result = widget.prototype(field)
self.assertEqual(type(result), str)
@@ -1248,7 +1248,7 @@ def test_prototype_str(self):
schema = DummySchema()
field = DummyField(schema, renderer)
widget = self._makeOne()
- protofield = DummyField()
+ protofield = DummyField(schema)
field.children=[protofield]
result = widget.prototype(field)
self.assertEqual(type(result), str)
@@ -1289,7 +1289,7 @@ def test_serialize_null_render_initial_item(self):
renderer = DummyRenderer('abc')
schema = DummySchema()
field = DummyField(schema, renderer)
- inner = DummyField()
+ inner = DummyField(schema)
field.children=[inner]
widget = self._makeOne()
widget.render_initial_item = True
@@ -1305,7 +1305,7 @@ def test_serialize_null_min_len_larger_than_cstruct(self):
renderer = DummyRenderer('abc')
schema = DummySchema()
field = DummyField(schema, renderer)
- inner = DummyField()
+ inner = DummyField(schema)
field.children=[inner]
widget = self._makeOne()
widget.min_len = 2
@@ -1321,7 +1321,7 @@ def test_serialize_null_min_one(self):
renderer = DummyRenderer('abc')
schema = DummySchema()
field = DummyField(schema, renderer)
- inner = DummyField()
+ inner = DummyField(schema)
field.children=[inner]
widget = self._makeOne()
widget.min_len = 1
@@ -1824,11 +1824,17 @@ def deserialize(self, field, pstruct):
raise self.exc
return pstruct
+ def serialize(self, field, cstruct):
+ if self.exc:
+ raise self.exc
+ return cstruct
+
def handle_error(self, field, error):
self.error = error
class DummySchema(object):
- pass
+ def serialize(self, cstruct):
+ return cstruct
class DummyInvalid(object):
pos = 0
@@ -1855,6 +1861,9 @@ def clone(self):
self.cloned = True
return self
+ def serialize(self, cstruct):
+ return self.widget.serialize(self, cstruct)
+
def deserialize(self, pstruct):
return self.widget.deserialize(self, pstruct)
View
@@ -1190,6 +1190,7 @@ def prototype(self, field):
# we clone the item field to bump the oid (for easier
# automated testing; finding last node)
item_field = field.children[0].clone()
+ # Ref #79 : call the serialize method of subnodes
proto = field.renderer(self.item_template, field=item_field,
cstruct=item_field.schema.serialize(null),
parent=field)
@@ -1225,8 +1226,13 @@ def serialize(self, field, cstruct, readonly=False):
else:
# this serialization is being performed as a result of a
# first-time rendering
- subfields = [ (item_field.schema.serialize(val),
- item_field.clone()) for val in cstruct ]
+ subfields = []
+ for val in cstruct:
+ if val == null:
+ # Ref #79 : if val is null maybe some default
+ # should be set by subnodes
+ val = item_field.schema.serialize(val)
+ subfields.append((val, item_field.clone()))
template = readonly and self.readonly_template or self.template
translate = field.translate

0 comments on commit 6951d3e

Please sign in to comment.