0001-misc-update-live-content-of-comment-fields-26441.patch
tests/test_form_pages.py | ||
---|---|---|
5792 | 5792 |
assert formdata.data['3'] == 'a' |
5793 | 5793 |
assert formdata.data['3_display'] == 'b' |
5794 | 5794 | |
5795 |
def test_field_live_comment_content(pub, http_requests): |
|
5796 |
FormDef.wipe() |
|
5797 |
formdef = FormDef() |
|
5798 |
formdef.name = 'Foo' |
|
5799 |
formdef.fields = [ |
|
5800 |
fields.StringField(type='string', id='1', label='Bar', size='40', |
|
5801 |
required=True, varname='bar'), |
|
5802 |
fields.StringField(type='string', id='2', label='Baz', size='40'), |
|
5803 |
fields.CommentField(id='5', label='bla {{form_var_bar}} bla', type='comment'), |
|
5804 |
] |
|
5805 |
formdef.store() |
|
5806 |
formdef.data_class().wipe() |
|
5807 | ||
5808 |
app = get_app(pub) |
|
5809 |
resp = app.get('/foo/') |
|
5810 |
assert 'f1' in resp.form.fields |
|
5811 |
assert resp.html.find('div', {'data-field-id': '1'}).attrs['data-live-source'] == 'true' |
|
5812 |
resp.form['f1'] = 'hello' |
|
5813 |
live_resp = app.post('/foo/live', params=resp.form.submit_fields()) |
|
5814 |
assert live_resp.json['result']['5']['content'] == '<p>bla hello bla</p>' |
|
5815 |
resp.form['f1'] = 'toto' |
|
5816 |
live_resp = app.post('/foo/live?modified_field_id=1', params=resp.form.submit_fields()) |
|
5817 |
assert live_resp.json['result']['5']['content'] == '<p>bla toto bla</p>' |
|
5818 |
live_resp = app.post('/foo/live?modified_field_id=2', params=resp.form.submit_fields()) |
|
5819 |
assert live_resp.json['result']['5']['content'] == '<p>bla toto bla</p>' |
|
5820 | ||
5795 | 5821 |
def test_form_edit_and_backoffice_field_change(pub): |
5796 | 5822 |
create_user(pub) |
5797 | 5823 |
wcs/fields.py | ||
---|---|---|
402 | 402 |
except RuntimeError: |
403 | 403 |
return True |
404 | 404 | |
405 |
def get_referenced_varnames(self, value): |
|
406 |
return re.findall(r'\bform[_\.]var[_\.]([a-zA-Z0-9_]+?)(?:_raw|\b)', value or '') |
|
407 | ||
405 | 408 |
def get_condition_varnames(self): |
406 |
return re.findall(r'\bform[_\.]var[_\.]([a-zA-Z0-9_]+?)(?:_raw|\b)', self.condition['value'])
|
|
409 |
return self.get_referenced_varnames(self.condition['value'])
|
|
407 | 410 | |
408 | 411 |
def has_live_conditions(self, formdef): |
409 | 412 |
varnames = self.get_condition_varnames() |
wcs/forms/root.py | ||
---|---|---|
400 | 400 |
if not varname in live_condition_fields: |
401 | 401 |
live_condition_fields[varname] = [] |
402 | 402 |
live_condition_fields[varname].append(field) |
403 |
if field.key == 'comment': |
|
404 |
for varname in field.get_referenced_varnames(field.label): |
|
405 |
if not varname in live_condition_fields: |
|
406 |
live_condition_fields[varname] = [] |
|
407 |
live_condition_fields[varname].append(field) |
|
403 | 408 | |
404 | 409 |
for field in displayed_fields: |
405 | 410 |
if field.varname in live_condition_fields: |
... | ... | |
1084 | 1089 |
if modified_field_varname in varnames: |
1085 | 1090 |
result[field.id]['items'] = [ |
1086 | 1091 |
{'id': x[2], 'text': x[1]} for x in field.get_options(mode='lazy')] |
1092 |
for widget in form.widgets: |
|
1093 |
if not getattr(widget, 'field', None): |
|
1094 |
continue |
|
1095 |
if widget.field.key == 'comment': |
|
1096 |
result[widget.field.id]['content'] = widget.content |
|
1087 | 1097 | |
1088 | 1098 |
return json.dumps({'result': result}) |
1089 | 1099 |
wcs/qommon/static/js/qommon.forms.js | ||
---|---|---|
108 | 108 |
$option.appendTo($select); |
109 | 109 |
} |
110 | 110 |
} |
111 |
if (value.content) { |
|
112 |
// replace comment content |
|
113 |
var $widget = $('[data-field-id="' + key + '"]'); |
|
114 |
$widget.html(value.content); |
|
115 |
} |
|
111 | 116 |
}); |
112 | 117 |
} |
113 | 118 |
}); |
114 |
- |