Repository: django-crispy-forms/django-crispy-forms

Issue:
python 3.2 compatibility



Discussion:

Resolving patch:
diff --git a/crispy_forms/bootstrap.py b/crispy_forms/bootstrap.py
--- a/crispy_forms/bootstrap.py
+++ b/crispy_forms/bootstrap.py
@@ -1,3 +1,4 @@
+from __future__ import unicode_literals
 from random import randint
 
 from django.template import Template
diff --git a/crispy_forms/layout.py b/crispy_forms/layout.py
--- a/crispy_forms/layout.py
+++ b/crispy_forms/layout.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
 from django.template import Template
 from django.template.loader import render_to_string
 from django.utils.html import conditional_escape
@@ -282,7 +284,7 @@ def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwarg
 
         legend = ''
         if self.legend:
-            legend = u'%s' % Template(text_type(self.legend)).render(context)
+            legend = '%s' % Template(text_type(self.legend)).render(context)
 
         template = self.get_template_name(template_pack)
         return render_to_string(
@@ -299,8 +301,8 @@ class MultiField(LayoutObject):
     def __init__(self, label, *fields, **kwargs):
         self.fields = list(fields)
         self.label_html = label
-        self.label_class = kwargs.pop('label_class', u'blockLabel')
-        self.css_class = kwargs.pop('css_class', u'ctrlHolder')
+        self.label_class = kwargs.pop('label_class', 'blockLabel')
+        self.css_class = kwargs.pop('css_class', 'ctrlHolder')
         self.css_id = kwargs.pop('css_id', None)
         self.template = kwargs.pop('template', self.template)
         self.field_template = kwargs.pop('field_template', self.field_template)
diff --git a/crispy_forms/utils.py b/crispy_forms/utils.py
--- a/crispy_forms/utils.py
+++ b/crispy_forms/utils.py
@@ -1,4 +1,4 @@
-from __future__ import with_statement
+from __future__ import with_statement, unicode_literals
 import logging
 import sys
 
@@ -167,7 +167,7 @@ def flatatt(attrs):
     XML-style pairs.  It is assumed that the keys do not need to be XML-escaped.
     If the passed dictionary is empty, then return an empty string.
     """
-    return u''.join([u' %s="%s"' % (k.replace('_', '-'), conditional_escape(v)) for k, v in attrs.items()])
+    return ''.join([' %s="%s"' % (k.replace('_', '-'), conditional_escape(v)) for k, v in attrs.items()])
 
 
 def render_crispy_form(form, helper=None, context=None):


Test patch:
diff --git a/crispy_forms/tests/test_form_helper.py b/crispy_forms/tests/test_form_helper.py
--- a/crispy_forms/tests/test_form_helper.py
+++ b/crispy_forms/tests/test_form_helper.py
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+from __future__ import unicode_literals
 import re
 
 import django
@@ -43,7 +44,7 @@ def test_inputs(settings):
     form_helper.add_input(Hidden('my-hidden', 'Hidden'))
     form_helper.add_input(Button('my-button', 'Button'))
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
@@ -81,7 +82,7 @@ def test_form_with_helper_without_layout(settings):
     form_helper.form_action = 'simpleAction'
     form_helper.form_error_title = 'ERRORS'
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy testForm form_helper %}
     """)
@@ -121,7 +122,7 @@ def test_form_show_errors_non_field_errors():
     form.helper.form_show_errors = True
     form.is_valid()
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy testForm %}
     """)
@@ -214,7 +215,7 @@ def test_template_helper_access():
 
 
 def test_without_helper(settings):
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form %}
     """)
@@ -234,7 +235,7 @@ def test_template_pack_override_compact(settings):
     override_pack = current_pack == 'uni_form' and 'bootstrap' or 'uni_form'
 
     # {% crispy form 'template_pack_name' %}
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {%% load crispy_forms_tags %%}
         {%% crispy form "%s" %%}
     """ % override_pack)
@@ -252,7 +253,7 @@ def test_template_pack_override_verbose(settings):
     override_pack = current_pack == 'uni_form' and 'bootstrap' or 'uni_form'
 
     # {% crispy form helper 'template_pack_name' %}
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {%% load crispy_forms_tags %%}
         {%% crispy form form_helper "%s" %%}
     """ % override_pack)
@@ -267,14 +268,14 @@ def test_template_pack_override_verbose(settings):
 
 def test_template_pack_override_wrong():
     with pytest.raises(TemplateSyntaxError):
-        get_template_from_string(u"""
+        get_template_from_string("""
             {% load crispy_forms_tags %}
             {% crispy form 'foo' %}
         """)
 
 
 def test_invalid_helper(settings):
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
@@ -286,7 +287,7 @@ def test_invalid_helper(settings):
 
 
 def test_formset_with_helper_without_layout(settings):
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy testFormSet formset_helper %}
     """)
@@ -321,7 +322,7 @@ def test_formset_with_helper_without_layout(settings):
 
 def test_CSRF_token_POST_form():
     form_helper = FormHelper()
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
@@ -338,7 +339,7 @@ def test_CSRF_token_POST_form():
 def test_CSRF_token_GET_form():
     form_helper = FormHelper()
     form_helper.form_method = 'GET'
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
diff --git a/crispy_forms/tests/test_layout.py b/crispy_forms/tests/test_layout.py
--- a/crispy_forms/tests/test_layout.py
+++ b/crispy_forms/tests/test_layout.py
@@ -1,4 +1,6 @@
 # -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
 import django
 from django import forms
 from django.core.urlresolvers import reverse
