misc: add getlist filter compatibility for block field (#45394)
This commit is contained in:
parent
0d0a5ad5ee
commit
e08ac1f3d4
|
@ -2311,3 +2311,6 @@ def test_block_variables(pub, blocks_feature):
|
|||
|
||||
tmpl = Template('{{ form_var_block|length }}')
|
||||
assert tmpl.render(context) == '2'
|
||||
|
||||
tmpl = Template('{% for foo in form_var_block|getlist:"foo" %}/{{ foo }}{% endfor %}')
|
||||
assert tmpl.render(context) == '/foo/foo2'
|
||||
|
|
|
@ -63,6 +63,11 @@ def get(mapping, key):
|
|||
return mapping[key]
|
||||
|
||||
|
||||
@register.filter
|
||||
def getlist(mapping, key):
|
||||
return mapping.getlist(key)
|
||||
|
||||
|
||||
@register.filter
|
||||
def startswith(string, substring):
|
||||
return string and force_text(string).startswith(force_text(substring))
|
||||
|
|
|
@ -890,6 +890,15 @@ class LazyFieldVarBlock(LazyFieldVar):
|
|||
for i in range(len(data)):
|
||||
yield self[i]
|
||||
|
||||
def getlist(self, key):
|
||||
# called by |getlist filter
|
||||
for field in self._field.block.fields:
|
||||
if field.varname == key:
|
||||
break
|
||||
else:
|
||||
raise AttributeError('No such attribute %r' % key)
|
||||
return [data.get(field.id) for data in self._formdata.data.get(self._field.id)['data']]
|
||||
|
||||
|
||||
class LazyUser(object):
|
||||
def __init__(self, user):
|
||||
|
|
Loading…
Reference in New Issue