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:
class AlarmTool(BaseTool):
"""
This tool will be usefull to manage alarms. There's
alarms everywhere in ERP5, and it is a nice idea to be able
to manage all of them from a central point.
This tool manages alarms.
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,...
"""
id = 'portal_alarms'
......@@ -80,18 +80,18 @@ class AlarmTool(BaseTool):
interval = 60 # Default interval for alarms is 60 seconds
last_tic = time.time()
# Factory Type Information
factory_type_information = \
{ 'id' : portal_type
, 'meta_type' : meta_type
, 'description' : """\
TemplateTool manages Business Templates."""
, 'description' : """AlarmTool manages alarms."""
, 'icon' : 'folder_icon.gif'
, 'product' : 'ERP5Type'
, 'factory' : 'addFolder'
, 'immediate_view' : 'Folder_viewContentList'
, 'allow_discussion' : 1
, 'allowed_content_types': ('Business Template',)
, 'allowed_content_types': ()
, 'filter_content_types' : 1
, 'global_allow' : 1
, 'actions' :
......@@ -99,26 +99,22 @@ TemplateTool manages Business Templates."""
, 'name' : 'View'
, 'category' : 'object_view'
, 'action' : 'Folder_viewContentList'
, 'permissions' : (
Permissions.View, )
, 'permissions' : ( Permissions.View, )
},
)
}
# API to manage alarms
"""
This is what we should do:
-- be able to see all alarms stored everywhere
-- defines global alarms
-- activate an alarm
-- see reports
-- see active alarms
-- retrieve all alarms
"""
# Aim of this API:
#-- see all alarms stored everywhere
#-- defines global alarms
#-- activate an alarm
#-- see reports
#-- see active alarms
#-- retrieve all alarms
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
"""
......@@ -127,19 +123,25 @@ TemplateTool manages Business Templates."""
if to_active:
now = str(DateTime())
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:
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)
# LOG('AlarmTool.getAlarmList, alarm_list',0,alarm_list)
if to_active:
now = DateTime()
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
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:
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)
return alarm_list
......@@ -161,23 +163,25 @@ TemplateTool manages Business Templates."""
security.declareProtected(Permissions.ManageProperties, 'subscribe')
def subscribe(self):
""" subscribe to the global Timer Service """
"""
Subscribe to the global Timer Service.
"""
service = getTimerService(self)
if not service:
LOG('AlarmTool', INFO, 'TimerService not available')
return
service.subscribe(self)
return "Subscribed to Timer Service"
security.declareProtected(Permissions.ManageProperties, 'unsubscribe')
def unsubscribe(self):
""" unsubscribe from the global Timer Service """
"""
Unsubscribe from the global Timer Service.
"""
service = getTimerService(self)
if not service:
LOG('AlarmTool', INFO, 'TimerService not available')
return
service.unsubscribe(self)
return "Usubscribed from Timer Service"
......@@ -198,9 +202,4 @@ TemplateTool manages Business Templates."""
if tick - self.last_tic >= self.interval:
self.tic()
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