misc: do not fail temporary_access_url if formdata got removed (#88232) #1275
|
@ -1795,3 +1795,27 @@ def test_convert_image_format_errors(pub):
|
|||
assert pub.get_cached_complex_data(img) is None
|
||||
assert pub.loggederror_class.count() == 1
|
||||
assert pub.loggederror_class.select()[0].summary == '|convert_image_format: conversion error (xxx)'
|
||||
|
||||
|
||||
def test_temporary_access_url(pub):
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'foobar'
|
||||
formdef.fields = [fields.StringField(id='1', label='Test', varname='foo')]
|
||||
formdef.store()
|
||||
|
||||
# no formdata
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
assert Template('{% temporary_access_url %}').render(context) == ''
|
||||
|
||||
# formdata
|
||||
formdata = formdef.data_class()()
|
||||
formdata.data = {'1': 'Foo Bar'}
|
||||
formdata.store()
|
||||
pub.substitutions.feed(formdata)
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
assert Template('{% temporary_access_url %}').render(context).startswith('http://example.net/code/')
|
||||
|
||||
# removed formdata
|
||||
formdata.remove_self()
|
||||
assert Template('{% temporary_access_url %}').render(context) == ''
|
||||
|
|
|
@ -1313,7 +1313,11 @@ def temporary_access_url(
|
|||
from wcs.formdef import FormDef
|
||||
|
||||
formdef = FormDef.get_by_urlname(formdef_urlname)
|
||||
formdata = formdef.data_class().get(formdata_id)
|
||||
try:
|
||||
formdata = formdef.data_class().get(formdata_id)
|
||||
except KeyError:
|
||||
# formdata somehow got removed, ignore
|
||||
return ''
|
||||
|
||||
duration = 0
|
||||
for amount, unit in ((days, 86400), (hours, 3600), (minutes, 60), (seconds, 1)):
|
||||
|
|
Loading…
Reference in New Issue