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:
parent
13ff6392f9
commit
89ce71c4e9
@ -33,6 +33,7 @@ from django.conf.urls import url
|
||||
from django.core.exceptions import ImproperlyConfigured # noqa
|
||||
from django.core.urlresolvers import reverse
|
||||
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.importlib import import_module # noqa
|
||||
from django.utils.module_loading import module_has_submodule # noqa
|
||||
@ -651,12 +652,6 @@ class Dashboard(Registry, HorizonComponent):
|
||||
class Workflow(object):
|
||||
pass
|
||||
|
||||
try:
|
||||
from django.utils.functional import empty # noqa
|
||||
except ImportError:
|
||||
# Django 1.3 fallback
|
||||
empty = None
|
||||
|
||||
|
||||
class LazyURLPattern(SimpleLazyObject):
|
||||
def __iter__(self):
|
||||
|
@ -16,7 +16,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import django
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
@ -32,16 +31,12 @@ from django.core.handlers import wsgi
|
||||
from django import http
|
||||
from django import test as django_test
|
||||
from django.test.client import RequestFactory # noqa
|
||||
from django.test import testcases
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils import unittest
|
||||
import six
|
||||
|
||||
if django.VERSION < (1, 7):
|
||||
from django.test import LiveServerTestCase # noqa
|
||||
else:
|
||||
from django.contrib.staticfiles.testing \
|
||||
import StaticLiveServerTestCase as LiveServerTestCase # noqa
|
||||
from django.contrib.staticfiles.testing \
|
||||
import StaticLiveServerTestCase as LiveServerTestCase
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -225,60 +220,6 @@ class TestCase(django_test.TestCase):
|
||||
"%s messages not as expected: %s" % (msg_type.title(),
|
||||
", ".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),
|
||||
"The WITH_SELENIUM env variable is not set.")
|
||||
|
@ -79,11 +79,7 @@ class UsageTable(tables.DataTable):
|
||||
# since these tables are dynamically created and named, we use title
|
||||
@property
|
||||
def name(self):
|
||||
# slugify was introduced in Django 1.5
|
||||
if hasattr(text, 'slugify'):
|
||||
return text.slugify(six.text_type(self.title))
|
||||
else:
|
||||
return self.title
|
||||
return text.slugify(six.text_type(self.title))
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
@ -22,7 +22,6 @@ Views for managing Swift containers.
|
||||
|
||||
import os
|
||||
|
||||
import django
|
||||
from django import http
|
||||
from django.utils.functional import cached_property # noqa
|
||||
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:
|
||||
name, ext = os.path.splitext(obj.orig_name)
|
||||
filename = "%s%s" % (filename, ext)
|
||||
# NOTE(tsufiev): StreamingHttpResponse class had been introduced in
|
||||
# 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)
|
||||
response = http.StreamingHttpResponse(obj.data)
|
||||
safe_name = filename.replace(",", "").encode('utf-8')
|
||||
response['Content-Disposition'] = 'attachment; filename="%s"' % safe_name
|
||||
response['Content-Type'] = 'application/octet-stream'
|
||||
|
@ -12,12 +12,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import django
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django import http
|
||||
from django.utils.six.moves.urllib.parse import urlsplit # noqa
|
||||
from django.utils import unittest
|
||||
|
||||
from mox3.mox import IsA # noqa
|
||||
|
||||
@ -54,9 +52,6 @@ class ChangePasswordTests(test.TestCase):
|
||||
|
||||
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', )})
|
||||
def test_change_password_sets_logout_reason(self):
|
||||
api.keystone.user_update_own_password(IsA(http.HttpRequest),
|
||||
|
@ -22,7 +22,6 @@ WEBROOT = '/'
|
||||
# Do not set it to '/home/', as this will cause circular redirect loop
|
||||
#LOGIN_REDIRECT_URL = WEBROOT
|
||||
|
||||
# Required for Django 1.5.
|
||||
# If horizon is running in production (DEBUG is False), set this
|
||||
# with the list of host/domain names that the application can serve.
|
||||
# For more information see:
|
||||
@ -30,12 +29,10 @@ WEBROOT = '/'
|
||||
#ALLOWED_HOSTS = ['horizon.example.com', ]
|
||||
|
||||
# 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.
|
||||
# For more information see:
|
||||
# https://docs.djangoproject.com/en/1.4/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
|
||||
# https://docs.djangoproject.com/en/1.8/ref/settings/#secure-proxy-ssl-header
|
||||
#SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||
|
||||
# If Horizon is being served through SSL, then uncomment the following two
|
||||
|
Loading…
Reference in New Issue
Block a user