Skip to content

Commit

Permalink
feat(renderer): add json handler
Browse files Browse the repository at this point in the history
  • Loading branch information
suryakencana007 committed Jan 22, 2018
1 parent c43fc08 commit acf7351
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Major release, unreleased codename ``aiko``
- add exception handler function, ``exception_handler`` route, default code 509 dengan pesan status berisi error exception `(resiliency)` methodologi.
- add ``trafaret`` validator, default False untuk `config_schema` values.
- add directive ``add_config_validator``, untuk schema trafaret validator.
- custom JSON renderer, ``JSONEncoder``, type object dump (ObjectId untuk mongodb id); uuid type; datetime type; EnumInt Type; enum


.. _Bakadocs: http://baka-framework.readthedocs.io/en/latest/
4 changes: 4 additions & 0 deletions baka/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import bson
from bson.objectid import ObjectId
from pyramid.renderers import JSON

from baka._compat import text_type
from .response import JSONAPIResponse
Expand Down Expand Up @@ -82,6 +83,7 @@ def __call__(self, value, system):
dictionary containing available system values
# (e.g. view, context, and request). """
request = system['request']

with JSONAPIResponse(request.response) as resp:
_in = u'Failed'
code, status = request.response.status_code, request.response.status
Expand Down Expand Up @@ -143,4 +145,6 @@ def __repr__(self):


def includeme(config):
json_renderer = JSON(cls=JSONEncoder)
config.add_renderer('json', json_renderer)
config.add_renderer('restful', Factory)
4 changes: 3 additions & 1 deletion examples/simpleapp/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from baka import Baka
from baka.log import log

Expand All @@ -8,7 +10,7 @@
@app.route('/')
def home_index(req):
log.info('/')
return {'home_page': 'Hello World'}
return {'home_page': 'Hello World', 'today': datetime.datetime.now().isoformat()}


@app.route('/home')
Expand Down

0 comments on commit acf7351

Please sign in to comment.