Skip to content

Commit

Permalink
Remove Python 2.5 shims, unused files, imports, PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Dygalo committed Aug 21, 2015
1 parent f1dc47c commit 145fd2b
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 125 deletions.
42 changes: 20 additions & 22 deletions crispy_forms/helper.py
Expand Up @@ -215,65 +215,63 @@ def __init__(self, form=None):
def build_default_layout(self, form):
return Layout(*form.fields.keys())

def get_form_method(self):
@property
def form_method(self):
return self._form_method

def set_form_method(self, method):
@form_method.setter
def form_method(self, method):
if method.lower() not in ('get', 'post'):
raise FormHelpersException('Only GET and POST are valid in the \
form_method helper attribute')

self._form_method = method.lower()

# we set properties the old way because we want to support pre-2.6 python
form_method = property(get_form_method, set_form_method)

def get_form_action(self):
@property
def form_action(self):
try:
return reverse(self._form_action)
except NoReverseMatch:
return self._form_action

def set_form_action(self, action):
@form_action.setter
def form_action(self, action):
self._form_action = action

# we set properties the old way because we want to support pre-2.6 python
form_action = property(get_form_action, set_form_action)

def get_form_style(self):
@property
def form_style(self):
if self._form_style == "default":
return ''

if self._form_style == "inline":
return 'inlineLabels'

def set_form_style(self, style):
@form_style.setter
def form_style(self, style):
if style.lower() not in ('default', 'inline'):
raise FormHelpersException('Only default and inline are valid in the \
form_style helper attribute')

self._form_style = style.lower()

form_style = property(get_form_style, set_form_style)

def get_help_text_inline(self):
@property
def help_text_inline(self):
return self._help_text_inline

def set_help_text_inline(self, flag):
@help_text_inline.setter
def help_text_inline(self, flag):
self._help_text_inline = flag
self._error_text_inline = not flag

help_text_inline = property(get_help_text_inline, set_help_text_inline)

def get_error_text_inline(self):
@property
def error_text_inline(self):
return self._error_text_inline

def set_error_text_inline(self, flag):
@error_text_inline.setter
def error_text_inline(self, flag):
self._error_text_inline = flag
self._help_text_inline = not flag

error_text_inline = property(get_error_text_inline, set_error_text_inline)

def add_input(self, input_object):
self.inputs.append(input_object)

Expand Down
2 changes: 2 additions & 0 deletions crispy_forms/layout.py
Expand Up @@ -7,6 +7,7 @@
from crispy_forms.compatibility import string_types, text_type
from crispy_forms.utils import render_field, flatatt, TEMPLATE_PACK, get_template_pack


class TemplateNameMixin(object):

def get_template_name(self, template_pack):
Expand All @@ -17,6 +18,7 @@ def get_template_name(self, template_pack):

return template


class LayoutObject(TemplateNameMixin):
def __getitem__(self, slice):
return self.fields[slice]
Expand Down
49 changes: 0 additions & 49 deletions crispy_forms/templates/bootstrap3/field.html.bk

This file was deleted.

28 changes: 14 additions & 14 deletions crispy_forms/tests/forms.py
Expand Up @@ -32,42 +32,42 @@ def __init__(self, *args, **kwargs):

