- The title of a schema node now defaults to a titleization of the
``name``. Underscores in the ``name`` are replaced with empty strings and the first letter of every resulting word is capitalized. Previously the ``name`` was not split on underscores, and the entirety of the ``name`` was capitalized.
This commit is contained in:
@@ -1,6 +1,15 @@
|
|||||||
Changes
|
Changes
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
Next release
|
||||||
|
------------
|
||||||
|
|
||||||
|
- The title of a schema node now defaults to a titleization of the
|
||||||
|
``name``. Underscores in the ``name`` are replaced with empty
|
||||||
|
strings and the first letter of every resulting word is capitalized.
|
||||||
|
Previously the ``name`` was not split on underscores, and the
|
||||||
|
entirety of the ``name`` was capitalized.
|
||||||
|
|
||||||
0.7.2 (2010/08/30)
|
0.7.2 (2010/08/30)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|||||||
@@ -1150,9 +1150,10 @@ class SchemaNode(object):
|
|||||||
an object that implements the
|
an object that implements the
|
||||||
:class:`colander.interfaces.Validator` interface.
|
:class:`colander.interfaces.Validator` interface.
|
||||||
|
|
||||||
- ``title``: The title of this node. Defaults to a captialization
|
- ``title``: The title of this node. Defaults to a titleization
|
||||||
of the ``name``. The title is used by higher-level systems (not
|
of the ``name`` (underscores replaced with empty strings and the
|
||||||
by Colander itself).
|
first letter of every resulting word capitalized). The title is
|
||||||
|
used by higher-level systems (not by Colander itself).
|
||||||
|
|
||||||
- ``description``: The description for this node. Defaults to
|
- ``description``: The description for this node. Defaults to
|
||||||
``''`` (the empty string). The description is used by
|
``''`` (the empty string). The description is used by
|
||||||
@@ -1176,7 +1177,7 @@ class SchemaNode(object):
|
|||||||
self.default = kw.pop('default', null)
|
self.default = kw.pop('default', null)
|
||||||
self.missing = kw.pop('missing', _marker)
|
self.missing = kw.pop('missing', _marker)
|
||||||
self.name = kw.pop('name', '')
|
self.name = kw.pop('name', '')
|
||||||
self.title = kw.pop('title', self.name.capitalize())
|
self.title = kw.pop('title', self.name.replace('_', ' ').title())
|
||||||
self.description = kw.pop('description', '')
|
self.description = kw.pop('description', '')
|
||||||
self.widget = kw.pop('widget', None)
|
self.widget = kw.pop('widget', None)
|
||||||
if kw:
|
if kw:
|
||||||
@@ -1279,7 +1280,7 @@ class _SchemaMeta(type):
|
|||||||
if isinstance(value, SchemaNode):
|
if isinstance(value, SchemaNode):
|
||||||
value.name = name
|
value.name = name
|
||||||
if not value.title:
|
if not value.title:
|
||||||
value.title = name.capitalize()
|
value.title = name.replace('_', ' ').title()
|
||||||
nodes.append((value._order, value))
|
nodes.append((value._order, value))
|
||||||
cls.__schema_nodes__ = nodes
|
cls.__schema_nodes__ = nodes
|
||||||
# Combine all attrs from this class and its subclasses.
|
# Combine all attrs from this class and its subclasses.
|
||||||
|
|||||||
@@ -1271,15 +1271,15 @@ class TestSchemaNode(unittest.TestCase):
|
|||||||
self.failUnless(hasattr(node, '_order'))
|
self.failUnless(hasattr(node, '_order'))
|
||||||
|
|
||||||
def test_ctor_no_title(self):
|
def test_ctor_no_title(self):
|
||||||
node = self._makeOne(None, 0, validator=1, default=2, name='name',
|
node = self._makeOne(None, 0, validator=1, default=2, name='name_a',
|
||||||
missing='missing')
|
missing='missing')
|
||||||
self.assertEqual(node.typ, None)
|
self.assertEqual(node.typ, None)
|
||||||
self.assertEqual(node.children, [0])
|
self.assertEqual(node.children, [0])
|
||||||
self.assertEqual(node.validator, 1)
|
self.assertEqual(node.validator, 1)
|
||||||
self.assertEqual(node.default, 2)
|
self.assertEqual(node.default, 2)
|
||||||
self.assertEqual(node.missing, 'missing')
|
self.assertEqual(node.missing, 'missing')
|
||||||
self.assertEqual(node.name, 'name')
|
self.assertEqual(node.name, 'name_a')
|
||||||
self.assertEqual(node.title, 'Name')
|
self.assertEqual(node.title, 'Name A')
|
||||||
|
|
||||||
def test_ctor_with_title(self):
|
def test_ctor_with_title(self):
|
||||||
node = self._makeOne(None, 0, validator=1, default=2, name='name',
|
node = self._makeOne(None, 0, validator=1, default=2, name='name',
|
||||||
@@ -1434,7 +1434,7 @@ class TestSchema(unittest.TestCase):
|
|||||||
def test_it(self):
|
def test_it(self):
|
||||||
import colander
|
import colander
|
||||||
class MySchema(colander.Schema):
|
class MySchema(colander.Schema):
|
||||||
thing = colander.SchemaNode(colander.String())
|
thing_a = colander.SchemaNode(colander.String())
|
||||||
thing2 = colander.SchemaNode(colander.String(), title='bar')
|
thing2 = colander.SchemaNode(colander.String(), title='bar')
|
||||||
node = MySchema(default='abc')
|
node = MySchema(default='abc')
|
||||||
self.failUnless(hasattr(node, '_order'))
|
self.failUnless(hasattr(node, '_order'))
|
||||||
@@ -1442,7 +1442,7 @@ class TestSchema(unittest.TestCase):
|
|||||||
self.assertEqual(node.__class__, colander.SchemaNode)
|
self.assertEqual(node.__class__, colander.SchemaNode)
|
||||||
self.assertEqual(node.typ.__class__, colander.Mapping)
|
self.assertEqual(node.typ.__class__, colander.Mapping)
|
||||||
self.assertEqual(node.children[0].typ.__class__, colander.String)
|
self.assertEqual(node.children[0].typ.__class__, colander.String)
|
||||||
self.assertEqual(node.children[0].title, 'Thing')
|
self.assertEqual(node.children[0].title, 'Thing A')
|
||||||
self.assertEqual(node.children[1].title, 'bar')
|
self.assertEqual(node.children[1].title, 'bar')
|
||||||
|
|
||||||
class TestSequenceSchema(unittest.TestCase):
|
class TestSequenceSchema(unittest.TestCase):
|
||||||
|
|||||||
Reference in New Issue
Block a user