Allow attachments on nested properties

This commit is contained in:
Francesco Siddi 2015-12-01 18:23:33 +01:00
parent f4ef811fae
commit 0475f7b456

View File

@ -357,8 +357,15 @@ def parse_attachments(response):
files_collection = app.data.driver.db['files'] files_collection = app.data.driver.db['files']
for field in response['properties']['attachments']: for field in response['properties']['attachments']:
for attachment in response['properties']['attachments']: for attachment in response['properties']['attachments']:
field_name = attachment['field'] # Make a list from the property path
field_content = response[field_name] field_name_path = attachment['field'].split('.')
# This currently allow to access only properties inside of
# the properties property
if len(field_name_path) > 1:
field_content = response[field_name_path[0]][field_name_path[1]]
# This is for the "normal" first level property
else:
field_content = response[field_name_path[0]]
for f in attachment['files']: for f in attachment['files']:
slug = f['slug'] slug = f['slug']
slug_tag = "[{0}]".format(slug) slug_tag = "[{0}]".format(slug)
@ -373,7 +380,12 @@ def parse_attachments(response):
# Parse the content of the file and replace the attachment # Parse the content of the file and replace the attachment
# tag with the actual image link # tag with the actual image link
field_content = field_content.replace(slug_tag, l) field_content = field_content.replace(slug_tag, l)
response[field_name] = field_content # Apply the parsed value back to the property. See above for
# clarifications on how this is done.
if len(field_name_path) > 1:
response[field_name_path[0]][field_name_path[1]] = field_content
else:
response[field_name_path[0]] = field_content
app.on_fetched_item_nodes += before_returning_item_permissions app.on_fetched_item_nodes += before_returning_item_permissions