Commit da17232a authored by Aurel's avatar Aurel

add method isSuscribed to know if alarm tool is suscribed to timer service or not


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7666 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eb72769a
...@@ -47,8 +47,8 @@ except ImportError: ...@@ -47,8 +47,8 @@ except ImportError:
class AlarmTool(BaseTool): class AlarmTool(BaseTool):
""" """
This tool manages alarms. This tool manages alarms.
It is used as a central managment point for all alarms. It is used as a central managment point for all alarms.
Inside this tool we have a way to retrieve all reports comings Inside this tool we have a way to retrieve all reports comings
...@@ -68,12 +68,20 @@ class AlarmTool(BaseTool): ...@@ -68,12 +68,20 @@ class AlarmTool(BaseTool):
security.declareProtected( Permissions.ManagePortal , 'manageAlarmList' ) security.declareProtected( Permissions.ManagePortal , 'manageAlarmList' )
manageAlarmList = DTMLFile( 'manageAlarmList', _dtmldir ) manageAlarmList = DTMLFile( 'manageAlarmList', _dtmldir )
security.declareProtected( Permissions.ManagePortal , 'manageAlarmAdvanced' )
manageAlarmAdvanced = DTMLFile( 'manageAlarmAdvanced', _dtmldir )
manage_options = ( ( { 'label' : 'Overview' manage_options = ( ( { 'label' : 'Overview'
, 'action' : 'manage_overview' , 'action' : 'manage_overview'
} }
, { 'label' : 'All Alarms' , { 'label' : 'All Alarms'
, 'action' : 'manageAlarmList' , 'action' : 'manageAlarmList'
} }
, { 'label' : 'Advanced'
, 'action' : 'manageAlarmAdvanced'
}
,
) )
+ Folder.manage_options + Folder.manage_options
) )
...@@ -133,11 +141,27 @@ class AlarmTool(BaseTool): ...@@ -133,11 +141,27 @@ class AlarmTool(BaseTool):
if alarm: if alarm:
user = alarm.getOwner() user = alarm.getOwner()
newSecurityManager(self.REQUEST, user) newSecurityManager(self.REQUEST, user)
if alarm.isActive() or not alarm.isEnabled(): if alarm.isActive() or not alarm.isEnabled():
# do nothing if already active, or not enabled # do nothing if already active, or not enabled
continue continue
alarm.activate().activeSense() alarm.activate().activeSense()
security.declareProtected(Permissions.ManageProperties, 'isSubscribed')
def isSubscribed(self):
"""
return True, if we are subscribed to TimerService.
Otherwise return False.
"""
service = getTimerService(self)
if not service:
LOG('AlarmTool', INFO, 'TimerService not available')
return False
path = '/'.join(self.getPhysicalPath())
if path in service.lisSubscriptions():
return True
return False
security.declareProtected(Permissions.ManageProperties, 'subscribe') security.declareProtected(Permissions.ManageProperties, 'subscribe')
def subscribe(self): def subscribe(self):
""" """
...@@ -165,13 +189,13 @@ class AlarmTool(BaseTool): ...@@ -165,13 +189,13 @@ class AlarmTool(BaseTool):
def manage_beforeDelete(self, item, container): def manage_beforeDelete(self, item, container):
self.unsubscribe() self.unsubscribe()
BaseTool.inheritedAttribute('manage_beforeDelete')(self, item, container) BaseTool.inheritedAttribute('manage_beforeDelete')(self, item, container)
def manage_afterAdd(self, item, container): def manage_afterAdd(self, item, container):
self.subscribe() self.subscribe()
BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container) BaseTool.inheritedAttribute('manage_afterAdd')(self, item, container)
def process_timer(self, tick, interval, prev="", next=""): def process_timer(self, tick, interval, prev="", next=""):
""" """
Call tic() every x seconds. x is defined in self.interval Call tic() every x seconds. x is defined in self.interval
This method is called by TimerService in the interval given This method is called by TimerService in the interval given
in zope.conf. The Default is every 5 seconds. in zope.conf. The Default is every 5 seconds.
......
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