wcs: add count filter (#49406)

This commit is contained in:
Lauréline Guérin 2020-12-15 14:49:48 +01:00
parent 0e0042fa22
commit 3b1b0d3ca1
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 11 additions and 0 deletions

View File

@ -23,3 +23,8 @@ register = template.Library()
@register.filter
def objects(cards, slug):
return getattr(cards, slug).objects
@register.filter
def count(queryset):
return queryset.count

View File

@ -108,3 +108,9 @@ def test_errors(mock_send, context, nocache):
mock_send.side_effect = lambda *a, **k: MockedRequestResponse(content=json.dumps({'data': None}))
assert t.render(context) == "[]"
@mock.patch('combo.apps.wcs.models.requests.send', side_effect=mocked_requests_send)
def test_count(mock_send, context, nocache):
t = Template('{% load wcs %}{{ cards|objects:"foo"|count }}')
assert t.render(context) == "2"