fields: extend field live dependency to structured/live data (#45342)

This commit is contained in:
Frédéric Péters 2020-07-27 13:51:49 +02:00
parent 83e341c9d9
commit 289067de6d
2 changed files with 29 additions and 1 deletions

View File

@ -7232,6 +7232,32 @@ def test_field_live_comment_content(pub, http_requests):
assert live_resp.json['result']['7']['content'] == '<p>bla hello bla</p>'
def test_field_live_comment_content_from_structured_item_data(pub, http_requests):
FormDef.wipe()
formdef = FormDef()
formdef.name = 'Foo'
formdef.fields = [
fields.ItemField(type='item', id='1', label='Foo',
varname='bar',
data_source={
'type': 'json',
'value': 'http://remote.example.net/json-list-extra'
}
),
fields.CommentField(id='7', label='bla {{form_var_bar_structured_foo}} bla', type='comment'),
]
formdef.store()
formdef.data_class().wipe()
app = get_app(pub)
resp = app.get('/foo/')
assert 'f1' in resp.form.fields
assert resp.html.find('div', {'data-field-id': '1'}).attrs['data-live-source'] == 'true'
resp.form['f1'] = 'a'
live_resp = app.post('/foo/live', params=resp.form.submit_fields())
assert live_resp.json['result']['7']['content'] == '<p>bla bar bla</p>'
def test_form_edit_and_backoffice_field_change(pub):
create_user(pub)

View File

@ -463,7 +463,9 @@ class Field(object):
return True
def get_referenced_varnames(self, formdef, value):
return re.findall(r'\b%s[_\.]var[_\.]([a-zA-Z0-9_]+?)(?:_raw|\b)' % formdef.var_prefix, value or '')
return re.findall(
r'\b%s[_\.]var[_\.]([a-zA-Z0-9_]+?)(?:_raw|_live_|_structured_|\b)' % formdef.var_prefix,
value or '')
def get_condition_varnames(self, formdef):
return self.get_referenced_varnames(formdef, self.condition['value'])