0001-templatetags-make-count-an-alias-of-length-49889.patch
tests/test_formdata.py | ||
---|---|---|
1142 | 1142 |
context = pub.substitutions.get_context_variables(mode='lazy') |
1143 | 1143 |
tmpl = Template('{{form_objects|filter_by:"foo_foo"|filter_value:"bar"|count}}') |
1144 | 1144 |
assert tmpl.render(context) == '7' |
1145 |
tmpl = Template('{{form_objects|filter_by:"foo_foo"|filter_value:"bar"|length}}') |
|
1146 |
assert tmpl.render(context) == '7' |
|
1145 | 1147 | |
1146 | 1148 |
pub.substitutions.feed(formdata) |
1147 | 1149 |
tmpl = Template('{{form_objects|filter_by:"foo_foo"|filter_value:form_var_foo_foo|count}}') |
... | ... | |
2249 | 2251 |
assert tmpl.render(context) == '3.14' |
2250 | 2252 | |
2251 | 2253 | |
2254 |
def test_lazy_formdata_count_as_len_filter(pub): |
|
2255 |
formdef = FormDef() |
|
2256 |
formdef.name = 'foobar' |
|
2257 |
formdef.url_name = 'foobar' |
|
2258 |
formdef.fields = [ |
|
2259 |
fields.StringField(id='0', label='value', varname='value'), |
|
2260 |
] |
|
2261 |
formdef.store() |
|
2262 |
formdata = formdef.data_class()() |
|
2263 |
formdata.data = {'0': 'coin'} |
|
2264 |
formdata.store() |
|
2265 |
pub.substitutions.feed(formdata) |
|
2266 |
for mode in (None, 'lazy'): |
|
2267 |
context = pub.substitutions.get_context_variables(mode=mode) |
|
2268 |
tmpl = Template('{{ form_var_value|count }}') |
|
2269 |
assert tmpl.render(context) == '4' |
|
2270 | ||
2271 | ||
2252 | 2272 |
def test_rounding_and_abs_conditions_django(pub, variable_test_data): |
2253 | 2273 |
for true_condition_value in ( |
2254 | 2274 |
# reminder |
wcs/qommon/templatetags/qommon.py | ||
---|---|---|
664 | 664 | |
665 | 665 |
@register.filter |
666 | 666 |
def count(queryset): |
667 |
return queryset.count |
|
667 |
if hasattr(queryset, 'get_value'): |
|
668 |
queryset = queryset.get_value() # unlazy |
|
669 |
return len(queryset) |
|
668 | 670 | |
669 | 671 | |
670 | 672 |
@register.filter |
671 |
- |