Fix for exception in /open-movies

When extension_props.cloud.poster was set to empty string, we would
try to get file anyway and we would set the has_poster has_poster
convenience attribute to true. This would lead to an exception when
trying to access the poster file object in the template.
This commit is contained in:
2019-04-04 11:47:23 +02:00
parent b4ecf93485
commit 6d47946b1b

View File

@@ -207,17 +207,22 @@ def open_projects():
'sort': '-_created',
}, api=api)
for project in projects._items:
# Attach poster file (ensure the extension_props.cloud.poster attributes exists)
if 'extension_props' not in project:
# Attach poster file (ensure the extension_props.cloud.poster
# attributes exists)
try:
# If the attribute exists, but is None, continue
if not project['extension_props'][EXTENSION_NAME]['poster']:
continue
# Fetch the file and embed it in the document
project.extension_props.cloud.poster = get_file(
project.extension_props.cloud.poster, api=api)
# Add convenience attribute that specifies the presence of the
# poster file
project.has_poster = True
# If there was a key error because one of the nested attributes is
# missing,
except KeyError:
continue
if EXTENSION_NAME not in project['extension_props']:
continue
if 'poster' not in project['extension_props'][EXTENSION_NAME]:
continue
project.extension_props.cloud.poster = get_file(
project.extension_props.cloud.poster, api=api)
# Add convenience attribute that specifies the presence of the poster file
project.has_poster = True
return render_template(
'films.html',