diff --git a/chatrooms/ajax/chat.py b/chatrooms/ajax/chat.py index fbfdcf9..2aed5cc 100644 --- a/chatrooms/ajax/chat.py +++ b/chatrooms/ajax/chat.py @@ -8,7 +8,7 @@ from django.conf import settings from django.db.models.signals import post_save from django.dispatch import receiver -from django.http import (HttpResponse, +from ..utils.compat import (HttpResponse, HttpResponseBadRequest) from django.utils.decorators import method_decorator diff --git a/chatrooms/utils/compat.py b/chatrooms/utils/compat.py new file mode 100644 index 0000000..baeb965 --- /dev/null +++ b/chatrooms/utils/compat.py @@ -0,0 +1,18 @@ +from django import VERSION +from django.http import (HttpResponse as BaseHttpResponse, + HttpResponseBadRequest as Base400) + +# https://github.com/chicagobuss/graphite-web/commit/842944a34085c4b6bd5f37532118be996a0ff4f1 +class ContentTypeMixin(object): + def __init__(self, *args, **kwargs): + if VERSION < (1, 5) and 'content_type' in kwargs: + kwargs['mimetype'] = kwargs.pop('content_type') + elif VERSION > (1, 7) and 'mimetype' in kwargs: + kwargs['content_type'] = kwargs.pop('mimetype') + super(ContentTypeMixin, self).__init__(*args, **kwargs) + +class HttpResponse(ContentTypeMixin, BaseHttpResponse): + pass + +class HttpResponseBadRequest(ContentTypeMixin, Base400): + pass