Commit 595fee10 authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: WIP support event's attachment

parent a1a10bee
"""Generic script to add event """Generic script to add event
It creates new Event for any context which become follow_up of created Event. It creates new Event for any context which become follow_up of created Event.
""" """
from erp5.component.tool.NotificationTool import buildEmailMessage
portal = context.getPortalObject() portal = context.getPortalObject()
ticket = context ticket = context
REQUEST = context.REQUEST
# Max ~3Mb
if int(REQUEST.getHeader('Content-Length', 0)) > 3145728:
raise ValueError('Huge attachment is not supported')
# Create a mail message to allow attachment in the event
attachment_list = []
if attachment:
# Build dict wrapper for NotificationTool
mime_type = attachment.headers.get('Content-Type', '')
content = attachment.read()
name = getattr(attachment, 'filename', None)
attachment = dict(mime_type=mime_type,
content=content,
name=name)
attachment_list.append(attachment)
email = buildEmailMessage(from_url=None,
to_url=None,
msg=text_content,
subject=title,
attachment_list=attachment_list)
if direction == 'outgoing': if direction == 'outgoing':
source_relative_url = source or ticket.getSource() source_relative_url = source or ticket.getSource()
...@@ -21,6 +46,9 @@ elif direction == 'incoming': ...@@ -21,6 +46,9 @@ elif direction == 'incoming':
else: else:
raise NotImplementedError('The specified direction is not handled: %r' % (direction,)) raise NotImplementedError('The specified direction is not handled: %r' % (direction,))
if (notification_message is not None) and (attachment is not None):
raise ValueError('Can not add attachment to a notification message')
event_kw = { event_kw = {
'portal_type': portal_type, 'portal_type': portal_type,
'resource': resource, 'resource': resource,
...@@ -33,7 +61,7 @@ event_kw = { ...@@ -33,7 +61,7 @@ event_kw = {
'start_date': DateTime(), 'start_date': DateTime(),
'follow_up_value': ticket, 'follow_up_value': ticket,
'language': language, 'language': language,
'text_content': text_content, 'data': email.as_string(),
'content_type': content_type, 'content_type': content_type,
} }
# Create event # Create event
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>title, direction, portal_type, resource, text_content, content_type, notification_message=None, substitution_method_parameter_dict=None, keep_draft=False, source=None, destination=None, language=None, comment=None, **kw</string> </value> <value> <string>title, direction, portal_type, resource, text_content, content_type, attachment=None, notification_message=None, substitution_method_parameter_dict=None, keep_draft=False, source=None, destination=None, language=None, comment=None, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment