Repository: django-cms/django-cms

Issue:
Usage of deprecated mimetype parameter crashes Django 1.7+
On the `support/3.0.x` branch, `mimetype` should be `content_type` for Django 1.6+. On `develop` where we don't need support for Django 1.4/1.5, we don't need conditional logic at all.

```
cms/utils/admin.py:        return render_to_response(template, context, mimetype="text/html; charset=utf-8")
cms/admin/settingsadmin.py:            return HttpResponse(json.dumps(""), mimetype="application/json")
cms/admin/settingsadmin.py:        return HttpResponse(json.dumps(request.session.get('cms_settings', '')), mimetype="application/json")
```

Apparently tests for these code paths also need to be added. Are the code paths that use `content_type` unconditionally also untested as it seems that should fail on Django 1.4/1.5? (e.g. a1650839)



Discussion:
@timgraham shouldn't it be `content_type` for Django 1.5+ (https://docs.djangoproject.com/en/1.5/topics/http/shortcuts/#django.shortcuts.render_to_response)?
I don't think we have **any** test specific for these functions
Cleanup on develop will happen after 3.0.8 relese

Correct, sorry I got the version wrong on that.

No worries :)
Fixing the 1.4 issue (I bet we don't have much users on 1.4, though)
I'll leave this open anyway for 3.1 to help writing more tests for such functions


Resolving patch:
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -39,13 +39,13 @@
 from cms.utils import helpers, permissions, get_language_from_request, admin as admin_utils, copy_plugins
 from cms.utils.i18n import get_language_list, get_language_tuple, get_language_object, force_language
 from cms.utils.admin import jsonify_request
+from cms.utils.compat import DJANGO_1_4
 from cms.utils.compat.dj import force_unicode, is_installed
 from cms.utils.compat.urls import unquote
 from cms.utils.conf import get_cms_setting
 from cms.utils.helpers import find_placeholder_relation
 from cms.utils.permissions import has_global_page_permission, has_generic_permission
 from cms.utils.plugins import current_site
-from cms.utils.compat import DJANGO_1_4
 from cms.utils.transaction import wrap_transaction
 from cms.utils.urlutils import add_url_parameters, admin_reverse
 
@@ -1356,7 +1356,10 @@ def add_page_type(self, request):
 
     def resolve(self, request):
         if not request.user.is_staff:
-            return HttpResponse('', content_type='text/plain')
+            if DJANGO_1_4:
+                return HttpResponse('', mimetype='text/plain')
+            else:
+                return HttpResponse('', content_type='text/plain')
         if request.session.get('cms_log_latest', False):
             log = LogEntry.objects.get(pk=request.session['cms_log_latest'])
             try:
@@ -1473,7 +1476,10 @@ def get_published_pagelist(self, *args, **kwargs):
                     }
                 )
 
-            return HttpResponse(json.dumps(results), content_type='application/json')
+            if DJANGO_1_4:
+                return HttpResponse(json.dumps(results), mimetype='application/json')
+            else:
+                return HttpResponse(json.dumps(results), content_type='application/json')
 
         else:
             return HttpResponseForbidden()
diff --git a/cms/admin/placeholderadmin.py b/cms/admin/placeholderadmin.py
--- a/cms/admin/placeholderadmin.py
+++ b/cms/admin/placeholderadmin.py
@@ -31,6 +31,7 @@
 from django.http import HttpResponseRedirect
 
 from cms.utils import copy_plugins, permissions, get_language_from_request
+from cms.utils.compat import DJANGO_1_4
 from cms.utils.i18n import get_language_list
 from cms.utils.transaction import wrap_transaction
 
@@ -274,7 +275,10 @@ def add_plugin(self, request):
                         args=[plugin.pk])),
             'breadcrumb': plugin.get_breadcrumb(),
         }
-        return HttpResponse(json.dumps(response), content_type='application/json')
+        if DJANGO_1_4:
+            return HttpResponse(json.dumps(response), mimetype='application/json')
+        else:
+            return HttpResponse(json.dumps(response), content_type='application/json')
 
     @method_decorator(require_POST)
     @xframe_options_sameorigin
@@ -344,7 +348,10 @@ def copy_plugins(self, request):
             )
         self.post_copy_plugins(request, source_placeholder, target_placeholder, plugins)
         json_response = {'plugin_list': reduced_list, 'reload': reload_required}
-        return HttpResponse(json.dumps(json_response), content_type='application/json')
+        if DJANGO_1_4:
+            return HttpResponse(json.dumps(json_response), mimetype='application/json')
+        else:
+            return HttpResponse(json.dumps(json_response), content_type='application/json')
 
     @xframe_options_sameorigin
     def edit_plugin(self, request, plugin_id):
@@ -480,7 +487,10 @@ def move_plugin(self, request):
                 x += 1
         self.post_move_plugin(request, source_placeholder, placeholder, plugin)
         json_response = {'reload': requires_reload(PLUGIN_MOVE_ACTION, [plugin])}
-        return HttpResponse(json.dumps(json_response), content_type='application/json')
+        if DJANGO_1_4:
+            return HttpResponse(json.dumps(json_response), mimetype='application/json')
+        else:
+            return HttpResponse(json.dumps(json_response), content_type='application/json')
 
     @xframe_options_sameorigin
     def delete_plugin(self, request, plugin_id):
diff --git a/cms/utils/admin.py b/cms/utils/admin.py
--- a/cms/utils/admin.py
+++ b/cms/utils/admin.py
@@ -1,22 +1,20 @@
 # -*- coding: utf-8 -*-
-from distutils.version import LooseVersion
 import json
 
-import django
 from django.contrib.sites.models import Site
 from django.http import HttpResponse
 from django.shortcuts import render_to_response
 from django.template.context import RequestContext
 from django.utils.encoding import smart_str
 
+from cms.constants import PUBLISHER_STATE_PENDING, PUBLISHER_STATE_DIRTY
 from cms.models import Page, GlobalPagePermission
 from cms.utils import get_language_from_request
 from cms.utils import get_language_list
 from cms.utils import get_cms_setting
-from cms.constants import PUBLISHER_STATE_PENDING, PUBLISHER_STATE_DIRTY
+from cms.utils.compat import DJANGO_1_4
 
 NOT_FOUND_RESPONSE = "NotFound"
-DJANGO_1_4 = LooseVersion(django.get_version()) < LooseVersion('1.5')
 
 
 def jsonify_request(response):
@@ -26,8 +24,10 @@ def jsonify_request(response):
          * content: original response content
     """
     content = {'status': response.status_code, 'content': smart_str(response.content, response._charset)}
-    return HttpResponse(json.dumps(content),
-                        content_type="application/json")
+    if DJANGO_1_4:
+        return HttpResponse(json.dumps(content), mimetype="text/html; charset=utf-8")
+    else:
+        return HttpResponse(json.dumps(content), content_type="text/html; charset=utf-8")
 
 
 publisher_classes = {


Test patch: