Commit d1eb52cd authored by Tristan Cavelier's avatar Tristan Cavelier

erp5_post: change create HTML post API

keep backward compatibility with erp5_officejs_support_request_ui
parent abc20a0e
follow_up_object, = context.getPortalObject().portal_catalog(relative_url=follow_up, limit=1) follow_up_object, = context.getPortalObject().portal_catalog(relative_url=follow_up, limit=1)
follow_up_object.edit() # update modification date follow_up_object.edit() # update modification date
result = context.PostModule_createHTMLPostFromText( post = context.PostModule_createHTMLPostFromText(
follow_up, follow_up=follow_up,
predecessor, data=data,
data,
file,
) )
return result
if file != "undefined": # XXX "undefined" ? should also be fixed in javascript side
document_kw = {'batch_mode': True,
'redirect_to_document': False,
'file': file}
document = context.Base_contribute(**document_kw)
# set relation between post and document
# XXX successor is used as a way to put a relation between the attachment and the post,
# the actual way should be to use a proper container like an Event that will have
# one or several posts and one or several attachments.
post.setSuccessorValueList([document])
# XXX depending on security model this should be changed accordingly
document.publish()
portal = context.getPortalObject() portal = context.getPortalObject()
now = DateTime()
# create an HTML Post # create an HTML Post
post_module = portal.post_module post_module = portal.post_module
...@@ -14,27 +12,20 @@ if object_list: ...@@ -14,27 +12,20 @@ if object_list:
else: else:
raise LookupError("Target follow up object not found") raise LookupError("Target follow up object not found")
post.edit( now = DateTime()
start_date=now, post_edit_kw = {
follow_up_value=follow_up_object, "start_date": now,
predecessor_value = predecessor if predecessor else None, "follow_up_value": follow_up_object,
text_content=data, "text_content": data,
) }
if predecessor is not None:
# handle attachments predecessor_value, = portal.portal_catalog(relative_url=predecessor)
if file != "undefined": post_edit_kw["predecessor_value"] = predecessor_value.getObject()
document_kw = {'batch_mode': True, post.edit(**post_edit_kw)
'redirect_to_document': False,
'file': file}
document = context.Base_contribute(**document_kw)
# set relation between post and document
post.setSuccessorValueList([document])
# depending on security model this should be changed accordingly
document.publish()
post.publish() post.publish()
# We need to reindex the object on server. So the page will get the post which # We need to reindex the object on server. So the page will get the post which
# just submmitted. # just submmitted.
post.immediateReindexObject() post.immediateReindexObject()
return return post
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>follow_up, predecessor, data, file</string> </value> <value> <string>follow_up, data, predecessor=None</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
return context.PostModule_createHTMLPost( return context.PostModule_createHTMLPost(
follow_up, follow_up=follow_up,
predecessor, predecessor=predecessor,
"<p>" + data.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace(" ", " &nbsp;").replace("\n", "<br/>") + "</p>", data="<p>" + data.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace(" ", " &nbsp;").replace("\n", "<br/>") + "</p>",
file,
) )
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>follow_up, predecessor, data, file</string> </value> <value> <string>follow_up, data, predecessor=None</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</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