Move django-openstack-auth to openstack-build
[openstack-build/django_openstack_auth-build.git] / centos7 / rpm / SOURCES / 0005-Fix-Login-form-s-fields-sorting-for-Django-1.7.patch
1 From bef46730e7d245f6aa61c4d800d74a5ca616dad8 Mon Sep 17 00:00:00 2001
2 From: lin-hua-cheng <os.lcheng@gmail.com>
3 Date: Mon, 13 Jul 2015 17:39:34 -0700
4 Subject: [PATCH] Fix Login form's fields sorting for Django 1.7
5
6 Starting from Django 1.7 self.fields.keyOrder no longer works for
7 setting fields ordering, need to rearrange fields there by recreating
8 underlying OrderedDict.
9
10 Change-Id: Idd015f0fa59061af2afc3936d8c37b004118bb64
11 Closes-Bug: #1474157
12 (cherry picked from commit 9c8406cbbc6b768921510aa99c999af380ca4ef2)
13 ---
14  openstack_auth/forms.py | 17 +++++++++++++----
15  1 file changed, 13 insertions(+), 4 deletions(-)
16
17 diff --git a/openstack_auth/forms.py b/openstack_auth/forms.py
18 index 9b03569..3a92ed1 100644
19 --- a/openstack_auth/forms.py
20 +++ b/openstack_auth/forms.py
21 @@ -11,8 +11,10 @@
22  # See the License for the specific language governing permissions and
23  # limitations under the License.
24  
25 +import collections
26  import logging
27  
28 +import django
29  from django.conf import settings
30  from django.contrib.auth import authenticate  # noqa
31  from django.contrib.auth import forms as django_auth_forms
32 @@ -55,7 +57,7 @@ class Login(django_auth_forms.AuthenticationForm):
33  
34      def __init__(self, *args, **kwargs):
35          super(Login, self).__init__(*args, **kwargs)
36 -        self.fields.keyOrder = ['username', 'password', 'region']
37 +        fields_ordering = ['username', 'password', 'region']
38          if getattr(settings,
39                     'OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT',
40                     False):
41 @@ -64,7 +66,7 @@ class Login(django_auth_forms.AuthenticationForm):
42                  required=True,
43                  widget=forms.TextInput(attrs={"autofocus": "autofocus"}))
44              self.fields['username'].widget = forms.widgets.TextInput()
45 -            self.fields.keyOrder = ['domain', 'username', 'password', 'region']
46 +            fields_ordering = ['domain', 'username', 'password', 'region']
47          self.fields['region'].choices = self.get_region_choices()
48          if len(self.fields['region'].choices) == 1:
49              self.fields['region'].initial = self.fields['region'].choices[0][0]
50 @@ -83,14 +85,21 @@ class Login(django_auth_forms.AuthenticationForm):
51                  required=False,
52                  initial=initial)
53              # move auth_type to the top of the list
54 -            self.fields.keyOrder.pop(-1)
55 -            self.fields.keyOrder.insert(0, 'auth_type')
56 +            fields_ordering.pop(-1)
57 +            fields_ordering.insert(0, 'auth_type')
58  
59          # websso is enabled, but keystone version is not supported
60          elif getattr(settings, 'WEBSSO_ENABLED', False):
61              msg = ("Websso is enabled but horizon is not configured to work " +
62                     "with keystone version 3 or above.")
63              LOG.warning(msg)
64 +        # Starting from 1.7 Django uses OrderedDict for fields and keyOrder
65 +        # no longer works for it
66 +        if django.VERSION >= (1, 7):
67 +            self.fields = collections.OrderedDict(
68 +                (key, self.fields[key]) for key in fields_ordering)
69 +        else:
70 +            self.fields.keyOrder = fields_ordering
71  
72      @staticmethod
73      def get_region_choices():