Commit 8173e6d1 by Roque

erp5_messenger: messenger now relies on post_module and web messages (events)

- refactoring in scripts to create threads and replies
- new query to get posts
1 parent 5a7c34ce
portal = context.getPortalObject()
person = context.ERP5Site_getAuthenticatedMemberPersonValue()
person = portal.person_module.get("roqueporchetto")
#TODO get person from user/autenticatedMember
messenger_thread = portal.messenger_thread_module.newContent(
messenger_thread = context.getPortalObject().messenger_thread_module.newContent(
title = thread_title,
portal_type = "Messenger Thread"
)
messenger_thread.setReference(messenger_thread.getId())
messenger_post = portal.messenger_post_module.newContent(
title = thread_title,
text_content = text_content,
source_value = person,
follow_up_value = messenger_thread,
portal_type = "Messenger Post"
)
messenger_thread.MessengerThread_createPost(thread_title, text_content)
portal_status_message = "New thread created"
context.Base_redirect("view", keep_items = dict(portal_status_message = portal_status_message))
messenger_thread.Base_redirect("view", keep_items = dict(portal_status_message = portal_status_message))
assert context.getPortalType() == "Messenger Thread"
portal = context.getPortalObject()
person = context.ERP5Site_getAuthenticatedMemberPersonValue()
person = portal.person_module.get("roqueporchetto")
#TODO get person from user/autenticatedMember
title = "Re: " + context.getTitle()
messenger_post = portal.messenger_post_module.newContent(
title = title,
text_content = text_content,
source_value = person,
follow_up_value = context,
portal_type = "Messenger Post"
)
context.MessengerThread_createPost(title, text_content)
portal_status_message = "New post created"
context.Base_redirect("view", keep_items = dict(portal_status_message = portal_status_message))
post = context.PostModule_createHTMLPost(
title = title,
source_reference = context.getReference(),
data = text_content,
follow_up = context.getRelativeUrl(),
predecessor = None
)
attached_file = None
web_site_relative_url = None
if attached_file not in ("undefined", None):
pass # TODO attached file
else:
post.publish()
after_ingest_document_tag = 'after-ingest-%s' % post.getId()
post.activate(
after_tag=after_ingest_document_tag
).Post_ingestAndCreateEvent(
web_site_relative_url=web_site_relative_url)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>title, text_content</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MessengerThread_createPost</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -159,7 +159,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: [ ( \'query\', context.getPortalObject().portal_catalog.getSQLCatalog().buildQuery({"portal_type":[\'Messenger Post\'], "strict_follow_up_uid":context.getUid()}).asSearchTextExpression(context.getPortalObject().portal_catalog.getSQLCatalog()) ), (\'view\', "view"), (\'jio_key\', context.getRelativeUrl()), (\'portal_type\', context.getPortalType()), (\'maximize\', \'listbox\' not in field.id)]</string> </value>
<value> <string>python: [ ( \'query\', context.getPortalObject().portal_catalog.getSQLCatalog().buildQuery({"portal_type":[\'Web Message\'], "source_reference":context.getId()}).asSearchTextExpression(context.getPortalObject().portal_catalog.getSQLCatalog()) ), (\'view\', "view"), (\'jio_key\', context.getRelativeUrl()), (\'portal_type\', context.getPortalType()), (\'maximize\', \'listbox\' not in field.id)]</string> </value>
</item>
</dictionary>
</pickle>
......
from Products.ERP5Type.Message import translateString
portal = context.getPortalObject()
messenger_thread = context.getFollowUpValue()
web_site_value = portal.restrictedTraverse(web_site_relative_url) if web_site_relative_url else None
data = str(context.getData())
is_html = context.getPortalType() == 'HTML Post'
if is_html: # sanitize HTML
data = portal.portal_transforms.convertToData(
'text/x-html-safe',
data,
context=context,
mimetype=context.getContentType())
# TODO: check resource, in support_request seems to be important
resource = None
source_value = context.ERP5Site_getAuthenticatedMemberPersonValue()
web_message = portal.event_module.newContent(
portal_type = 'Web Message',
title = context.getTitle(),
content_type = 'text/html' if is_html else 'text/plain',
text_content = data,
follow_up_value = messenger_thread,
aggregate_value_list = [context] + context.getSuccessorValueList(
portal_type = portal.getPortalDocumentTypeList()),
resource = resource,
source_value = source_value,
start_date = context.getCreationDate(),
source_reference = context.getSourceReference())
web_message.stop()
context.archive(
comment=translateString('Ingested as ${web_message_reference}',
mapping={'web_message_reference': web_message.getReference()}))
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>web_site_relative_url=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Post_ingestAndCreateEvent</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!