misc: give widget templates full access to publisher context (#24338)
This commit is contained in:
parent
a0dfbf8046
commit
240ba37244
|
@ -2,6 +2,7 @@
|
|||
{% block widget-control %}
|
||||
<!-- TEST TEMPLATE -->
|
||||
<!-- backoffice: {{ request.quixote_request.is_in_backoffice|pprint }} -->
|
||||
<!-- substitution variable: {{ example_url }} -->
|
||||
<select id="form_{{widget.name}}" name="{{widget.name}}"
|
||||
{% for attr in widget.attrs.items %}{{attr.0}}="{{attr.1}}"{% endfor %}>
|
||||
<option value="">---</option>
|
||||
|
|
|
@ -4547,6 +4547,15 @@ def test_form_custom_select_template(pub):
|
|||
# make sure request is available in context
|
||||
assert '<!-- backoffice: False -->' in resp.body
|
||||
|
||||
# test for substitution variables being available
|
||||
if not pub.site_options.has_section('variables'):
|
||||
pub.site_options.add_section('variables')
|
||||
pub.site_options.set('variables', 'example_url', 'http://remote.example.net/')
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
pub.site_options.write(fd)
|
||||
resp = get_app(pub).get('/test/')
|
||||
assert 'substitution variable: http://remote.example.net/' in resp.body
|
||||
|
||||
def test_form_status_appearance_keywords(pub):
|
||||
create_user(pub)
|
||||
formdef = create_formdef()
|
||||
|
|
|
@ -128,7 +128,11 @@ def render(self):
|
|||
self.rendered_title = lambda: safe(self.render_title(self.get_title()))
|
||||
self.rendered_error = lambda: safe(self.render_error(self.get_error()))
|
||||
self.rendered_hint = lambda: safe(self.render_hint(self.get_hint()))
|
||||
context = {'widget': self}
|
||||
if get_publisher():
|
||||
context = get_publisher().substitutions.get_context_variables()
|
||||
else:
|
||||
context = {}
|
||||
context['widget'] = self
|
||||
template_names = get_template_names(self)
|
||||
return htmltext(render_template(template_names, context))
|
||||
|
||||
|
|
Loading…
Reference in New Issue