0002-fields-fix-file-field-prefill-with-wrong-value-54131.patch
tests/form_pages/test_file_field.py | ||
---|---|---|
375 | 375 |
resp.forms[0]['f0$file'] = upload |
376 | 376 |
resp = resp.forms[0].submit('submit') |
377 | 377 |
assert 'forbidden file type' in resp.text |
378 | ||
379 | ||
380 |
def test_form_file_field_with_wrong_value(pub): |
|
381 |
if pub.is_using_postgresql(): |
|
382 |
pub.loggederror_class.wipe() |
|
383 | ||
384 |
FormDef.wipe() |
|
385 |
formdef = FormDef() |
|
386 |
formdef.name = 'test' |
|
387 |
formdef.fields = [ |
|
388 |
fields.FileField(id='0', label='file', prefill={'type': 'string', 'value': 'foo bar wrong value'}) |
|
389 |
] |
|
390 |
formdef.store() |
|
391 | ||
392 |
get_app(pub).get('/test/') |
|
393 |
if pub.is_using_postgresql(): |
|
394 |
assert pub.loggederror_class.count() == 1 |
|
395 |
logged_error = pub.loggederror_class.select()[0] |
|
396 |
assert logged_error.formdef_id == formdef.id |
|
397 |
assert logged_error.summary == 'Failed to set value on field "file"' |
|
398 |
assert logged_error.exception_class == 'AttributeError' |
|
399 |
assert logged_error.exception_message == "'str' object has no attribute 'time'" |
wcs/qommon/form.py | ||
---|---|---|
758 | 758 |
return False |
759 | 759 | |
760 | 760 |
def set_value(self, value): |
761 |
self.value = value |
|
762 |
if self.value: |
|
763 |
if not hasattr(self.value, 'token') or not get_session().get_tempfile(self.value.token): |
|
764 |
# it has no token, or its token is not in the session; this may be |
|
765 |
# because the file value has not been created when filling a form, |
|
766 |
# or because it was restored from a draft created from an expired |
|
767 |
# session. Either way, create and use a new token. |
|
768 |
self.value.token = get_session().add_tempfile(self.value, storage=self.storage).get('token') |
|
769 |
self.get_widget('token').set_value(self.value.token) |
|
761 |
try: |
|
762 |
self.value = value |
|
763 |
if self.value: |
|
764 |
if not hasattr(self.value, 'token') or not get_session().get_tempfile(self.value.token): |
|
765 |
# it has no token, or its token is not in the session; this may be |
|
766 |
# because the file value has not been created when filling a form, |
|
767 |
# or because it was restored from a draft created from an expired |
|
768 |
# session. Either way, create and use a new token. |
|
769 |
self.value.token = ( |
|
770 |
get_session().add_tempfile(self.value, storage=self.storage).get('token') |
|
771 |
) |
|
772 |
self.get_widget('token').set_value(self.value.token) |
|
773 |
except Exception as e: |
|
774 |
get_publisher().record_error( |
|
775 |
_('Failed to set value on field "%s"') % self.field.label, |
|
776 |
formdef=getattr(self, 'formdef', None), |
|
777 |
exception=e, |
|
778 |
) |
|
779 |
self.value = None |
|
770 | 780 | |
771 | 781 |
def add_media(self): |
772 | 782 |
get_response().add_javascript(['qommon.fileupload.js']) |
773 |
- |