@@ -44,7 +46,7 @@ def test_invalid_unicode_characters(settings):
         )
     )
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
@@ -61,7 +63,7 @@ def __init__(self, *args, **kwargs):
             self.fields['contraseña'] = forms.CharField()
 
         helper = FormHelper()
-        helper.layout = Layout(u'contraseña')
+        helper.layout = Layout('contraseña')
 
     if PY2:
         with pytest.raises(Exception):
@@ -85,7 +87,7 @@ class Meta:
         'first_name',
     )
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
@@ -102,7 +104,7 @@ def test_layout_unresolved_field(settings):
         )
     )
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
@@ -121,7 +123,7 @@ def test_double_rendered_field(settings):
         )
     )
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
@@ -138,7 +140,7 @@ class ExampleForm(forms.Form):
     form = ExampleForm()
     form2 = TestForm()
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {{ form.as_ul }}
         {% crispy form2 %}
@@ -156,33 +158,33 @@ def test_layout_fieldset_row_html_with_unicode_fieldnames(settings):
     form_helper.add_layout(
         Layout(
             Fieldset(
-                u'Company Data',
-                u'is_company',
+                'Company Data',
+                'is_company',
                 css_id = "fieldset_company_data",
                 css_class = "fieldsets",
                 title = "fieldset_title",
                 test_fieldset = "123"
             ),
             Fieldset(
-                u'User Data',
-                u'email',
+                'User Data',
+                'email',
                 Row(
-                    u'password1',
-                    u'password2',
+                    'password1',
+                    'password2',
                     css_id = "row_passwords",
                     css_class = "rows",
                 ),
                 HTML('<a href="#" id="testLink">test link</a>'),
-                HTML(u"""
+                HTML("""
                     {% if flag %}{{ message }}{% endif %}
                 """),
-                u'first_name',
-                u'last_name',
+                'first_name',
+                'last_name',
             )
         )
     )
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
@@ -210,7 +212,7 @@ def test_layout_fieldset_row_html_with_unicode_fieldnames(settings):
 
 
 def test_change_layout_dynamically_delete_field():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form_helper %}
     """)
@@ -220,7 +222,7 @@ def test_change_layout_dynamically_delete_field():
     form_helper.add_layout(
         Layout(
             Fieldset(
-                u'Company Data',
+                'Company Data',
                 'is_company',
                 'email',
                 'password1',
@@ -360,7 +362,7 @@ def test_modelformset_layout():
 
 
 def test_i18n():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form form.helper %}
     """)
@@ -465,7 +467,7 @@ def test_layout_composition():
         )
     )
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
             {% load crispy_forms_tags %}
             {% crispy form form_helper %}
         """)
@@ -517,7 +519,7 @@ def test_second_layout_multifield_column_buttonholder_submit_div():
         )
     )
 
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
             {% load crispy_forms_tags %}
             {% crispy form form_helper %}
         """)
diff --git a/crispy_forms/tests/test_layout_objects.py b/crispy_forms/tests/test_layout_objects.py
--- a/crispy_forms/tests/test_layout_objects.py
+++ b/crispy_forms/tests/test_layout_objects.py
@@ -1,4 +1,6 @@
 # -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
 from django import forms
 from django.template import Context
 
@@ -26,7 +28,7 @@
 from crispy_forms.utils import render_crispy_form
 
 def test_field_with_custom_template():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form %}
     """)
@@ -41,7 +43,7 @@ def test_field_with_custom_template():
     assert '<h1>Special custom field</h1>' in html
 
 def test_multiwidget_field():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy form %}
     """)
@@ -70,7 +72,7 @@ def test_multiwidget_field():
 
 
 def test_field_type_hidden():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {% crispy test_form %}
     """)
@@ -136,7 +138,7 @@ def test_i18n():
         HTML(_("Enter a valid value."))
     )
     html = render_crispy_form(form)
-    assert u"Introduzca un valor correcto" in html
+    assert "Introduzca un valor correcto" in html
     deactivate()
 
 
diff --git a/crispy_forms/tests/test_tags.py b/crispy_forms/tests/test_tags.py
--- a/crispy_forms/tests/test_tags.py
+++ b/crispy_forms/tests/test_tags.py
@@ -1,4 +1,6 @@
 # -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
 from django.forms.forms import BoundField
 from django.forms.models import formset_factory
 from django.template import Context
@@ -19,7 +21,7 @@
 
 
 def test_as_crispy_errors_form_without_non_field_errors():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {{ form|as_crispy_errors }}
     """)
@@ -32,7 +34,7 @@ def test_as_crispy_errors_form_without_non_field_errors():
 
 
 def test_as_crispy_errors_form_with_non_field_errors():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {{ form|as_crispy_errors }}
     """)
@@ -47,7 +49,7 @@ def test_as_crispy_errors_form_with_non_field_errors():
 
 
 def test_crispy_filter_with_form():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {{ form|crispy }}
     """)
@@ -60,7 +62,7 @@ def test_crispy_filter_with_form():
 
 
 def test_crispy_filter_with_formset():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_tags %}
         {{ testFormset|crispy }}
     """)
@@ -79,7 +81,7 @@ def test_crispy_filter_with_formset():
 
 
 def test_classes_filter():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_field %}
         {{ testField|classes }}
     """)
@@ -92,7 +94,7 @@ def test_classes_filter():
 
 
 def test_crispy_field_and_class_converters():
-    template = get_template_from_string(u"""
+    template = get_template_from_string("""
         {% load crispy_forms_field %}
         {% crispy_field testField 'class' 'error' %}
     """)