Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue #79 #121

Closed
wants to merge 2 commits into from

2 participants

@tonthon

Tests run fine now

@mcdonc
Owner

This was fixed slightly differently, see comments attached to #79. Thanks!

@mcdonc mcdonc closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 18 deletions.
  1. +15 −6 deform/tests/test_widget.py
  2. +20 −12 deform/widget.py
View
21 deform/tests/test_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
32 deform/widget.py
@@ -271,31 +271,31 @@ class MoneyInputWidget(Widget):
symbol
the symbol to be used before of the user values. default: ``$``
-
+
showSymbol
set if the symbol must be displayed or not. default: ``False``
-
+
symbolStay
set if the symbol will stay in the field after the user exists the
field. default: ``False``
-
+
thousands
the thousands separator. default: ``,``
-
+
decimal
the decimal separator. default: ``.``
-
+
precision
how many decimal places are allowed. default: 2
defaultZero
when the user enters the field, it sets a default mask using zero.
default: ``True``
-
+
allowZero
use this setting to prevent users from inputing zero. default:
``False``
-
+
allowNegative
use this setting to prevent users from inputing negative values.
default: ``False``
@@ -305,7 +305,7 @@ class MoneyInputWidget(Widget):
requirements = ( ('jquery.maskMoney', None), )
options = None
size = None
-
+
def serialize(self, field, cstruct, readonly=False):
if cstruct in (null, None):
cstruct = ''
@@ -316,7 +316,7 @@ def serialize(self, field, cstruct, readonly=False):
options = json.dumps(dict(options))
return field.renderer(template, mask_options=options, field=field,
cstruct=cstruct)
-
+
def deserialize(self, field, pstruct):
if pstruct is null:
return null
@@ -1190,8 +1190,10 @@ 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=null, parent=field)
+ cstruct=item_field.schema.serialize(null),
+ parent=field)
if isinstance(proto, string_types):
proto = proto.encode('utf-8')
proto = url_quote(proto)
@@ -1224,7 +1226,13 @@ def serialize(self, field, cstruct, readonly=False):
else:
# this serialization is being performed as a result of a
# first-time rendering
- subfields = [ (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
@@ -1234,7 +1242,7 @@ def serialize(self, field, cstruct, readonly=False):
subitem_name=item_field.name)
if isinstance(self.add_subitem_text_template, TranslationString):
add_subitem_text = self.add_subitem_text_template % \
- add_template_mapping
+ add_template_mapping
else:
add_subitem_text = _(self.add_subitem_text_template,
mapping=add_template_mapping)
Something went wrong with that request. Please try again.