misc: make _live_ attributes work with custom view data sources (#47844)
This commit is contained in:
parent
bcbaabf181
commit
700265f03e
|
@ -828,9 +828,22 @@ def test_lazy_formdata_live_item(pub):
|
|||
assert context['form_var_foo_live_var_attr'] == 'attr2'
|
||||
assert 'form_var_foo_live_var_attr' in context.get_flat_keys()
|
||||
|
||||
# check it also works with custom views
|
||||
ds = {'type': 'carddef:%s:xxx' % carddef.url_name}
|
||||
formdef.fields = [fields.ItemField(id='0', label='string', type='item',
|
||||
varname='foo', data_source=ds, display_disabled_items=True)]
|
||||
formdef.store()
|
||||
pub.substitutions.reset()
|
||||
pub.substitutions.feed(pub)
|
||||
pub.substitutions.feed(formdef)
|
||||
pub.substitutions.feed(formdata)
|
||||
pub.get_request().live_card_cache = {}
|
||||
assert 'form_var_foo_live_var_attr' in context.get_flat_keys()
|
||||
assert context['form_var_foo_live_var_name'] == 'baz'
|
||||
|
||||
# mock missing carddef to get call count
|
||||
pub.get_request().live_card_cache = {}
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
# mock missing carddef to get call count
|
||||
with mock.patch('wcs.carddef.CardDef.get_by_urlname') as get_by_urlname:
|
||||
get_by_urlname.side_effect = KeyError
|
||||
|
||||
|
|
|
@ -712,7 +712,7 @@ class LazyFieldVarStructured(LazyFieldVar):
|
|||
return LazyFormData(carddata)
|
||||
from wcs.carddef import CardDef
|
||||
try:
|
||||
carddef = CardDef.get_by_urlname(self._field.data_source['type'][8:])
|
||||
carddef = CardDef.get_by_urlname(self._field.data_source['type'].split(':')[1])
|
||||
carddata = carddef.data_class().get(self.raw)
|
||||
if request:
|
||||
request.live_card_cache[cache_key] = carddata
|
||||
|
|
Loading…
Reference in New Issue