Commit b9c74460 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Make some refactoring for the following purposes:

- if an alarm is not enabled, it should not be effective
- if an alarm is expired, it should not be effective
- an alarm should not be invoked only because it gets enabled




git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30362 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0de71363
...@@ -151,13 +151,16 @@ class PeriodicityMixin: ...@@ -151,13 +151,16 @@ class PeriodicityMixin:
Ex: here, we use minute as smaller duration. Ex: here, we use minute as smaller duration.
On CalendarPeriod, day is the smaller duration. On CalendarPeriod, day is the smaller duration.
""" """
periodicity_stop_date = self.getPeriodicityStopDate()
if next_start_date is None: if next_start_date is None:
next_start_date = current_date next_start_date = current_date
if next_start_date > current_date: if next_start_date > current_date \
return or (periodicity_stop_date is not None \
and next_start_date >= periodicity_stop_date):
return None
else: else:
# Make sure the old date is not too far away # Make sure the old date is not too far away
day_count = int(current_date-next_start_date) day_count = int(current_date - next_start_date)
next_start_date = next_start_date + day_count next_start_date = next_start_date + day_count
previous_date = next_start_date previous_date = next_start_date
...@@ -544,38 +547,61 @@ Alarm Tool Node: %s ...@@ -544,38 +547,61 @@ Alarm Tool Node: %s
security.declareProtected(Permissions.ModifyPortalContent, 'setNextAlarmDate') security.declareProtected(Permissions.ModifyPortalContent, 'setNextAlarmDate')
def setNextAlarmDate(self, current_date=None): def setNextAlarmDate(self, current_date=None):
"""Save the next alarm date.
""" """
Save the next alarm date alarm_date = self.getAlarmDate()
""" if alarm_date is not None:
if self.getPeriodicityStartDate() is None:
return
next_start_date = self.getAlarmDate()
if current_date is None: if current_date is None:
# This is usefull to set the current date as parameter for # This is usefull to set the current date as parameter for
# unit testing, by default it should be now # unit testing, by default it should be now
current_date = DateTime() current_date = DateTime()
alarm_date = self.getNextPeriodicalDate(current_date,
next_start_date = self.getNextPeriodicalDate(current_date, next_start_date=alarm_date)
next_start_date=next_start_date) self.Alarm_zUpdateAlarmDate(uid=self.getUid(), alarm_date=alarm_date)
if next_start_date is not None:
self.Alarm_zUpdateAlarmDate(uid=self.getUid(),
alarm_date=next_start_date)
security.declareProtected(Permissions.AccessContentsInformation, 'getAlarmDate') security.declareProtected(Permissions.AccessContentsInformation, 'getAlarmDate')
def getAlarmDate(self): def getAlarmDate(self):
"""Obtain the next alarm date.
Return a DateTime object which specifies when this alarm should
be invoked at next time. The return value can be None when it should
not be invoked automatically.
By definition, if periodicity start date is not defined (i.e. None),
their is no valid time range, so return None. If periodicity stop
date is not defined (i.e. None), assume that this alarm will be
effective forever. Otherwise, if a date exceeds the periodicity stop
date, return None, as it is not effective any longer.
""" """
returns something like ['Sunday','Monday',...] alarm_date = None
""" enabled = self.getEnabled()
alarm_date=None periodicity_start_date = self.getPeriodicityStartDate()
# No periodicity start date, return None if enabled and periodicity_start_date is not None:
if self.getPeriodicityStartDate() is not None: # Respect what is stored in the catalog.
result_list = self.Alarm_zGetAlarmDate(uid=self.getUid()) result_list = self.Alarm_zGetAlarmDate(uid=self.getUid())
if len(result_list)==1: if len(result_list) == 1:
alarm_date = result_list[0].alarm_date alarm_date = result_list[0].alarm_date
periodicity_start_date = self.getPeriodicityStartDate() # But if the catalog does not have a valid one, replace it
if alarm_date < periodicity_start_date: # with the start date.
if alarm_date is None or alarm_date < periodicity_start_date:
alarm_date = periodicity_start_date alarm_date = periodicity_start_date
# Check if it is valid.
periodicity_stop_date = self.getPeriodicityStopDate()
if periodicity_stop_date is not None \
and alarm_date >= periodicity_stop_date:
alarm_date = None
else:
# convert the date to the user provided timezone # convert the date to the user provided timezone
alarm_zone = periodicity_start_date.timezone() alarm_zone = periodicity_start_date.timezone()
alarm_date = alarm_date.toZone(alarm_zone) alarm_date = alarm_date.toZone(alarm_zone)
return alarm_date return alarm_date
# XXX there seem to be something which wants to call setters against
# alarm_date, but alarms do not want to store a date in ZODB.
security.declareProtected(Permissions.ModifyPortalContent, 'setAlarmDate')
def setAlarmDate(self, *args, **kw):
pass
def _setAlarmDate(self, *args, **kw):
pass
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