wcs: fix |objects filter without cards in context (#67554)

This commit is contained in:
Lauréline Guérin 2022-11-17 09:08:23 +01:00
parent f0a435dd8a
commit 8f6fd7b2fe
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 10 additions and 1 deletions

View File

@ -21,7 +21,10 @@ register = template.Library()
@register.filter
def objects(cards, slug):
return getattr(cards, slug).objects
try:
return getattr(cards, slug).objects
except AttributeError:
return None
@register.filter

View File

@ -110,6 +110,12 @@ def test_objects(mock_send, settings, context, nocache):
t.render(context)
assert mock_send.call_args_list[0][0][0].url.startswith('http://127.0.0.3:8999/api/cards/bar/list?')
context = Context({}) # no cards in context
mock_send.reset_mock()
t = Template('{{ cards|objects:"bar" }}')
t.render(context)
assert mock_send.call_args_list == []
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
def test_with_custom_view(mock_send, context, nocache):