Jonathan Vanasco <[email protected]>
writes:
> If anyone has done this already , would you mind sharing your code and
> setup ?
I have this (trimmed) code in a module loaded by the standard
"pyramid.includes" setting::
class Encoder(JSONEncoder):
"""Extends JSONEncoder for date and decimal types."""
...
def py2json(data):
return dumps(data, cls=Encoder, separators=(',', ':'))
def json_renderer_factory(info):
def _render(value, system):
request = system.get('request')
if request is not None:
response = request.response
ct = response.content_type
if ct == response.default_content_type:
response.content_type = 'application/json'
return py2json(value)
return _render
def includeme(config):
"""Install our JSON renderer, able to deal with datetimes."""
config.add_renderer('json', json_renderer_factory)
hth,
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected] | -- Fortunato Depero, 1929.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.