j2labs/schematics — pull request #197 by kstrauser (2014-01-10 21:02:45+00:00)
Title: Giving context to serialization

This adds a new 'context' keyword argument to all to_native, to_primitive, and related function so that users can pass in information that those methods need to correctly deserialize data.

For instance, suppose a hypothetical MultiLanguageString type that holds messages in many different locales. The context argument allows users to pass in a requested locale so that the MultiLanguageString can return the correct string representation. For example:

```python
>>> class TestModel(Model):
... mls = MultiLingualStringType()
...

>>> t = TestModel({'mls': {'en_US': 'Hello, world!'}})

>>> t.to_native()
{'mls': {u'en_US': u'Hello, world!'}}

>>> t.to_native(context={'locale': 'en_US'})
{'mls': u'Hello, world!'}
```