Add support for Django 1.10

Registered by Rob Cresswell

https://www.djangoproject.com/download/#supported-versions

Django 1.10 will be released during the N cycle, and Django 1.9 will end mainstream support.

Matching Django OpenStack Auth blueprint: https://blueprints.launchpad.net/django-openstack-auth/+spec/dj110

Blueprint information

Status:
Complete
Approver:
David Lyle
Priority:
High
Drafter:
Rob Cresswell
Direction:
Approved
Assignee:
None
Definition:
Approved
Series goal:
Accepted for 10.0.0-newton
Implementation:
Implemented
Milestone target:
milestone icon newton-rc1
Started by
David Lyle
Completed by
Rob Cresswell

Related branches

Sprints

Whiteboard

Gerrit topic: https://review.openstack.org/#q,topic:bp/dj110,n,z

Addressed by: https://review.openstack.org/280901
    Update URLs to Django 1.8+ style

Addressed by: https://review.openstack.org/298411
    Add default value for get_form() form_class arg

Gerrit topic: https://review.openstack.org/#q,topic:bp/django-1,n,z

Addressed by: https://review.openstack.org/335397
    Add Django 1.10 tox env

Addressed by: https://review.openstack.org/335433
    [Django 1.10] Remove old style URLS

Notes from zigo:
==========

Debian bug related about (build) dependency packages:
----------
   https://bugs.debian.org/828662 (has patch from upstream)
   https://bugs.debian.org/828667 Latest upstream commit fixes the issue
   https://bugs.debian.org/828670 patch under review: https://review.openstack.org/#/c/344076/
   https://bugs.debian.org/828671 https://github.com/fusionbox/django-pyscss/pull/43/commits/ddda505c6a05080ffc9f631e0cede5cbb6a032c2

All of them have been addressed, plus I'm waiting for the approval to upload a new version of django-nose:

Dango 1.10 means we need django-nose 1.4.4:
    https://review.openstack.org/344195

Horizon uses removed django.conf.urls.patterns() in 2 places
----------
   This breaks sahara-dashboard and others if Django >= .10.
   https://review.openstack.org/#/c/344678/

Django 1.10 get_form switches to kwargs:
----------
This breaks 3 unit tests in horizon, and a lot more in openstack_dashboard. Here are the ones for Horizon:
horizon.test.tests.forms.FormMixinTests.test_modal_form_mixin_add_to_field_header_not_set
horizon.test.tests.forms.FormMixinTests.test_modal_form_mixin_add_to_field_header_set
horizon.test.tests.forms.FormMixinTests.test_modal_form_mixin_hide_true_if_ajax

Proposed patch: https://review.openstack.org/#/c/344931/

Defining TEMPLATES =
----------
In Django 1.10, we have to define something like this in horizon/test/settings.py:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [ os.path.join( os.path.dirname(os.path.abspath(__file__)), 'tests', 'templates'), ],
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.request',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.contrib.messages.context_processors.messages',
                'horizon.context_processors.horizon'
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
                'horizon.loaders.TemplateLoader'
            ],
        },
    },
]

otherwise, there's 60-ish unit test errors Horizon, and a way more in openstack_dashboard. However, if we do set this, we still have 4 errors remaining, pages returning 200 instead of 302. Also, under Django 1.9, we then get 2 new issues in horizon.test.tests.base:CustomPermissionsTests.test_customized_permissions as well as horizon.test.tests.base:HorizonTests.test_required_permissions with errors "Found 0 instances of 'Login as different user' in response (expected 1)".

In Django 1.10, after fixing settings.py (ie: add a TEMPLATES thing), we have errors:
horizon.test.tests.base.CustomPermissionsTests.test_customized_permissions
horizon.test.tests.base.HorizonTests.test_public
horizon.test.tests.base.HorizonTests.test_required_permissions
horizon.test.tests.base.HorizonTests.test_ssl_redirect_by_proxy

I'm not sure how to fix settings.py then. :/

In openstack_dashboard/test/settings.py. something like this should be done:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(TEST_DIR, 'templates'), ],
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.request',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.contrib.messages.context_processors.messages',
                'horizon.context_processors.horizon',
                'openstack_dashboard.context_processors.openstack',
            ],
            'loaders': [
                'horizon.themes.ThemeTemplateLoader',
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
                'django.template.loaders.cached.Loader',
                'horizon.loaders.TemplateLoader',
            ],
        },
    },
]

note the django.template instead of django.core. This shall also be fixed in other places in the config file.

django.conf.urls.url wrong call
----------
This patch seems to help, though I'm really not sure what I'm doing here, so I would need a real Django dev to look at the issue and eventually approve the patch. Note that it doesn't break Django 1.9 (all unit tests are passing), and seem to solve some Django 1.10 problems:

https://review.openstack.org/345259

==========

that's all the issues I had in the horizon folder. Now, the openstack_dashboard notes.

Addressed by: https://review.openstack.org/345998
    Use argparse instead of optparse

Addressed by: https://review.openstack.org/351381
    Update Django 1.10 tox env

Addressed by: https://review.openstack.org/357829
    Update TEMPLATES setting for Django 1.10

Gerrit topic: https://review.openstack.org/#q,topic:bp/dj110-security,n,z

Addressed by: https://review.openstack.org/357879
    Support is_authenticated() and is_anonymous() 1.10

Addressed by: https://review.openstack.org/373935
    Fix compatibility issues with Django 1.10

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.