0001-blocks-check-variable-name-in-digest-template-48207.patch
tests/admin_pages/test_block.py | ||
---|---|---|
47 | 47 |
def test_block_new(pub, blocks_feature): |
48 | 48 |
create_superuser(pub) |
49 | 49 |
create_role() |
50 |
BlockDef.wipe() |
|
50 | 51 |
app = login(get_app(pub)) |
51 | 52 |
resp = app.get('/backoffice/forms/') |
52 | 53 |
resp = resp.click('Fields blocks') |
... | ... | |
106 | 107 |
resp = resp.follow() |
107 | 108 | |
108 | 109 | |
110 |
def test_block_options_digest_template(pub, blocks_feature): |
|
111 |
create_superuser(pub) |
|
112 |
BlockDef.wipe() |
|
113 |
block = BlockDef() |
|
114 |
block.name = 'foobar' |
|
115 |
block.fields = [] |
|
116 |
block.store() |
|
117 | ||
118 |
app = login(get_app(pub)) |
|
119 |
resp = app.get('/backoffice/forms/blocks/%s/settings' % block.id) |
|
120 |
resp.form['digest_template'] = 'X{{form_var_foo}}Y' |
|
121 |
resp = resp.form.submit('submit') |
|
122 |
assert 'Wrong variable "form_var_…" detected. Please replace it by "foobar_var_…".' in resp.text |
|
123 |
block = BlockDef.get(block.id) |
|
124 |
assert block.digest_template is None |
|
125 | ||
126 |
resp = app.get('/backoffice/forms/blocks/%s/settings' % block.id) |
|
127 |
resp.form['digest_template'] = 'X{{foobar_var_foo}}Y' |
|
128 |
resp = resp.form.submit('submit') |
|
129 |
block = BlockDef.get(block.id) |
|
130 |
assert block.digest_template == 'X{{foobar_var_foo}}Y' |
|
131 | ||
132 | ||
109 | 133 |
def test_block_export_import(pub, blocks_feature): |
110 | 134 |
create_superuser(pub) |
111 | 135 |
create_role() |
wcs/admin/blocks.py | ||
---|---|---|
160 | 160 |
self.objectdef.name = form.get_widget('name').parse() |
161 | 161 |
if form.get_widget('slug'): |
162 | 162 |
self.objectdef.slug = form.get_widget('slug').parse() |
163 |
self.objectdef.digest_template = form.get_widget('digest_template').parse() |
|
164 |
self.objectdef.store() |
|
165 |
return redirect('.') |
|
163 |
widget_template = form.get_widget('digest_template') |
|
164 |
if widget_template.parse() and 'form_var_' in widget_template.parse(): |
|
165 |
widget_template.set_error( |
|
166 |
_('Wrong variable "form_var_…" detected. Please replace it by "%s_var_…".') |
|
167 |
% self.objectdef.slug) |
|
168 |
else: |
|
169 |
self.objectdef.digest_template = widget_template.parse() |
|
170 |
self.objectdef.store() |
|
171 |
return redirect('.') |
|
166 | 172 | |
167 | 173 |
html_top(self.section, title=_('Settings')) |
168 | 174 |
r = TemplateIO(html=True) |
169 |
- |