0001-backoffice-keep-extra-query-parameters-in-backoffice.patch
tests/backoffice_pages/test_submission.py | ||
---|---|---|
1315 | 1315 |
assert 'The target user was not found, this form is anonymous.' in resp.text |
1316 | 1316 | |
1317 | 1317 | |
1318 |
def test_backoffice_submission_with_nameid_and_extra_query_string(pub, local_user): |
|
1319 |
user = create_user(pub) |
|
1320 | ||
1321 |
FormDef.wipe() |
|
1322 |
formdef = FormDef() |
|
1323 |
formdef.name = 'form title' |
|
1324 |
formdef.fields = [ |
|
1325 |
fields.ComputedField( |
|
1326 |
id='1', |
|
1327 |
label='computed', |
|
1328 |
varname='computed', |
|
1329 |
value_template='{{ request.GET.param }}', |
|
1330 |
freeze_on_initial_value=True, |
|
1331 |
), |
|
1332 |
fields.StringField( |
|
1333 |
id='2', |
|
1334 |
label='field', |
|
1335 |
type='string', |
|
1336 |
prefill={'type': 'string', 'value': 'x{{ form_var_computed }}y'}, |
|
1337 |
), |
|
1338 |
fields.StringField( |
|
1339 |
id='3', |
|
1340 |
label='field', |
|
1341 |
type='string', |
|
1342 |
prefill={'type': 'string', 'value': 'x{{ request.GET.param }}y'}, |
|
1343 |
), |
|
1344 |
] |
|
1345 |
formdef.backoffice_submission_roles = user.roles[:] |
|
1346 |
formdef.workflow_roles = {'_receiver': 1} |
|
1347 |
formdef.store() |
|
1348 | ||
1349 |
app = login(get_app(pub)) |
|
1350 |
resp = app.get('/backoffice/submission/form-title/?NameID=%s¶m=test' % local_user.name_identifiers[0]) |
|
1351 |
assert resp.location.startswith('http://example.net/backoffice/submission/form-title/') |
|
1352 | ||
1353 |
formdata_no = resp.location.split('/')[-2] |
|
1354 |
formdata = formdef.data_class().get(formdata_no) |
|
1355 |
assert formdata.user_id == str(local_user.id) |
|
1356 |
resp = resp.follow() # redirect to created draft |
|
1357 |
resp = resp.follow() # redirect to ?mt= |
|
1358 | ||
1359 |
# check user is mentioned in sidebar |
|
1360 |
assert '<h3>Associated User</h3>' in resp |
|
1361 |
assert '<p>%s</p>' % local_user.get_display_name() in resp |
|
1362 | ||
1363 |
assert resp.form['f2'].value == 'xtesty' # prefill with computed string (= request.GET) |
|
1364 |
assert resp.form['f3'].value == 'xtesty' # prefill with request.GET |
|
1365 |
resp = resp.form.submit('submit') |
|
1366 |
assert 'Check values then click submit.' in resp.text |
|
1367 |
# final submit |
|
1368 |
resp = resp.form.submit('submit') |
|
1369 | ||
1370 |
formdata_no = resp.location.split('/')[-2] |
|
1371 |
data_class = formdef.data_class() |
|
1372 |
formdata = data_class.get(formdata_no) |
|
1373 |
assert formdata.user_id == str(local_user.id) |
|
1374 |
assert formdata.data == {'1': 'test', '2': 'xtesty', '3': 'xtesty'} |
|
1375 | ||
1376 | ||
1318 | 1377 |
def test_backoffice_submission_only_one_check(pub, local_user): |
1319 | 1378 |
user = create_user(pub) |
1320 | 1379 |
wcs/backoffice/submission.py | ||
---|---|---|
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import time |
18 |
import urllib.parse |
|
18 | 19 | |
19 | 20 |
from django.utils.safestring import mark_safe |
20 | 21 |
from quixote import get_publisher, get_request, get_response, get_session, redirect |
... | ... | |
84 | 85 |
return redirect(get_publisher().get_backoffice_url() + '/submission/') |
85 | 86 |
return super()._q_index() |
86 | 87 | |
88 |
def restore_draft(self): |
|
89 |
# redirect to draft and keep extra query parameters so {{request.GET}} can be used in form. |
|
90 |
params = {'mt': self.get_restore_draft_magictoken()} |
|
91 |
params.update(get_request().form or {}) |
|
92 |
return redirect('../?' + urllib.parse.urlencode(params)) |
|
93 | ||
87 | 94 | |
88 | 95 |
class FormFillPage(PublicFormFillPage): |
89 | 96 |
_q_exports = [ |
... | ... | |
145 | 152 |
formdata.submission_context['caller'] = caller |
146 | 153 |
formdata.store() |
147 | 154 |
self.set_tracking_code(formdata) |
148 |
return redirect('%s/' % formdata.id) |
|
155 |
redirect_url = '%s/' % formdata.id |
|
156 |
extra_query_params = { |
|
157 |
x: y |
|
158 |
for x, y in get_request().form.items() |
|
159 |
if x not in ('channel', 'NameID', 'ReturnURL', 'caller') |
|
160 |
} |
|
161 |
if extra_query_params: |
|
162 |
redirect_url += '?' + urllib.parse.urlencode(extra_query_params) |
|
163 |
return redirect(redirect_url) |
|
149 | 164 | |
150 | 165 |
self.selected_submission_channel = get_request().form.get('channel') or get_request().form.get( |
151 | 166 |
'submission_channel' |
wcs/forms/common.py | ||
---|---|---|
312 | 312 |
templates=list(self.get_formdef_template_variants(self.status_templates)), context=context |
313 | 313 |
) |
314 | 314 | |
315 |
def restore_draft(self):
|
|
316 |
# restore and redirect to draft
|
|
315 |
def get_restore_draft_magictoken(self):
|
|
316 |
# restore draft into session
|
|
317 | 317 |
session = get_session() |
318 | 318 |
filled = self.filled |
319 | 319 |
if not (get_request().is_in_backoffice() and filled.backoffice_submission): |
... | ... | |
355 | 355 |
computed_data[field.id] = form_data[field.id] |
356 | 356 |
if computed_data: |
357 | 357 |
session.add_magictoken('%s-computed' % magictoken, computed_data) |
358 |
return magictoken |
|
358 | 359 | |
360 |
def restore_draft(self): |
|
361 |
# redirect to draft |
|
362 |
magictoken = self.get_restore_draft_magictoken() |
|
359 | 363 |
return redirect('../?mt=%s' % magictoken) |
360 | 364 | |
361 | 365 |
def get_workflow_form(self, user): |
362 |
- |