issue with title being overwritten when child

PR #183 and #185 tried to fix this but missed one aspect when
a schemanode is added as a child via class definitions.
This commit is contained in:
Tim Tisdall
2015-07-10 17:32:05 +00:00
parent b1b95374dc
commit ce28908165
2 changed files with 14 additions and 5 deletions

View File

@@ -1862,7 +1862,7 @@ class _SchemaNode(object):
missing = required missing = required
missing_msg = 'Required' missing_msg = 'Required'
name = '' name = ''
raw_title = _marker raw_title = _marker # only changes if title is explicitly set
title = _marker title = _marker
description = '' description = ''
widget = None widget = None
@@ -1888,9 +1888,8 @@ class _SchemaNode(object):
self.typ = self.schema_type() self.typ = self.schema_type()
# bw compat forces us to manufacture a title if one is not supplied # bw compat forces us to manufacture a title if one is not supplied
title = kw.get('title', _marker) title = kw.get('title', self.title)
if title is _marker: if title is _marker:
if self.title is _marker:
name = kw.get('name', self.name) name = kw.get('name', self.name)
kw['title'] = name.replace('_', ' ').title() kw['title'] = name.replace('_', ' ').title()
else: else:

View File

@@ -2847,6 +2847,16 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
node = MyNode(name='my', title='other title') node = MyNode(name='my', title='other title')
self.assertEqual(node.title, 'other title') self.assertEqual(node.title, 'other title')
def test_subelement_title_not_overwritten(self):
import colander
class SampleNode(colander.SchemaNode):
schema_type = colander.String
title = 'Some Title'
class SampleSchema(colander.Schema):
node = SampleNode()
schema = SampleSchema()
self.assertEqual('Some Title', schema.children[0].title)
def test_subclass_value_overridden_by_constructor(self): def test_subclass_value_overridden_by_constructor(self):
import colander import colander
class MyNode(colander.SchemaNode): class MyNode(colander.SchemaNode):