diff --git a/CHANGES.md b/CHANGES.md index c050e3e..12f7cee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,8 @@ # Tango Shared Core Change Log + +### 0.14.0 +* Removed humanized_simple_join tag, improved humanized_join, and polished tests. + ### 0.13.0 * Removed internal xmltramp copy in favor of xmltramp2. diff --git a/setup.py b/setup.py index 84bd395..6ad0504 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='tango-shared-core', - version='0.13.0', + version='0.14.0', author=u'Tim Baxter', author_email='mail.baxter@gmail.com', description='Tango shared/core functionality.', diff --git a/tango_shared/templatetags/formatting.py b/tango_shared/templatetags/formatting.py index 7ad2073..c6af8ac 100644 --- a/tango_shared/templatetags/formatting.py +++ b/tango_shared/templatetags/formatting.py @@ -31,34 +31,6 @@ def fixbreaks(value): return value.replace('\n', ' \n') -@register.filter -def humanized_simple_join(value): - """ - Given a list of strings, format them with commas and spaces, - but with 'and' at the end. - - Unlike humanize_join, this does not wrap each object in a link. - - >>> humanized_simple_join(['apples', 'oranges', 'pears']) - "apples, oranges, and pears" - - In a template, if mylist = ['apples', 'oranges', 'pears'] - then {{ mylist|humanized_simple_join }} - will output "apples, oranges, and pears" - - """ - # make everything a string to avoid errors - value = [six.u(item) for item in value] - - if len(value) == 1: # one item in list - return value[0] - if len(value) == 2: # two items in list - return "%s and %s" % (value[0], value[1]) - - # join all but the last element - all_but_last = ", ".join(value[:-1]) - return "%s, and %s" % (all_but_last, value[-1]) - @register.filter def humanized_join(value, add_links=False): @@ -83,6 +55,7 @@ def humanized_join(value, add_links=False): # If it's not a list, just return it if not type(value) is list: return value + if add_links: try: value = ['%s' % (item.get_absolute_url(), six.u(item)) for item in value] diff --git a/tango_shared/tests.py b/tango_shared/tests.py index 59a9448..26621be 100644 --- a/tango_shared/tests.py +++ b/tango_shared/tests.py @@ -45,20 +45,20 @@ class TemplateTagsTests(TestCase): def setUp(self): self.test_list = ['apples', 'oranges'] - def test_humanized_join_with_one_items(self): + def test_humanized_join(self): t = Template('{% load formatting %}{{ mylist|humanized_join }}') + + # with one item c = Context({"mylist": 'foo'}) output = t.render(c) self.assertEqual(output, 'foo') - def test_humanized_join_with_two_items(self): - t = Template('{% load formatting %}{{ mylist|humanized_join }}') + # with two items c = Context({"mylist": self.test_list}) output = t.render(c) self.assertEqual(output, 'apples and oranges') - def test_humanized_join_with_more_items(self): - t = Template('{% load formatting %}{{ mylist|humanized_join }}') + # with three self.test_list.append('pears') c = Context({"mylist": self.test_list}) output = t.render(c)