Remove some old (pre-1.8) Django compatibility code

These lines of code were introduced as Horizon migrated
through several Django versions and are no longer
needed.

Change-Id: I12aae1a843fccc803859da6337a3274339a3741f
Partially-Implements: blueprint drop-dj17
This commit is contained in:
Richard Jones 2015-11-05 16:51:48 +11:00
parent 13ff6392f9
commit 89ce71c4e9
6 changed files with 7 additions and 91 deletions

View File

@ -33,6 +33,7 @@ from django.conf.urls import url
from django.core.exceptions import ImproperlyConfigured # noqa from django.core.exceptions import ImproperlyConfigured # noqa
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import empty
from django.utils.functional import SimpleLazyObject # noqa from django.utils.functional import SimpleLazyObject # noqa
from django.utils.importlib import import_module # noqa from django.utils.importlib import import_module # noqa
from django.utils.module_loading import module_has_submodule # noqa from django.utils.module_loading import module_has_submodule # noqa
@ -651,12 +652,6 @@ class Dashboard(Registry, HorizonComponent):
class Workflow(object): class Workflow(object):
pass pass
try:
from django.utils.functional import empty # noqa
except ImportError:
# Django 1.3 fallback
empty = None
class LazyURLPattern(SimpleLazyObject): class LazyURLPattern(SimpleLazyObject):
def __iter__(self): def __iter__(self):

View File

@ -16,7 +16,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import django
import logging import logging
import os import os
import socket import socket
@ -32,16 +31,12 @@ from django.core.handlers import wsgi
from django import http from django import http
from django import test as django_test from django import test as django_test
from django.test.client import RequestFactory # noqa from django.test.client import RequestFactory # noqa
from django.test import testcases
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils import unittest from django.utils import unittest
import six import six
if django.VERSION < (1, 7): from django.contrib.staticfiles.testing \
from django.test import LiveServerTestCase # noqa import StaticLiveServerTestCase as LiveServerTestCase
else:
from django.contrib.staticfiles.testing \
import StaticLiveServerTestCase as LiveServerTestCase # noqa
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -225,60 +220,6 @@ class TestCase(django_test.TestCase):
"%s messages not as expected: %s" % (msg_type.title(), "%s messages not as expected: %s" % (msg_type.title(),
", ".join(msgs)) ", ".join(msgs))
def assertNotContains(self, response, text, status_code=200,
msg_prefix='', html=False):
# Prior to Django 1.7 assertContains and assertNotContains behaved
# differently regarding response's 'streaming' flag
if django.VERSION < (1, 7):
return self._assertNotContains(response, text, status_code,
msg_prefix, html)
else:
return super(TestCase, self).assertNotContains(
response, text, status_code, msg_prefix, html)
def _assertNotContains(self, response, text, status_code=200,
msg_prefix='', html=False):
"""Asserts that a response indicates that some content was retrieved
successfully, (i.e., the HTTP status code was as expected), and that
``text`` doesn't occurs in the content of the response.
This is an override of django_test.TestCase.assertNotContains method,
which is able to work with StreamingHttpResponse. Should be called
for Django versions prior to 1.7.
"""
# If the response supports deferred rendering and hasn't been rendered
# yet, then ensure that it does get rendered before proceeding further.
if (hasattr(response, 'render') and callable(response.render) and
not response.is_rendered):
response.render()
if msg_prefix:
msg_prefix += ": "
self.assertEqual(
response.status_code, status_code,
msg_prefix + "Couldn't retrieve content: Response code was %d"
" (expected %d)" % (response.status_code, status_code))
if getattr(response, 'streaming', False):
content = b''.join(response.streaming_content)
else:
content = response.content
if not isinstance(text, bytes) or html:
text = force_text(text, encoding=response._charset)
content = content.decode(response._charset)
text_repr = "'%s'" % text
else:
text_repr = repr(text)
if html:
content = testcases.assert_and_parse_html(
self, content, None, 'Response\'s content is not valid HTML:')
text = testcases.assert_and_parse_html(
self, text, None, 'Second argument is not valid HTML:')
self.assertEqual(
content.count(text), 0,
msg_prefix + "Response should not contain %s" % text_repr)
@unittest.skipUnless(os.environ.get('WITH_SELENIUM', False), @unittest.skipUnless(os.environ.get('WITH_SELENIUM', False),
"The WITH_SELENIUM env variable is not set.") "The WITH_SELENIUM env variable is not set.")

View File

