Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 1.7 compatibility #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions provider/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import urlparse
from django.http import HttpResponse
from django.http import HttpResponseRedirect, QueryDict
from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateView
Expand All @@ -9,6 +8,14 @@
from . import constants, scope


try:
from django.http import JsonResponse
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, I would add since >= django1.7 comment and maybe move that to provider/compat ?

except ImportError:
from django.http import HttpResponse
def JsonResponse(response_data, *args, **kwargs):
return HttpResponse(json.dumps(response_data), *args, mimetype='application/json', **kwargs)


class OAuthError(Exception):
"""
Exception to throw inside any views defined in :attr:`provider.views`.
Expand Down Expand Up @@ -298,8 +305,7 @@ def error_response(self, error, mimetype='application/json', status=400,
Return an error response to the client with default status code of
*400* stating the error as outlined in :rfc:`5.2`.
"""
return HttpResponse(json.dumps(error), mimetype=mimetype,
status=status, **kwargs)
return JsonResponse(error, status=status, **kwargs)

def get(self, request):
data = self.get_data(request)
Expand Down Expand Up @@ -463,8 +469,7 @@ def error_response(self, error, mimetype='application/json', status=400,
Return an error response to the client with default status code of
*400* stating the error as outlined in :rfc:`5.2`.
"""
return HttpResponse(json.dumps(error), mimetype=mimetype,
status=status, **kwargs)
return JsonResponse(error, status=status, **kwargs)

def access_token_response(self, access_token):
"""
Expand All @@ -487,9 +492,7 @@ def access_token_response(self, access_token):
except ObjectDoesNotExist:
pass

return HttpResponse(
json.dumps(response_data), mimetype='application/json'
)
return JsonResponse(response_data)

def authorization_code(self, request, data, client):
"""
Expand Down