Skip to content

Commit

Permalink
add compatibilty for mimetype on HttpResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
roramirez committed Jul 18, 2015
1 parent 7725424 commit 0d4e95f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chatrooms/ajax/chat.py
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions 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

0 comments on commit 0d4e95f

Please sign in to comment.