--- a/src/pyams_content_es/component/extfile.py Mon Jun 20 14:37:15 2016 +0200
+++ b/src/pyams_content_es/component/extfile.py Tue Jun 06 17:20:00 2017 +0200
@@ -27,21 +27,29 @@
@adapter_config(name='extfile', context=IExtFileContainerTarget, provides=IDocumentIndexInfo)
def ExtFileContainerTargetIndexInfo(content):
"""External files index info"""
- result = []
+ extfiles = []
+ attachments = []
for extfile in IExtFileContainer(content).values():
- extfile_index = {'title': extfile.title,
- 'description': extfile.description,
- 'data': {}}
+ extfiles.append({'title': extfile.title,
+ 'description': extfile.description})
for lang, data in extfile.data.items():
- if data.content_type.startswith(b'image/') or \
- data.content_type.startswith(b'audio/') or \
- data.content_type.startswith(b'video/'):
+ content_type = data.content_type
+ if isinstance(content_type, bytes):
+ content_type = content_type.decode()
+ if content_type.startswith('image/') or \
+ content_type.startswith('audio/') or \
+ content_type.startswith('video/'):
continue
- extfile_index['data'][lang] = {
- '_content_type': data.content_type.decode(),
- '_name': data.filename,
- '_language': lang,
- '_content': base64.encodebytes(data.data).decode()
- }
- result.append(extfile_index)
- return {'extfile': result}
+ attachments.append({
+ 'content_type': content_type,
+ 'name': data.filename,
+ 'language': lang,
+ 'content': base64.encodebytes(data.data).decode().replace('\n', '')
+ })
+ result = {'extfile': extfiles}
+ if attachments:
+ result.update({
+ '__pipeline__': 'attachment',
+ 'attachments': attachments
+ })
+ return result