25 lines
462 B
Python
25 lines
462 B
Python
from decimal import Decimal
|
|
import uuid
|
|
from pyramid.renderers import JSON
|
|
|
|
|
|
class DecimalAsFloatHack(float):
|
|
def __init__(self, d):
|
|
self.d = d
|
|
|
|
def __repr__(self):
|
|
return str(self.d)
|
|
|
|
|
|
def decimal_adaptor(obj, request):
|
|
return DecimalAsFloatHack(obj)
|
|
|
|
|
|
def uuid_adaptor(obj, request):
|
|
return str(obj)
|
|
|
|
json_renderer = JSON()
|
|
|
|
json_renderer.add_adapter(Decimal, decimal_adaptor)
|
|
json_renderer.add_adapter(uuid.UUID, uuid_adaptor)
|