0001-templatetags-add-split-33042.patch
combo/public/templatetags/combo.py | ||
---|---|---|
220 | 220 |
except AttributeError: |
221 | 221 |
return None |
222 | 222 | |
223 |
@register.filter |
|
224 |
def split(string, separator=' '): |
|
225 |
return (string or '').split(separator) |
|
226 | ||
223 | 227 |
@register.filter(name='get_group') |
224 | 228 |
def get_group(group_list, group_name): |
225 | 229 |
ret = [] |
tests/test_public_templatetags.py | ||
---|---|---|
122 | 122 |
context = Context({'foo': {'foo-bar': 'hello'}, 'key': 'foo-bar'}) |
123 | 123 |
assert t.render(context) == 'hello' |
124 | 124 | |
125 |
def test_split(): |
|
126 |
t = Template('{% load combo %}{% for x in plop|split %}{{x}}<br>{% endfor %}') |
|
127 |
assert t.render(Context({'plop': 'ab cd ef'})) == 'ab<br>cd<br>ef<br>' |
|
128 |
t = Template('{% load combo %}{% for x in plop|split:"|" %}{{x}} {% endfor %}') |
|
129 |
assert t.render(Context({'plop': 'ab|cd|ef'})) == 'ab cd ef ' |
|
130 | ||
125 | 131 |
def test_get_group(): |
126 | 132 |
context = Context({'cities': [ |
127 | 133 |
{'name': 'Mumbai', 'population': '19,000,000', 'country': 'India'}, |
128 |
- |