Commit 9332b823 authored by Vincent Pelletier's avatar Vincent Pelletier

Alarm: Assorted coding style improvements.

Especially, stop using getToolByName.
parent ecffced1
...@@ -35,7 +35,6 @@ from AccessControl.SecurityManagement import getSecurityManager, \ ...@@ -35,7 +35,6 @@ from AccessControl.SecurityManagement import getSecurityManager, \
setSecurityManager, newSecurityManager setSecurityManager, newSecurityManager
from AccessControl.User import nobody from AccessControl.User import nobody
from Products.CMFActivity.ActivityRuntimeEnvironment import getActivityRuntimeEnvironment from Products.CMFActivity.ActivityRuntimeEnvironment import getActivityRuntimeEnvironment
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
...@@ -107,10 +106,7 @@ class Alarm(XMLObject, PeriodicityMixin): ...@@ -107,10 +106,7 @@ class Alarm(XMLObject, PeriodicityMixin):
""" """
activate_kw = dict(activate_kw) activate_kw = dict(activate_kw)
portal_membership = self.getPortalObject().portal_membership if (fixit or not self.getEnabled()) and not self.getPortalObject().portal_membership.checkPermission(Permissions.ManagePortal, self):
if fixit or not self.getEnabled():
checkPermission = portal_membership.checkPermission
if not checkPermission(Permissions.ManagePortal, self):
raise Unauthorized('fixing problems or activating a disabled alarm is not allowed') raise Unauthorized('fixing problems or activating a disabled alarm is not allowed')
# Use UnrestrictedMethod, so that the behaviour would not # Use UnrestrictedMethod, so that the behaviour would not
...@@ -329,7 +325,8 @@ class Alarm(XMLObject, PeriodicityMixin): ...@@ -329,7 +325,8 @@ class Alarm(XMLObject, PeriodicityMixin):
else: else:
prefix = 'INFO' prefix = 'INFO'
notification_tool = getToolByName(self, 'portal_notifications') portal = self.getPortalObject()
notification_tool = portal.portal_notifications
candidate_list = self.getDestinationValueList() candidate_list = self.getDestinationValueList()
if not candidate_list: if not candidate_list:
candidate_list = None candidate_list = None
...@@ -352,7 +349,7 @@ class Alarm(XMLObject, PeriodicityMixin): ...@@ -352,7 +349,7 @@ class Alarm(XMLObject, PeriodicityMixin):
notification_tool.sendMessage(recipient=candidate_list, notification_tool.sendMessage(recipient=candidate_list,
subject='[%s][%s] Alarm Notification: %s' % subject='[%s][%s] Alarm Notification: %s' %
(prefix, self.getPortalObject().getTitle(), self.getTitle()), (prefix, portal.getTitle(), self.getTitle()),
message=""" message="""
Alarm Title: %s (%s) Alarm Title: %s (%s)
...@@ -361,7 +358,7 @@ Alarm Description: ...@@ -361,7 +358,7 @@ Alarm Description:
Alarm Tool Node: %s Alarm Tool Node: %s
""" % (self.getTitle(), self.getId(), self.getDescription(), """ % (self.getTitle(), self.getId(), self.getDescription(),
self.getPortalObject().portal_alarms.getAlarmNode()), portal.portal_alarms.getAlarmNode()),
attachment_list=attachment_list) attachment_list=attachment_list)
security.declareProtected(Permissions.ManagePortal, 'getLastActiveProcess') security.declareProtected(Permissions.ManagePortal, 'getLastActiveProcess')
...@@ -400,12 +397,12 @@ Alarm Tool Node: %s ...@@ -400,12 +397,12 @@ Alarm Tool Node: %s
pass pass
else: else:
activate_kw.setdefault('tag', activity_runtime_environment.getTag()) activate_kw.setdefault('tag', activity_runtime_environment.getTag())
portal_activities = getToolByName(self,'portal_activities') return self.getPortalObject().portal_activities.newActiveProcess(
active_process = portal_activities.newActiveProcess(start_date=DateTime(), start_date=DateTime(),
causality_value=self, causality_value=self,
activate_kw=activate_kw, activate_kw=activate_kw,
**kw) **kw
return active_process )
security.declareProtected(Permissions.ModifyPortalContent, 'setNextAlarmDate') security.declareProtected(Permissions.ModifyPortalContent, 'setNextAlarmDate')
def setNextAlarmDate(self, current_date=None): def setNextAlarmDate(self, current_date=None):
......
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