misc: always clean complex values (#50104)
This commit is contained in:
parent
b4e6eafe16
commit
1f597a3c63
|
@ -2217,6 +2217,8 @@ def test_webservice_with_complex_data(http_requests, pub):
|
|||
ItemsField(id='2', label='2nd field',
|
||||
type='items', varname='items',
|
||||
data_source=datasource),
|
||||
StringField(id='3', label='3rd field',
|
||||
type='str', varname='str'),
|
||||
]
|
||||
formdef.workflow_id = wf.id
|
||||
formdef.store()
|
||||
|
@ -2229,6 +2231,7 @@ def test_webservice_with_complex_data(http_requests, pub):
|
|||
formdata.data['2'] = ['a', 'b']
|
||||
formdata.data['2_display'] = 'aa, bb'
|
||||
formdata.data['2_structured'] = formdef.fields[1].store_structured_value(formdata.data, '2')
|
||||
formdata.data['3'] = 'tutuche'
|
||||
formdata.just_created()
|
||||
formdata.store()
|
||||
|
||||
|
@ -2248,6 +2251,8 @@ def test_webservice_with_complex_data(http_requests, pub):
|
|||
'ezt_items_raw': '[form_var_items_raw]',
|
||||
'joined_items_raw': '{{ form_var_items_raw|join:"|" }}',
|
||||
'forloop_items_raw': '{% for item in form_var_items_raw %}{{item}}|{% endfor %}',
|
||||
'str': '{{ form_var_str }}',
|
||||
'str_mod': '{{ form_var_str }}--plop',
|
||||
}
|
||||
pub.substitutions.feed(formdata)
|
||||
with get_publisher().complex_data():
|
||||
|
@ -2268,6 +2273,8 @@ def test_webservice_with_complex_data(http_requests, pub):
|
|||
'ezt_items_raw': repr(['a', 'b']),
|
||||
'joined_items_raw': 'a|b',
|
||||
'forloop_items_raw': 'a|b|',
|
||||
'str': 'tutuche',
|
||||
'str_mod': 'tutuche--plop',
|
||||
}
|
||||
|
||||
# check it's possible to disable complex data support
|
||||
|
|
|
@ -2953,6 +2953,7 @@ class FormBackOfficeStatusPage(FormStatusPage):
|
|||
raises=True,
|
||||
record_errors=False,
|
||||
allow_complex=True)
|
||||
has_complex_result = get_publisher().has_cached_complex_data(result)
|
||||
complex_result = get_publisher().get_cached_complex_data(result)
|
||||
result = re.sub(r'[\uE000-\uF8FF]', '', result)
|
||||
except Exception as exception:
|
||||
|
@ -2971,7 +2972,7 @@ class FormBackOfficeStatusPage(FormStatusPage):
|
|||
r += htmltext('<pre class="test-tool-result-plain">%s</pre>') % result
|
||||
else:
|
||||
r += htmltext('<div class="test-tool-result-plain">%s</div>') % result
|
||||
if complex_result:
|
||||
if has_complex_result:
|
||||
r += htmltext('<h3>%s</h3>') % _('Also rendered as an object:')
|
||||
r += htmltext('<div class="test-tool-result-plain">%s (%s)</div>') % (
|
||||
complex_result, complex_result.__class__.__name__)
|
||||
|
|
|
@ -18,6 +18,7 @@ from contextlib import contextmanager
|
|||
import json
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
import traceback
|
||||
|
@ -410,10 +411,17 @@ class WcsPublisher(StubWcsPublisher):
|
|||
self.complex_data_cache[str_value] = value
|
||||
return str_value
|
||||
|
||||
def has_cached_complex_data(self, value):
|
||||
return bool(value in (self.complex_data_cache or {}))
|
||||
|
||||
def get_cached_complex_data(self, value):
|
||||
if not isinstance(value, str):
|
||||
return value
|
||||
value_ = (self.complex_data_cache or {}).get(value)
|
||||
if self.complex_data_cache is None:
|
||||
return value
|
||||
if value not in self.complex_data_cache:
|
||||
return re.sub(r'[\uE000-\uF8FF]', '', value)
|
||||
value_ = self.complex_data_cache.get(value)
|
||||
if hasattr(value_, 'get_value'):
|
||||
# unlazy variable
|
||||
return value_.get_value()
|
||||
|
|
Loading…
Reference in New Issue