Changeset - c22bcf9cf464
[Not reviewed]
0 1 0
Hiroshi Miura - 9 years ago 2015-07-20 03:03:54
miurahr@linux.com
fix OrderedDict import error in Py2.6

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
1 file changed with 5 insertions and 3 deletions:
0 comments (0 inline, 0 general)
symposion/forms.py
Show inline comments
 
from collections import OrderedDict
 
try:
 
    from collections import OrderedDict
 
except ImportError:
 
    OrderedDict = None
 

	
 
from django import forms
 
from django import VERSION as django_VERSION
 

	
 
import account.forms
 

	
 

	
 
class SignupForm(account.forms.SignupForm):
 

	
 
    first_name = forms.CharField()
 
    last_name = forms.CharField()
 
    email_confirm = forms.EmailField(label="Confirm Email")
 

	
 
    def __init__(self, *args, **kwargs):
 
        super(SignupForm, self).__init__(*args, **kwargs)
...
 
@@ -37,19 +39,19 @@ class SignupForm(account.forms.SignupForm):
 
def reorder_fields(fields, order):
 
    """Reorder form fields by order, removing items not in order.
 

	
 
    >>> reorder_fields(
 
    ...     OrderedDict([('a', 1), ('b', 2), ('c', 3)]),
 
    ...     ['b', 'c', 'a'])
 
    OrderedDict([('b', 2), ('c', 3), ('a', 1)])
 
    """
 
    for key, v in fields.items():
 
        if key not in order:
 
            del fields[key]
 

	
 
    if django_VERSION < (1, 7, 0):
 
    if not OrderedDict or hasattr(fields, "keyOrder"):
 
        # fields is SortedDict
 
        fields.keyOrder.sort(key=lambda k: order.index(k[0]))
 
        return fields
 
    else:
 
        # fields is OrderedDict
 
        return OrderedDict(sorted(fields.items(), key=lambda k: order.index(k[0])))
0 comments (0 inline, 0 general)