Commit 36ec65be authored by Vincent Pelletier's avatar Vincent Pelletier

Improve docstrings.

Respect 80 columns limit.
Remove erroneous activation of alarms.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6899 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1e606522
...@@ -47,11 +47,11 @@ except ImportError: ...@@ -47,11 +47,11 @@ except ImportError:
class AlarmTool(BaseTool): class AlarmTool(BaseTool):
""" """
This tool will be usefull to manage alarms. There's This tool manages alarms.
alarms everywhere in ERP5, and it is a nice idea to be able
to manage all of them from a central point.
Inside this tool we will have a way to retrieve all reports comings It is used as a central managment point for all alarms.
Inside this tool we have a way to retrieve all reports comings
from Alarms,... from Alarms,...
""" """
id = 'portal_alarms' id = 'portal_alarms'
...@@ -80,18 +80,18 @@ class AlarmTool(BaseTool): ...@@ -80,18 +80,18 @@ class AlarmTool(BaseTool):
interval = 60 # Default interval for alarms is 60 seconds interval = 60 # Default interval for alarms is 60 seconds
last_tic = time.time() last_tic = time.time()
# Factory Type Information # Factory Type Information
factory_type_information = \ factory_type_information = \
{ 'id' : portal_type { 'id' : portal_type
, 'meta_type' : meta_type , 'meta_type' : meta_type
, 'description' : """\ , 'description' : """AlarmTool manages alarms."""
TemplateTool manages Business Templates."""
, 'icon' : 'folder_icon.gif' , 'icon' : 'folder_icon.gif'
, 'product' : 'ERP5Type' , 'product' : 'ERP5Type'
, 'factory' : 'addFolder' , 'factory' : 'addFolder'
, 'immediate_view' : 'Folder_viewContentList' , 'immediate_view' : 'Folder_viewContentList'
, 'allow_discussion' : 1 , 'allow_discussion' : 1
, 'allowed_content_types': ('Business Template',) , 'allowed_content_types': ()
, 'filter_content_types' : 1 , 'filter_content_types' : 1
, 'global_allow' : 1 , 'global_allow' : 1
, 'actions' : , 'actions' :
...@@ -99,26 +99,22 @@ TemplateTool manages Business Templates.""" ...@@ -99,26 +99,22 @@ TemplateTool manages Business Templates."""
, 'name' : 'View' , 'name' : 'View'
, 'category' : 'object_view' , 'category' : 'object_view'
, 'action' : 'Folder_viewContentList' , 'action' : 'Folder_viewContentList'
, 'permissions' : ( , 'permissions' : ( Permissions.View, )
Permissions.View, )
}, },
) )
} }
# API to manage alarms # API to manage alarms
""" # Aim of this API:
This is what we should do: #-- see all alarms stored everywhere
#-- defines global alarms
-- be able to see all alarms stored everywhere #-- activate an alarm
-- defines global alarms #-- see reports
-- activate an alarm #-- see active alarms
-- see reports #-- retrieve all alarms
-- see active alarms
-- retrieve all alarms
"""
security.declareProtected(Permissions.ModifyPortalContent, 'getAlarmList') security.declareProtected(Permissions.ModifyPortalContent, 'getAlarmList')
def getAlarmList(self,to_active=0): def getAlarmList(self, to_active = 0):
""" """
We retrieve thanks to the catalog the full list of alarms We retrieve thanks to the catalog the full list of alarms
""" """
...@@ -127,19 +123,25 @@ TemplateTool manages Business Templates.""" ...@@ -127,19 +123,25 @@ TemplateTool manages Business Templates."""
if to_active: if to_active:
now = str(DateTime()) now = str(DateTime())
date_expression = '<= %s' % now date_expression = '<= %s' % now
catalog_search = self.portal_catalog(portal_type = self.getPortalAlarmTypeList(), alarm_date=date_expression) catalog_search = self.portal_catalog(portal_type = \
self.getPortalAlarmTypeList(), alarm_date = date_expression)
else: else:
catalog_search = self.portal_catalog(portal_type = self.getPortalAlarmTypeList()) catalog_search = self.portal_catalog(portal_type = \
self.getPortalAlarmTypeList())
alarm_list = map(lambda x:x.getObject(),catalog_search) alarm_list = map(lambda x:x.getObject(),catalog_search)
# LOG('AlarmTool.getAlarmList, alarm_list',0,alarm_list)
if to_active: if to_active:
now = DateTime() now = DateTime()
date_expression = '<= %s' % str(now) date_expression = '<= %s' % str(now)
catalog_search = self.portal_catalog(portal_type = self.getPortalAlarmTypeList(), alarm_date=date_expression) catalog_search = self.portal_catalog(
portal_type = self.getPortalAlarmTypeList(), alarm_date=date_expression
)
# check again the alarm date in case the alarm was not yet reindexed # check again the alarm date in case the alarm was not yet reindexed
alarm_list = [x.getObject() for x in catalog_search if x.getObject().getAlarmDate()<=now] alarm_list = [x.getObject() for x in catalog_search \
if x.getObject().getAlarmDate()<=now]
else: else:
catalog_search = self.portal_catalog(portal_type = self.getPortalAlarmTypeList()) catalog_search = self.portal_catalog(
portal_type = self.getPortalAlarmTypeList()
)
alarm_list = map(lambda x:x.getObject(),catalog_search) alarm_list = map(lambda x:x.getObject(),catalog_search)
return alarm_list return alarm_list
...@@ -161,23 +163,25 @@ TemplateTool manages Business Templates.""" ...@@ -161,23 +163,25 @@ TemplateTool manages Business Templates."""
security.declareProtected(Permissions.ManageProperties, 'subscribe') security.declareProtected(Permissions.ManageProperties, 'subscribe')
def subscribe(self): def subscribe(self):
""" subscribe to the global Timer Service """ """
Subscribe to the global Timer Service.
"""
service = getTimerService(self) service = getTimerService(self)
if not service: if not service:
LOG('AlarmTool', INFO, 'TimerService not available') LOG('AlarmTool', INFO, 'TimerService not available')
return return
service.subscribe(self) service.subscribe(self)
return "Subscribed to Timer Service" return "Subscribed to Timer Service"
security.declareProtected(Permissions.ManageProperties, 'unsubscribe') security.declareProtected(Permissions.ManageProperties, 'unsubscribe')
def unsubscribe(self): def unsubscribe(self):
""" unsubscribe from the global Timer Service """ """
Unsubscribe from the global Timer Service.
"""
service = getTimerService(self) service = getTimerService(self)
if not service: if not service:
LOG('AlarmTool', INFO, 'TimerService not available') LOG('AlarmTool', INFO, 'TimerService not available')
return return
service.unsubscribe(self) service.unsubscribe(self)
return "Usubscribed from Timer Service" return "Usubscribed from Timer Service"
...@@ -198,9 +202,4 @@ TemplateTool manages Business Templates.""" ...@@ -198,9 +202,4 @@ TemplateTool manages Business Templates."""
if tick - self.last_tic >= self.interval: if tick - self.last_tic >= self.interval:
self.tic() self.tic()
self.last_tic = tick self.last_tic = tick
for alarm in self.getAlarmList(to_active=1):
if alarm.isActive() or not alarm.isEnabled():
# do nothing if already active, or not enabled
continue
alarm.activate().activeSense()
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