Skip to content

Commit

Permalink
Add request argument to render_to_json function
Browse files Browse the repository at this point in the history
  • Loading branch information
yceruto committed Feb 7, 2019
1 parent 79b0138 commit 9f64eda
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions django_ajax/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def inner(request, *args, **kwargs):
if request.is_ajax():
# return json response
try:
return render_to_json(func(request, *args, **kwargs), **ajax_kwargs)
return render_to_json(func(request, *args, **kwargs), request, **ajax_kwargs)
except Exception as exception:
return render_to_json(exception, **{'request': request})
return render_to_json(exception, request)
else:
# return standard response
return func(request, *args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion django_ajax/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LazyJSONEncoder(LazyJSONEncoderMixin, json.JSONEncoder):
pass


def serialize_to_json(data, *args, **kwargs):
def serialize_to_json(data, **kwargs):
"""
A wrapper for simplejson.dumps with defaults as:
Expand Down
4 changes: 2 additions & 2 deletions django_ajax/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JSONResponse(HttpResponse):
Return a JSON serialized HTTP response
"""

def __init__(self, data, *args, **kwargs):
def __init__(self, data, **kwargs):
"""
This returns a object that we send as json content using
utils.serialize_to_json, that is a wrapper to json.dumps
Expand All @@ -26,6 +26,6 @@ def __init__(self, data, *args, **kwargs):
kwargs['sort_keys'] = settings.DEBUG

super(JSONResponse, self).__init__(
content=serialize_to_json(data, *args, **kwargs),
content=serialize_to_json(data, **kwargs),
content_type='application/json'
)
6 changes: 3 additions & 3 deletions django_ajax/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}


def render_to_json(response, *args, **kwargs):
def render_to_json(response, request=None, **kwargs):
"""
Creates the main structure and returns the JSON response.
"""
Expand All @@ -87,7 +87,7 @@ def render_to_json(response, *args, **kwargs):
status_code = 404
elif issubclass(type(response), Exception):
status_code = 500
logger.exception(str(response), extra={'request': kwargs.pop('request', None)})
logger.exception(str(response), extra={'request': request})

if settings.DEBUG:
import sys
Expand All @@ -106,5 +106,5 @@ def render_to_json(response, *args, **kwargs):
'content': response
}

return JSONResponse(data, *args, **kwargs)
return JSONResponse(data, **kwargs)

0 comments on commit 9f64eda

Please sign in to comment.