0005-general-allow-lazy-value-in-filter-filters-43328.patch
tests/test_formdata.py | ||
---|---|---|
950 | 950 |
tmpl = Template('{{form_objects|filter_by:"foo_foo"|filter_value:"bar"|count}}') |
951 | 951 |
assert tmpl.render(context) == '7' |
952 | 952 | |
953 |
pub.substitutions.feed(formdata) |
|
954 |
tmpl = Template('{{form_objects|filter_by:"foo_foo"|filter_value:form_var_foo_foo|count}}') |
|
955 |
assert tmpl.render(context) == '7' |
|
956 | ||
953 | 957 | |
954 | 958 |
def test_lazy_global_forms(pub, variable_test_data): |
955 | 959 |
lazy_formdata = variable_test_data |
wcs/qommon/templatetags/qommon.py | ||
---|---|---|
518 | 518 | |
519 | 519 |
@register.filter |
520 | 520 |
def order_by(queryset, attribute): |
521 |
if hasattr(attribute, 'get_value'): |
|
522 |
attribute = attribute.get_value() # unlazy |
|
521 | 523 |
return queryset.order_by(attribute) |
522 | 524 | |
523 | 525 | |
524 | 526 |
@register.filter |
525 | 527 |
def filter_by(queryset, attribute): |
528 |
if hasattr(attribute, 'get_value'): |
|
529 |
attribute = attribute.get_value() # unlazy |
|
526 | 530 |
return queryset.filter_by(attribute) |
527 | 531 | |
528 | 532 | |
529 | 533 |
@register.filter |
530 | 534 |
def filter_value(queryset, value): |
535 |
if hasattr(value, 'get_value'): |
|
536 |
value = value.get_value() # unlazy |
|
531 | 537 |
return queryset.apply_filter_value(value) |
532 | 538 | |
533 | 539 | |
534 |
- |