Commit 0bb24217 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_rss_style: Refactor base RSS queries

   Reduce the number of scripts and refactor the query script to rely on getMovementHistory.

   Before only the latest event was notified, to reduce the list and only to ping the user to access the site. Now all events are considered on the list (not the latest ones) and include some general clean up on base RSS feeds.
parent c27cce14
kw['simulation_state'] = ['validated','submitted', 'suspended', 'invalidated',
"""Returns all ticket related events for RSS from a given module
"""
from Products.PythonScripts.standard import Object
portal = context.getPortalObject()
# for safety, we limit at 100 lines
list_lines = min(list_lines, 100)
getTicket_memo = {}
def getTicketInfo(event):
follow_up = event.getFollowUp()
try:
return getTicket_memo[follow_up]
except KeyError:
ticket = portal.restrictedTraverse(follow_up, None)
if ticket is None:
# For corner cases where user has an event for which he cannot access the ticket,
# we don't raise error so that others events are visible.
return event.getTitle(), '', ''
getTicket_memo[follow_up] = (
ticket.getTitle(),
ticket.getResourceTranslatedTitle() or '',
ticket.Base_getTicketUrl(),
)
return getTicket_memo[follow_up]
data_list = []
for brain in portal.portal_simulation.getMovementHistoryList(
security_query=portal.portal_catalog.getSecurityQuery(),
# Limit only to listable portal types
portal_type=['Web Message', 'Mail Nessage'],
follow_up_simulation_state = ['validated','submitted', 'suspended', 'invalidated',
# Unfortunally Upgrade decision uses diferent states.
'confirmed', 'delivered']
kw['sort_on'] = [('modification_date', 'DESC'),]
return context.searchFolder(**kw)
'confirmed', 'started', 'stopped', 'delivered'],
only_accountable=False,
# Only query by portal types of the module
follow_up_portal_type=context.getVisibleAllowedContentTypeList(),
omit_input=True,
simulation_state=('started', 'stopped', 'delivered'),
limit=list_lines,
sort_on=(('stock.date', 'desc'),
('uid', 'desc')),):
event = brain.getObject()
(ticket_title,
ticket_category,
ticket_link) = getTicketInfo(event)
data_list.append(
Object(**{
'title': ticket_title,
'category': ticket_category,
'author': brain.node_title,
'link': ticket_link,
'description': event.Event_getRSSTextContent(),
'pubDate': brain.date,
'guid': '{}-{}'.format(
event.getFollowUp(),
event.getRelativeUrl()),
'thumbnail': ( None)
})
)
return data_list
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
<value> <string>list_lines=50, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -37,6 +37,10 @@
<key> <string>action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>action_title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
......@@ -79,11 +83,7 @@
<item>
<key> <string>hidden</string> </key>
<value>
<list>
<string>listbox_modification_date</string>
<string>listbox_title</string>
<string>listbox_description</string>
</list>
<list/>
</value>
</item>
</dictionary>
......@@ -99,7 +99,7 @@
</item>
<item>
<key> <string>name</string> </key>
<value> <string>WebSection_viewMonitoringSupportRequestList</string> </value>
<value> <string>Folder_viewOpenTicketList</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
......@@ -115,7 +115,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>View Monitoring Support Request List</string> </value>
<value> <string>RSS Feed</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
......
......@@ -90,9 +90,7 @@
</item>
<item>
<key> <string>lines</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
<value> <string></string> </value>
</item>
<item>
<key> <string>list_method</string> </key>
......@@ -101,7 +99,7 @@
<item>
<key> <string>selection_name</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
......@@ -125,15 +123,31 @@
<list>
<tuple>
<string>title</string>
<string>Title</string>
<string>title</string>
</tuple>
<tuple>
<string>modification_date</string>
<string>guid</string>
<string>guid</string>
</tuple>
<tuple>
<string>pubDate</string>
<string>pubDate</string>
</tuple>
<tuple>
<string>description</string>
<string>Description</string>
<string>summary</string>
</tuple>
<tuple>
<string>link</string>
<string>link</string>
</tuple>
<tuple>
<string>author</string>
<string>author</string>
</tuple>
<tuple>
<string>thumbnail</string>
<string>thumbnail</string>
</tuple>
</list>
</value>
......@@ -181,12 +195,12 @@
</item>
<item>
<key> <string>lines</string> </key>
<value> <int>20</int> </value>
<value> <int>50</int> </value>
</item>
<item>
<key> <string>list_method</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
......@@ -210,19 +224,6 @@
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: int(here.REQUEST.get(\'size\', preferences.getPreference(\'preferred_listbox_list_mode_line_count\', 30)))</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
......@@ -235,7 +236,7 @@
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="Method" module="Products.Formulator.MethodField"/>
</pickle>
......
from Products.ERP5Type.Cache import CachingMethod
portal = context.getPortalObject()
def getLastEventRelativeUrl(uid):
portal = context.getPortalObject()
last_event = portal.portal_catalog.getResultValue(
follow_up_uid=context.getUid(),
portal_type=portal.getPortalEventTypeList(),
simulation_state=["confirmed", "started", "stopped", "delivered"],
sort_on=(("modification_date", 'DESC'),))
if last_event is not None:
return last_event.getRelativeUrl()
else:
return last_event
last_event_url = CachingMethod(getLastEventRelativeUrl,
id='Ticket_getLatestEventRelativeUrl',
cache_factory='erp5_content_short')(context.getUid())
if last_event_url is not None:
return portal.restrictedTraverse(last_event_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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Ticket_getLatestEvent</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
latest_event_relative_url = ''
latest_event = context.Ticket_getLatestEvent()
if latest_event:
latest_event_relative_url = latest_event.getRelativeUrl()
return '{}-{}'.format(
context.getRelativeUrl(),
latest_event_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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Ticket_getRSSGuid</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
kw['portal_type'] = ["Support Request", "Regularisation Request", "Upgrade Decision"]
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person:
kw['default_destination_decision_uid'] = person.getUid()
kw['simulation_state'] = "NOT cancelled"
kw['sort_on'] = (('modification_date', 'DESC'),)
kw['limit'] = 50
return portal.portal_catalog(**kw)
else:
return []
<?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>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSection_getUserCriticalTicketList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""Returns all ticket related events for RSS
"""
from Products.PythonScripts.standard import Object
portal = context.getPortalObject()
kw['portal_type'] = ["Support Request", "Regularisation Request", "Upgrade Decision"]
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person:
kw['default_destination_decision_uid'] = person.getUid()
kw['simulation_state'] = "NOT cancelled"
kw['sort_on'] = (('modification_date', 'DESC'),)
kw['limit'] = 50
# for safety, we limit at 100 lines
list_lines = min(list_lines, 100)
return portal.portal_catalog(**kw)
getTicket_memo = {}
def getTicketInfo(event):
follow_up = event.getFollowUp()
try:
return getTicket_memo[follow_up]
except KeyError:
ticket = portal.restrictedTraverse(follow_up, None)
if ticket is None:
# For corner cases where user has an event for which he cannot access the ticket,
# we don't raise error so that others events are visible.
return event.getTitle(), '', ''
getTicket_memo[follow_up] = (
ticket.getTitle(),
ticket.getResourceTranslatedTitle() or '',
ticket.Base_getTicketUrl(),
)
return getTicket_memo[follow_up]
else:
return []
data_list = []
for brain in portal.portal_simulation.getMovementHistoryList(
security_query=portal.portal_catalog.getSecurityQuery(),
# Limit only to listable portal types
portal_type=['Web Message', 'Mail Nessage'],
follow_up_simulation_state="NOT cancelled",
only_accountable=False,
follow_up_portal_type=['Support Request', 'Regularisation Request', 'Upgrade Decision'],
omit_input=True,
simulation_state=('started', 'stopped', 'delivered'),
limit=list_lines,
sort_on=(('stock.date', 'desc'),
('uid', 'desc')),):
event = brain.getObject()
(ticket_title,
ticket_category,
ticket_link) = getTicketInfo(event)
data_list.append(
Object(**{
'title': ticket_title,
'category': ticket_category,
'author': brain.node_title,
'link': ticket_link,
'description': event.getTextContent(),
'pubDate': brain.date,
'guid': '{}-{}'.format(
event.getFollowUp(),
event.getRelativeUrl()),
'thumbnail': ( None)
})
)
return data_list
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
<value> <string>list_lines=50, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -79,11 +79,7 @@
<item>
<key> <string>hidden</string> </key>
<value>
<list>
<string>listbox_modification_date</string>
<string>listbox_title</string>
<string>listbox_description</string>
</list>
<list/>
</value>
</item>
</dictionary>
......
......@@ -128,20 +128,28 @@
<string>Title</string>
</tuple>
<tuple>
<string>Ticket_getRSSGuid</string>
<string>guid</string>
<string>guid</string>
</tuple>
<tuple>
<string>modification_date</string>
<string>pubDate</string>
<string>pubDate</string>
</tuple>
<tuple>
<string>description</string>
<string>Description</string>
<string>description</string>
</tuple>
<tuple>
<string>Base_getTicketUrl</string>
<string>link</string>
<string>link</string>
</tuple>
<tuple>
<string>author</string>
<string>author</string>
</tuple>
<tuple>
<string>thumbnail</string>
<string>thumbnail</string>
</tuple>
</list>
</value>
......@@ -159,20 +167,7 @@
<item>
<key> <string>editable_columns</string> </key>
<value>
<list>
<tuple>
<string>title</string>
<string>Title</string>
</tuple>
<tuple>
<string>modification_date</string>
<string>modification_date</string>
</tuple>
<tuple>
<string>description</string>
<string>description</string>
</tuple>
</list>
<list/>
</value>
</item>
<item>
......@@ -251,7 +246,7 @@
<dictionary>
<item>
<key> <string>method_name</string> </key>
<value> <string>WebSection_getUserCriticalTicketList</string> </value>
<value> <string>WebSection_getUserTicketList</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -79,11 +79,7 @@
<item>
<key> <string>hidden</string> </key>
<value>
<list>
<string>listbox_modification_date</string>
<string>listbox_title</string>
<string>listbox_description</string>
</list>
<list/>
</value>
</item>
</dictionary>
......
......@@ -128,11 +128,11 @@
<string>Title</string>
</tuple>
<tuple>
<string>Ticket_getRSSGuid</string>
<string>guid</string>
<string>guid</string>
</tuple>
<tuple>
<string>modification_date</string>
<string>pubDate</string>
<string>pubDate</string>
</tuple>
<tuple>
......@@ -140,8 +140,16 @@
<string>Description</string>
</tuple>
<tuple>
<string>Base_getTicketUrl</string>
<string>link</string>
<string>link</string>
</tuple>
<tuple>
<string>author</string>
<string>author</string>
</tuple>
<tuple>
<string>thumbnail</string>
<string>thumbnail</string>
</tuple>
</list>
</value>
......@@ -159,20 +167,7 @@
<item>
<key> <string>editable_columns</string> </key>
<value>
<list>
<tuple>
<string>title</string>
<string>Title</string>
</tuple>
<tuple>
<string>modification_date</string>
<string>modification_date</string>
</tuple>
<tuple>
<string>description</string>
<string>description</string>
</tuple>
</list>
<list/>
</value>
</item>
<item>
......
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