1.1 --- a/imiptools/period.py Sun Aug 02 00:11:39 2015 +0200
1.2 +++ b/imiptools/period.py Sun Aug 02 01:04:59 2015 +0200
1.3 @@ -103,6 +103,40 @@
1.4 def get_end_point(self):
1.5 return to_utc_datetime(self.get_end(), self.get_tzid())
1.6
1.7 + # Period and event recurrence logic.
1.8 +
1.9 + def is_replaced(self, recurrenceids):
1.10 +
1.11 + """
1.12 + Return whether this period refers to one of the 'recurrenceids'.
1.13 + The 'recurrenceids' should be normalised to UTC datetimes according to
1.14 + time zone information provided by their objects or be floating dates or
1.15 + datetimes requiring conversion using contextual time zone information.
1.16 + """
1.17 +
1.18 + for recurrenceid in recurrenceids:
1.19 + if self.is_affected(period, recurrenceid):
1.20 + return recurrenceid
1.21 + return None
1.22 +
1.23 + def is_affected(self, recurrenceid):
1.24 +
1.25 + """
1.26 + Return whether this period refers to 'recurrenceid'. The 'recurrenceid'
1.27 + should be normalised to UTC datetimes according to time zone information
1.28 + provided by their objects. Otherwise, this period's contextual time zone
1.29 + information is used to convert any date or floating datetime
1.30 + representation to a point in time.
1.31 + """
1.32 +
1.33 + if not recurrenceid:
1.34 + return None
1.35 + d = get_recurrence_start(recurrenceid)
1.36 + dt = get_recurrence_start_point(recurrenceid, self.tzid)
1.37 + if self.get_start() == d or self.get_start_point() == dt:
1.38 + return recurrenceid
1.39 + return None
1.40 +
1.41 class FreeBusyPeriod(Period):
1.42
1.43 "A free/busy record abstraction."
1.44 @@ -183,39 +217,6 @@
1.45 def __repr__(self):
1.46 return "RecurringPeriod%r" % (self.as_tuple(),)
1.47
1.48 -# Period and event recurrence logic.
1.49 -
1.50 -def is_replaced(period, recurrenceids, tzid):
1.51 -
1.52 - """
1.53 - Return whether 'period' refers to one of the 'recurrenceids', interpreted
1.54 - using 'tzid' if necessary. The 'recurrenceids' should be normalised to UTC
1.55 - datetimes according to time zone information provided by their objects.
1.56 - """
1.57 -
1.58 - for s in recurrenceids:
1.59 - if is_affected(period, s, tzid):
1.60 - return s
1.61 - return None
1.62 -
1.63 -def is_affected(period, recurrenceid, tzid):
1.64 -
1.65 - """
1.66 - Return whether 'period' refers to 'recurrenceid', interpreted using 'tzid'
1.67 - if necessary. The 'recurrenceid' should be normalised to UTC datetimes
1.68 - according to time zone information provided by their objects. Otherwise,
1.69 - 'tzid' is used to convert any date or floating datetime representation to a
1.70 - point in time.
1.71 - """
1.72 -
1.73 - if not recurrenceid:
1.74 - return None
1.75 - d = get_recurrence_start(recurrenceid)
1.76 - dt = get_recurrence_start_point(recurrenceid, tzid)
1.77 - if period.get_start() == d or period.get_start_point() == dt:
1.78 - return recurrenceid
1.79 - return None
1.80 -
1.81 # Time and period management.
1.82
1.83 def can_schedule(freebusy, periods, uid, recurrenceid):
1.84 @@ -340,7 +341,7 @@
1.85 # Find the range of periods potentially overlapping the period in the
1.86 # free/busy collection.
1.87
1.88 - last = bisect_right(freebusy, Period(period.get_end(), period.get_end(), period.get_tzid()))
1.89 + last = bisect_right(freebusy, Period(period.get_end(), period.get_end(), period.tzid))
1.90 startpoints = freebusy[:last]
1.91
1.92 # Find the range of periods potentially overlapping the period in a version
1.93 @@ -663,6 +664,6 @@
1.94 remove_period(freebusy, uid, recurrenceid)
1.95
1.96 for p in periods:
1.97 - insert_period(freebusy, FreeBusyPeriod(p.get_start(), p.get_end(), uid, transp, recurrenceid, summary, organiser, p.get_tzid()))
1.98 + insert_period(freebusy, FreeBusyPeriod(p.get_start(), p.get_end(), uid, transp, recurrenceid, summary, organiser, p.tzid))
1.99
1.100 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/imipweb/event.py Sun Aug 02 00:11:39 2015 +0200
2.2 +++ b/imipweb/event.py Sun Aug 02 01:04:59 2015 +0200
2.3 @@ -493,7 +493,7 @@
2.4
2.5 recurrenceid = obj.get_recurrenceid()
2.6 recurrenceids = self._get_recurrences(uid)
2.7 - replaced = not recurrenceid and self.is_replaced(p, recurrenceids)
2.8 + replaced = not recurrenceid and p.is_replaced(recurrenceids)
2.9
2.10 # Provide a summary of the object.
2.11
2.12 @@ -743,7 +743,7 @@
2.13 args = self.env.get_args()
2.14
2.15 p = event_period_from_period(period)
2.16 - replaced = not recurrenceid and self.is_replaced(p, recurrenceids)
2.17 + replaced = not recurrenceid and p.is_replaced(recurrenceids)
2.18
2.19 # Isolate the controls from neighbouring tables.
2.20
2.21 @@ -830,7 +830,7 @@
2.22 partstat = participant_attr and participant_attr.get("PARTSTAT")
2.23
2.24 for p in have_conflict(freebusy, periods, True):
2.25 - if not recurrenceid and self.is_replaced(p, recurrenceids):
2.26 + if not recurrenceid and p.is_replaced(recurrenceids):
2.27 continue
2.28
2.29 if ( # Unidentified or different event
2.30 @@ -1000,7 +1000,7 @@
2.31 _name = self.element_name
2.32
2.33 p = event_period_from_period(period)
2.34 - replaced = not recurrenceid and self.is_replaced(p, recurrenceids)
2.35 + replaced = not recurrenceid and p.is_replaced(recurrenceids)
2.36
2.37 # Show controls for editing as organiser.
2.38
2.39 @@ -1055,11 +1055,11 @@
2.40 page = self.page
2.41
2.42 p = event_period_from_period(period)
2.43 - replaced = not recurrenceid and self.is_replaced(p, recurrenceids)
2.44 + replaced = not recurrenceid and p.is_replaced(recurrenceids)
2.45
2.46 css = " ".join([
2.47 replaced and "replaced" or "",
2.48 - self.is_affected(p, recurrenceid) and "affected" or ""
2.49 + p.is_affected(recurrenceid) and "affected" or ""
2.50 ])
2.51
2.52 formdate = show_start and p.get_form_start() or p.get_form_end()
3.1 --- a/imipweb/resource.py Sun Aug 02 00:11:39 2015 +0200
3.2 +++ b/imipweb/resource.py Sun Aug 02 01:04:59 2015 +0200
3.3 @@ -23,8 +23,7 @@
3.4 from imiptools.client import Client
3.5 from imiptools.data import get_uri, uri_values
3.6 from imiptools.dates import get_recurrence_start_point
3.7 -from imiptools.period import FreeBusyPeriod, is_affected, is_replaced, \
3.8 - remove_period, remove_affected_period
3.9 +from imiptools.period import FreeBusyPeriod, remove_period, remove_affected_period
3.10 from imipweb.env import CGIEnvironment
3.11 import babel.dates
3.12 import imip_store
3.13 @@ -154,18 +153,10 @@
3.14 recurrenceid,
3.15 obj.get_value("SUMMARY"),
3.16 obj.get_value("ORGANIZER"),
3.17 - p.get_tzid()
3.18 + p.tzid
3.19 ))
3.20 return summary
3.21
3.22 - # Period and recurrence testing.
3.23 -
3.24 - def is_replaced(self, period, recurrenceids):
3.25 - return is_replaced(period, recurrenceids, self.get_tzid())
3.26 -
3.27 - def is_affected(self, period, recurrenceid):
3.28 - return is_affected(period, recurrenceid, self.get_tzid())
3.29 -
3.30 # Preference methods.
3.31
3.32 def get_user_locale(self):