Commit f665c90e authored by Jérome Perrin's avatar Jérome Perrin

officejs_support_request_ui: reuse existing API script for "Comment {Date,Author}"

Because this API script returns JSON, it cannot easily be used
"internally" server side, so the logic as been moved to a
SupportRequest_getCommentPostList and
SupportRequest_getCommentPostListAsJson just does the serialization to
JSON part.

It has been found that there is no convention for "scripts returning
JSON but that can also be called by other script", so this way is not an
example to follow.
parent 827b9e18
portal = context.getPortalObject()
document_type_list = portal.getPortalDocumentTypeList()
event_list = portal.portal_simulation.getMovementHistoryList(
security_query=portal.portal_catalog.getSecurityQuery(),
portal_type=portal.getPortalEventTypeList(),
strict_follow_up_uid=context.getUid(),
simulation_state=('started', 'stopped', 'delivered', ),
only_accountable=False,
omit_input=True,
sort_on=(('date', 'asc'), ('uid', 'asc',),)
)
comment_list = []
for event in event_list:
event = event.getObject()
attachment_link = attachment_name = None
attachment = event.getDefaultAggregateValue(portal_type=document_type_list)
if attachment is not None:
attachment_link, attachment_name = attachment.getRelativeUrl(), attachment.getFilename()
comment_list.append((dict(
user=event.getSourceTitle(),
date=event.getStartDate().ISO8601(),
text=event.asStrippedHTML(),
attachment_link=attachment_link,
attachment_name=attachment_name,
message_id=event.getSourceReference(),
)))
just_posted_comment = portal.portal_sessions[
'%s.latest_comment' % context.getRelativeUrl()].pop(
'comment_post_list', None)
if just_posted_comment is not None:
# make sure not to display twice if it was already ingested in the meantime.
if just_posted_comment['message_id'] not in [comment['message_id'] for comment in comment_list]:
comment_list.append(just_posted_comment)
return comment_list
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SupportRequest_getCommentPostList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from json import dumps from json import dumps
portal = context.getPortalObject() return dumps(context.SupportRequest_getCommentPostList())
document_type_list = portal.getPortalDocumentTypeList()
event_list = portal.portal_simulation.getMovementHistoryList(
security_query=portal.portal_catalog.getSecurityQuery(),
portal_type=portal.getPortalEventTypeList(),
strict_follow_up_uid=context.getUid(),
simulation_state=('started', 'stopped', 'delivered', ),
only_accountable=False,
omit_input=True,
sort_on=(('date', 'asc'), ('uid', 'asc',),)
)
comment_list = []
for event in event_list:
event = event.getObject()
attachment_link = attachment_name = None
attachment = event.getDefaultAggregateValue(portal_type=document_type_list)
if attachment is not None:
attachment_link, attachment_name = attachment.getRelativeUrl(), attachment.getFilename()
comment_list.append((dict(
user=event.getSourceTitle(),
date=event.getStartDate().ISO8601(),
text=event.asStrippedHTML(),
attachment_link=attachment_link,
attachment_name=attachment_name,
message_id=event.getSourceReference(),
)))
just_posted_comment = portal.portal_sessions[
'%s.latest_comment' % context.getRelativeUrl()].pop(
'comment_post_list', None)
if just_posted_comment is not None:
# make sure not to display twice if it was already ingested in the meantime.
if just_posted_comment['message_id'] not in [comment['message_id'] for comment in comment_list]:
comment_list.append(just_posted_comment)
return dumps(comment_list)
portal = context.getPortalObject() comment_list = context.SupportRequest_getCommentPostList()
if comment_list:
# get the related Support Request, this should not be None return comment_list[-1]['user']
support_request_list = portal.portal_catalog(portal_type="Support Request", id=context.getId()) # with id keyword, this function will return a sequence data type which contains one element.
support_request_object = support_request_list[0].getObject()
# get the all HTML Posts which related to this Support Request
post_list = portal.portal_catalog(portal_type="HTML Post", strict_follow_up_uid=support_request_object.getUid(), sort_on=(('modification_date', 'descending'),), limit=1, validation_state="published") # with id keyword, this function will return a sequence data type which contains one element.
if len(post_list):
return post_list[0].Base_getOwnerTitle()
else:
return None
portal = context.getPortalObject() from DateTime import DateTime
comment_list = context.SupportRequest_getCommentPostList()
# get the related Support Request, this should not be None if comment_list:
support_request_list = portal.portal_catalog(portal_type="Support Request", id=context.getId()) # with id keyword, this function will return a sequence data type which contains one element. return DateTime(comment_list[-1]['date'])
support_request_object = support_request_list[0].getObject()
# get the all HTML Posts which related to this Support Request
post_list = portal.portal_catalog(portal_type="HTML Post", strict_follow_up_uid=support_request_object.getUid()) # with id keyword, this function will return a sequence data type which contains one element.
post_list = sorted(post_list, key=lambda x:x.getStartDate(), reverse=True)
preferred_date_order = portal.portal_preferences.getPreferredDateOrder()
if post_list:
# raise NotImplementedError(post_list[0].getStartDate())
post_date = post_list[0].getStartDate()
if is_pure_date:
return post_date
# raise NotImplementedError(post_date.strftime("%H:%M:%S"))
if post_date.isCurrentDay():
return post_date.strftime("%H:%M:%S")
else:
if preferred_date_order == 'dmy':
return "%s/%s/%s" % (post_date.dd(), post_date.mm(), post_date.year())
if preferred_date_order == 'mdy':
return "%s/%s/%s" % (post_date.mm(), post_date.dd(), post_date.year())
# ymd
return "%s/%s/%s" % (post_date.year(), post_date.mm(), post_date.dd())
else:
return None
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>is_pure_date=False</string> </value> <value> <string></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