Permalink
Browse files

Rename template tag library from form_utils_tags to form_utils.

--HG--
rename : form_utils/templatetags/form_utils_tags.py => form_utils/templatetags/form_utils.py
  • Loading branch information...
carljm committed Aug 30, 2012
1 parent abe3965 commit af59df1796ea40fee81a29e7e45e348a3dcdce9e
Showing with 30 additions and 25 deletions.
  1. +5 −2 CHANGES.rst
  2. +2 −0 README.rst
  3. +2 −2 form_utils/templatetags/{form_utils_tags.py → form_utils.py}
  4. +21 −21 tests/tests.py
View
@@ -4,8 +4,11 @@ CHANGES
tip (unreleased)
----------------
-- Removed ``FORM_UTILS_MEDIA_URL`` setting and updated to use ``STATIC_URL``
- rather than ``MEDIA_URL`` throughout. (May be backwards-incompatible.)
+- BACKWARDS-INCOMPATIBLE: Renamed template tag library from ``form_utils_tags``
+ to ``form_utils``.
+
+- BACKWARDS-INCOMPATIBLE: Removed ``FORM_UTILS_MEDIA_URL`` setting and updated
+ to use ``STATIC_URL`` rather than ``MEDIA_URL`` throughout.
- Added "error" class to row_attrs for fields with errors. Thanks Aron
Griffis.
View
@@ -190,6 +190,8 @@ done, e.g.::
``django-form-utils`` also provides a convenience template filter,
``render``. It is used like this::
+ {% load form_utils %}
+
{{ form|render }}
By default, it will check whether the form is a ``BetterForm``, and if
@@ -1,9 +1,9 @@
"""
templatetags for django-form-utils
-Time-stamp: <2009-03-26 12:32:08 carljm form_utils_tags.py>
-
"""
+from __future__ import absolute_import
+
from django import forms
from django import template
from django.template.loader import render_to_string
View
@@ -409,7 +409,7 @@ def test_render_form(self):
"""
form = BoringForm()
- tpl = template.Template('{% load form_utils_tags %}{{ form|render }}')
+ tpl = template.Template('{% load form_utils %}{{ form|render }}')
html = tpl.render(template.Context({'form': form}))
self.assertEqual([l.strip() for l in html.splitlines() if l.strip()],
self.boring_form_html)
@@ -444,7 +444,7 @@ def test_render_betterform(self):
"""
form = ApplicationForm()
- tpl = template.Template('{% load form_utils_tags %}{{ form|render }}')
+ tpl = template.Template('{% load form_utils %}{{ form|render }}')
html = tpl.render(template.Context({'form': form}))
self.assertEqual([l.strip() for l in html.splitlines() if l.strip()],
self.betterform_html)
@@ -670,10 +670,10 @@ class ClearableImageWidgetField(ClearableFileField):
class FieldFilterTests(TestCase):
"""Tests for form field filters."""
@property
- def form_utils_tags(self):
+ def form_utils(self):
"""The module under test."""
- from form_utils.templatetags import form_utils_tags
- return form_utils_tags
+ from form_utils.templatetags import form_utils
+ return form_utils
@property
@@ -691,17 +691,17 @@ class PersonForm(forms.Form):
def test_placeholder(self):
"""``placeholder`` filter sets placeholder attribute."""
- bf = self.form_utils_tags.placeholder(self.form()["name"], "Placeholder")
+ bf = self.form_utils.placeholder(self.form()["name"], "Placeholder")
self.assertIn('placeholder="Placeholder"', unicode(bf))
- @patch("form_utils.templatetags.form_utils_tags.render_to_string")
+ @patch("form_utils.templatetags.form_utils.render_to_string")
def test_label(self, render_to_string):
"""``label`` filter renders field label from template."""
render_to_string.return_value = "<label>something</label>"
bf = self.form()["name"]
- label = self.form_utils_tags.label(bf)
+ label = self.form_utils.label(bf)
self.assertEqual(label, "<label>something</label>")
render_to_string.assert_called_with(
@@ -714,12 +714,12 @@ def test_label(self, render_to_string):
)
- @patch("form_utils.templatetags.form_utils_tags.render_to_string")
+ @patch("form_utils.templatetags.form_utils.render_to_string")
def test_label_override(self, render_to_string):
"""label filter allows overriding the label text."""
bf = self.form()["name"]
- self.form_utils_tags.label(bf, "override")
+ self.form_utils.label(bf, "override")
render_to_string.assert_called_with(
"forms/_label.html",
@@ -732,24 +732,24 @@ def test_label_override(self, render_to_string):
def test_label_text(self):
"""``label_text`` filter returns field's default label text."""
- self.assertEqual(self.form_utils_tags.label_text(self.form()["name"]), "Name")
+ self.assertEqual(self.form_utils.label_text(self.form()["name"]), "Name")
def test_value_text(self):
"""``value_text`` filter returns value of field."""
self.assertEqual(
- self.form_utils_tags.value_text(self.form({"name": "boo"})["name"]), "boo")
+ self.form_utils.value_text(self.form({"name": "boo"})["name"]), "boo")
def test_value_text_unbound(self):
"""``value_text`` filter returns default value of unbound field."""
- self.assertEqual(self.form_utils_tags.value_text(self.form()["name"]), "none")
+ self.assertEqual(self.form_utils.value_text(self.form()["name"]), "none")
def test_value_text_choices(self):
"""``value_text`` filter returns human-readable value of choicefield."""
self.assertEqual(
- self.form_utils_tags.value_text(
+ self.form_utils.value_text(
self.form({"level": "a"})["level"]), "Advanced")
@@ -758,43 +758,43 @@ def test_values_text_choices(self):
f = self.form({"level": ["a", "b"]})
self.assertEqual(
- self.form_utils_tags.values_text(f["level"]), ["Advanced", "Beginner"])
+ self.form_utils.values_text(f["level"]), ["Advanced", "Beginner"])
def test_optional_false(self):
"""A required field should not be marked optional."""
- self.assertFalse(self.form_utils_tags.optional(self.form()["name"]))
+ self.assertFalse(self.form_utils.optional(self.form()["name"]))
def test_optional_true(self):
"""A non-required field should be marked optional."""
- self.assertTrue(self.form_utils_tags.optional(self.form()["level"]))
+ self.assertTrue(self.form_utils.optional(self.form()["level"]))
def test_detect_checkbox(self):
"""``is_checkbox`` detects checkboxes."""
f = self.form()
- self.assertTrue(self.form_utils_tags.is_checkbox(f["awesome"]))
+ self.assertTrue(self.form_utils.is_checkbox(f["awesome"]))
def test_detect_non_checkbox(self):
"""``is_checkbox`` detects that select fields are not checkboxes."""
f = self.form()
- self.assertFalse(self.form_utils_tags.is_checkbox(f["level"]))
+ self.assertFalse(self.form_utils.is_checkbox(f["level"]))
def test_is_multiple(self):
"""`is_multiple` detects a SelectMultiple widget."""
f = self.form()
f.fields["level"].widget = forms.SelectMultiple()
- self.assertTrue(self.form_utils_tags.is_multiple(f["level"]))
+ self.assertTrue(self.form_utils.is_multiple(f["level"]))
def test_is_not_multiple(self):
"""`is_multiple` detects a non-multiple widget."""
f = self.form()
- self.assertFalse(self.form_utils_tags.is_multiple(f["level"]))
+ self.assertFalse(self.form_utils.is_multiple(f["level"]))

0 comments on commit af59df1

Please sign in to comment.