@ -79,11 +79,7 @@ class UsageTable(tables.DataTable):
# since these tables are dynamically created and named, we use title # since these tables are dynamically created and named, we use title
@property @property
def name(self): def name(self):
# slugify was introduced in Django 1.5 return text.slugify(six.text_type(self.title))
if hasattr(text, 'slugify'):
return text.slugify(six.text_type(self.title))
else:
return self.title
def __str__(self): def __str__(self):
return self.title return self.title

View File

@ -22,7 +22,6 @@ Views for managing Swift containers.
import os import os
import django
from django import http from django import http
from django.utils.functional import cached_property # noqa from django.utils.functional import cached_property # noqa
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -207,14 +206,7 @@ def object_download(request, container_name, object_path):
if not os.path.splitext(obj.name)[1] and obj.orig_name: if not os.path.splitext(obj.name)[1] and obj.orig_name:
name, ext = os.path.splitext(obj.orig_name) name, ext = os.path.splitext(obj.orig_name)
filename = "%s%s" % (filename, ext) filename = "%s%s" % (filename, ext)
# NOTE(tsufiev): StreamingHttpResponse class had been introduced in response = http.StreamingHttpResponse(obj.data)
# Django 1.5 specifically for the purpose streaming and/or transferring
# large files, it's less fragile than standard HttpResponse and should be
# used when available.
if django.VERSION >= (1, 5):
response = http.StreamingHttpResponse(obj.data)
else:
response = http.HttpResponse(obj.data)
safe_name = filename.replace(",", "").encode('utf-8') safe_name = filename.replace(",", "").encode('utf-8')
response['Content-Disposition'] = 'attachment; filename="%s"' % safe_name response['Content-Disposition'] = 'attachment; filename="%s"' % safe_name
response['Content-Type'] = 'application/octet-stream' response['Content-Type'] = 'application/octet-stream'

View File

@ -12,12 +12,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import django
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django import http from django import http
from django.utils.six.moves.urllib.parse import urlsplit # noqa from django.utils.six.moves.urllib.parse import urlsplit # noqa
from django.utils import unittest
from mox3.mox import IsA # noqa from mox3.mox import IsA # noqa
@ -54,9 +52,6 @@ class ChangePasswordTests(test.TestCase):
self.assertFormError(res, "form", None, ['Passwords do not match.']) self.assertFormError(res, "form", None, ['Passwords do not match.'])
@unittest.skipUnless(django.VERSION[0] >= 1 and django.VERSION[1] >= 6,
"'HttpResponseRedirect' object has no attribute "
"'url' prior to Django 1.6")
@test.create_stubs({api.keystone: ('user_update_own_password', )}) @test.create_stubs({api.keystone: ('user_update_own_password', )})
def test_change_password_sets_logout_reason(self): def test_change_password_sets_logout_reason(self):
api.keystone.user_update_own_password(IsA(http.HttpRequest), api.keystone.user_update_own_password(IsA(http.HttpRequest),

View File

@ -22,7 +22,6 @@ WEBROOT = '/'
# Do not set it to '/home/', as this will cause circular redirect loop # Do not set it to '/home/', as this will cause circular redirect loop
#LOGIN_REDIRECT_URL = WEBROOT #LOGIN_REDIRECT_URL = WEBROOT
# Required for Django 1.5.
# If horizon is running in production (DEBUG is False), set this # If horizon is running in production (DEBUG is False), set this
# with the list of host/domain names that the application can serve. # with the list of host/domain names that the application can serve.
# For more information see: # For more information see:
@ -30,12 +29,10 @@ WEBROOT = '/'
#ALLOWED_HOSTS = ['horizon.example.com', ] #ALLOWED_HOSTS = ['horizon.example.com', ]
# Set SSL proxy settings: # Set SSL proxy settings:
# For Django 1.4+ pass this header from the proxy after terminating the SSL, # Pass this header from the proxy after terminating the SSL,
# and don't forget to strip it from the client's request. # and don't forget to strip it from the client's request.
# For more information see: # For more information see:
# https://docs.djangoproject.com/en/1.4/ref/settings/#secure-proxy-ssl-header # https://docs.djangoproject.com/en/1.8/ref/settings/#secure-proxy-ssl-header
#SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
# https://docs.djangoproject.com/en/1.5/ref/settings/#secure-proxy-ssl-header
#SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') #SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# If Horizon is being served through SSL, then uncomment the following two # If Horizon is being served through SSL, then uncomment the following two