class CheckboxesTestForm(forms.Form):
checkboxes = forms.MultipleChoiceField(
choices = (
choices=(
(1, "Option one"),
(2, "Option two"),
(3, "Option three")
),
initial = (1,),
widget = forms.CheckboxSelectMultiple,
initial=(1,),
widget=forms.CheckboxSelectMultiple,
)

alphacheckboxes = forms.MultipleChoiceField(
choices = (
choices=(
('option_one', "Option one"),
('option_two', "Option two"),
('option_three', "Option three")
),
initial = ('option_two', 'option_three'),
widget = forms.CheckboxSelectMultiple,
initial=('option_two', 'option_three'),
widget=forms.CheckboxSelectMultiple,
)

numeric_multiple_checkboxes = forms.MultipleChoiceField(
choices = (
choices=(
(1, "Option one"),
(2, "Option two"),
(3, "Option three")
),
initial = (1, 2),
widget = forms.CheckboxSelectMultiple,
initial=(1, 2),
widget=forms.CheckboxSelectMultiple,
)

inline_radios = forms.ChoiceField(
choices = (
choices=(
('option_one', "Option one"),
('option_two', "Option two"),
),
widget = forms.RadioSelect,
initial = 'option_two',
widget=forms.RadioSelect,
initial='option_two',
)


Expand All @@ -89,12 +89,12 @@ def __init__(self, *args, **kwargs):

class TestForm4(forms.ModelForm):
class Meta:
'''
"""
before Django1.6, one cannot use __all__ shortcut for fields
without getting the following error:
django.core.exceptions.FieldError: Unknown field(s) (a, l, _) specified for CrispyTestModel
because obviously it casts the string to a set
'''
"""
model = CrispyTestModel
if django.VERSION >= (1, 6):
fields = '__all__' # eliminate RemovedInDjango18Warning
Expand Down
18 changes: 9 additions & 9 deletions crispy_forms/tests/test_form_helper.py
Expand Up @@ -82,7 +82,7 @@ def test_form_with_helper_without_layout(settings):
""")

# now we render it, with errors
form = TestForm({'password1': 'wargame','password2': 'god'})
form = TestForm({'password1': 'wargame', 'password2': 'god'})
form.is_valid()
c = Context({'testForm': form, 'form_helper': form_helper})
html = template.render(c)
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_formset_with_helper_without_layout(settings):
form_helper.form_method = 'POST'
form_helper.form_action = 'simpleAction'

TestFormSet = formset_factory(TestForm, extra = 3)
TestFormSet = formset_factory(TestForm, extra=3)
testFormSet = TestFormSet()

c = Context({'testFormSet': testFormSet, 'formset_helper': form_helper, 'csrf_token': _get_new_csrf_key()})
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_multifield_errors():
'email': 'invalidemail',
'password1': 'yes',
'password2': 'yes',
})
})
form.helper = FormHelper()
form.helper.layout = Layout(
MultiField('legend', 'email')
Expand All @@ -470,12 +470,12 @@ def test_multifield_errors():
@only_bootstrap
def test_bootstrap_form_show_errors():
form = TestForm({
'email': 'invalidemail',
'first_name': 'first_name_too_long',
'last_name': 'last_name_too_long',
'password1': 'yes',
'password2': 'yes',
})
'email': 'invalidemail',
'first_name': 'first_name_too_long',
'last_name': 'last_name_too_long',
'password1': 'yes',
'password2': 'yes',
})
form.helper = FormHelper()
form.helper.layout = Layout(
AppendedText('email', 'whatever'),
Expand Down
44 changes: 24 additions & 20 deletions crispy_forms/tests/test_layout.py
Expand Up @@ -154,19 +154,19 @@ def test_layout_fieldset_row_html_with_unicode_fieldnames(settings):
Fieldset(
'Company Data',
'is_company',
css_id = "fieldset_company_data",
css_class = "fieldsets",
title = "fieldset_title",
test_fieldset = "123"
css_id="fieldset_company_data",
css_class="fieldsets",
title="fieldset_title",
test_fieldset="123"
),
Fieldset(
'User Data',
'email',
Row(
'password1',
'password2',
css_id = "row_passwords",
css_class = "rows",
css_id="row_passwords",
css_class="rows",
),
HTML('<a href="#" id="testLink">test link</a>'),
HTML("""
Expand Down Expand Up @@ -221,12 +221,12 @@ def test_change_layout_dynamically_delete_field():
'email',
'password1',
'password2',
css_id = "multifield_info",
css_id="multifield_info",
),
Column(
'first_name',
'last_name',
css_id = "column_name",
css_id="column_name",
)
)
)
Expand All @@ -250,13 +250,15 @@ def test_formset_layout(settings):
helper.form_method = 'POST'
helper.form_action = 'simpleAction'
helper.layout = Layout(
Fieldset("Item {{ forloop.counter }}",
Fieldset(
"Item {{ forloop.counter }}",
'is_company',
'email',
),
HTML("{% if forloop.first %}Note for first form only{% endif %}"),
Row('password1', 'password2'),
Fieldset("",
Fieldset(
"",
'first_name',
'last_name'
)
Expand Down Expand Up @@ -437,17 +439,18 @@ def test_layout_composition():
form_helper.add_layout(
Layout(
Layout(
MultiField("Some company data",
MultiField(
"Some company data",
'is_company',
'email',
css_id = "multifield_info",
css_id="multifield_info",
),
),
Column(
'first_name',
# 'last_name', Missing a field on purpose
css_id = "column_name",
css_class = "columns",
css_id="column_name",
css_class="columns",
),
ButtonHolder(
Submit('Save', 'Save', css_class='button white'),
Expand Down Expand Up @@ -486,18 +489,19 @@ def test_second_layout_multifield_column_buttonholder_submit_div():
form_helper = FormHelper()
form_helper.add_layout(
Layout(
MultiField("Some company data",
MultiField(
"Some company data",
'is_company',
'email',
css_id = "multifield_info",
title = "multifield_title",
multifield_test = "123"
css_id="multifield_info",
title="multifield_title",
multifield_test="123"
),
Column(
'first_name',
'last_name',
css_id = "column_name",
css_class = "columns",
css_id="column_name",
css_class="columns",
),
ButtonHolder(
Submit('Save the world', '{{ value_var }}', css_class='button white', data_id='test', data_name='test'),
Expand Down

0 comments on commit 145fd2b

Please sign in to comment.