Skip to content

Commit

Permalink
Adding FORM_GLOBAL_CSS_ATTRS, bump to 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer committed Apr 12, 2014
1 parent 94d2bfd commit e99f855
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
9 changes: 9 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ FORM_ERROR_CSS_CLASS
If specified, the given CSS class will be added to every field that is
in an error state on every gollum form.

FORM_GLOBAL_CSS_CLASS
---------------------

* Default: *(not set)*
* Type: ``str``

If specified, the given CSS class will be added to every field, period,
the end.

FORM_REQUIRED_ATTRS
-------------------

Expand Down
2 changes: 2 additions & 0 deletions gollum/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def css_classes(self, extra_classes=None):
answer.add(settings.FORM_REQUIRED_CSS_CLASS)
if self.errors and hasattr(settings, 'FORM_ERROR_CSS_CLASS'):
answer.add(settings.FORM_ERROR_CSS_CLASS)
if hasattr(settings, 'FORM_GLOBAL_CSS_CLASS'):
answer.add(settings.FORM_GLOBAL_CSS_CLASS)

# Return the final answer.
return ' '.join(answer)
12 changes: 12 additions & 0 deletions tests/test_bound_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def test_error_css_class(self):
assert not re.search(r'class="[\s\w-]*error[\s\w-]*"', foo_output)
assert re.search(r'class="[\s\w-]*error[\s\w-]*"', bar_output)

def test_global_css_class(self):
"""Establish that the `FORM_GLOBAL_CSS_CLASS` setting works
as intended.
"""
form = self.form_class({ 'foo': 'eggs', 'bar': 'baz' })
form.is_valid()
with override_settings(FORM_GLOBAL_CSS_CLASS='global'):
foo_output = six.text_type(form['foo'])
bar_output = six.text_type(form['bar'])
assert re.search(r'class="[\s\w-]*global[\s\w-]*"', foo_output)
assert re.search(r'class="[\s\w-]*global[\s\w-]*"', bar_output)

def test_css_from_widget_class(self):
"""Establish that a CSS class on a widget itself is included
in the BoundField output.
Expand Down

0 comments on commit e99f855

Please sign in to comment.