0001-misc-add-fields-verification-after-tracking-code-590.patch
wcs/admin/forms.py | ||
---|---|---|
266 | 266 |
title=_('Enable support for tracking codes'), |
267 | 267 |
value=self.formdef.enable_tracking_codes, |
268 | 268 |
) |
269 |
validation_fields = [(None, '---', None)] |
|
270 |
for field in self.formdef.fields: |
|
271 |
if field.type in ('string', 'date', 'email'): |
|
272 |
validation_fields.append((field.id, field.label, field.id)) |
|
273 |
form.add( |
|
274 |
WidgetList, |
|
275 |
'tracking_code_fields', |
|
276 |
title=_('Tracking code post-validation fields'), |
|
277 |
element_type=SingleSelectWidget, |
|
278 |
value=self.formdef.tracking_code_fields, |
|
279 |
add_element_label=_('Add Field'), |
|
280 |
element_kwargs={'render_br': False, 'options': validation_fields}, |
|
281 |
) |
|
282 | ||
269 | 283 |
widget = form.add( |
270 | 284 |
WcsExtraStringWidget, |
271 | 285 |
'drafts_lifespan', |
... | ... | |
442 | 456 |
'only_allow_one', |
443 | 457 |
'disabled', |
444 | 458 |
'enable_tracking_codes', |
459 |
'tracking_code_fields', |
|
445 | 460 |
'always_advertise', |
446 | 461 |
'disabled_redirection', |
447 | 462 |
'publication_date', |
wcs/formdef.py | ||
---|---|---|
147 | 147 |
disabled = False |
148 | 148 |
only_allow_one = False |
149 | 149 |
enable_tracking_codes = False |
150 |
tracking_code_fields = None |
|
150 | 151 |
disabled_redirection = None |
151 | 152 |
always_advertise = False |
152 | 153 |
publication_date = None |
wcs/forms/root.py | ||
---|---|---|
181 | 181 |
raise errors.TraversalError() |
182 | 182 |
if get_request().is_from_bot(): |
183 | 183 |
raise errors.AccessForbiddenError() |
184 | ||
185 |
verification_fields = [ |
|
186 |
field |
|
187 |
for field in formdata.formdef.fields |
|
188 |
if field.id in (formdata.formdef.tracking_code_fields or []) |
|
189 |
] |
|
190 |
if verification_fields: |
|
191 |
form = Form() |
|
192 |
for field in verification_fields: |
|
193 |
widget = field.add_to_form(form) |
|
194 |
widget.field = field |
|
195 |
form.add_submit('submit', _('Verify')) |
|
196 |
form.add_submit('cancel', _('Cancel')) |
|
197 | ||
198 |
if form.get_submit() == 'cancel': |
|
199 |
return redirect('/') |
|
200 | ||
201 |
if form.is_submitted() and not form.has_errors(): |
|
202 |
for field in verification_fields: |
|
203 |
submitted = form.get_widget('f%s' % field.id).parse() |
|
204 |
if submitted != formdata.data.get(field.id): |
|
205 |
raise errors.AccessForbiddenError(_('Verification failed')) |
|
206 |
else: |
|
207 |
html_top() |
|
208 |
r = TemplateIO(html=True) |
|
209 |
r += htmltext('<h2>%s</h2>') % _('Tracking Code Verification') |
|
210 |
r += form.render() |
|
211 |
return r.getvalue() |
|
212 | ||
184 | 213 |
get_session().mark_anonymous_formdata(formdata) |
185 | 214 |
return redirect(formdata.get_url()) |
186 | 215 | |
187 |
- |