1.1 --- a/imiptools/freebusy/common.py Wed Jun 14 00:21:20 2017 +0200
1.2 +++ b/imiptools/freebusy/common.py Wed Jun 14 00:30:32 2017 +0200
1.3 @@ -644,6 +644,13 @@
1.4 if i < len(self.periods) and self.periods[i] == period:
1.5 del self.periods[i]
1.6
1.7 + def remove_periods_before(self, period):
1.8 +
1.9 + "Remove the entries in the collection before 'period'."
1.10 +
1.11 + last = bisect_right(self.periods, period)
1.12 + self.remove_periods(self.periods[:last])
1.13 +
1.14 def remove_event_periods(self, uid, recurrenceid=None, participant=None):
1.15
1.16 """
2.1 --- a/imiptools/freebusy/database.py Wed Jun 14 00:21:20 2017 +0200
2.2 +++ b/imiptools/freebusy/database.py Wed Jun 14 00:30:32 2017 +0200
2.3 @@ -183,6 +183,27 @@
2.4
2.5 self.cursor.execute(query, values)
2.6
2.7 + def remove_periods_before(self, period):
2.8 +
2.9 + "Remove the entries in the collection before 'period'."
2.10 +
2.11 + end = format_datetime(period.get_start_point())
2.12 +
2.13 + columns, values = [], []
2.14 +
2.15 + if end:
2.16 + columns.append("end <= ?")
2.17 + values.append(end)
2.18 +
2.19 + query, values = self.get_query(
2.20 + "delete from %(table)s :condition" % {
2.21 + "columns" : self.columnlist(self.period_columns),
2.22 + "table" : self.table_name
2.23 + },
2.24 + columns, values)
2.25 +
2.26 + self.cursor.execute(query, values)
2.27 +
2.28 def remove_event_periods(self, uid, recurrenceid=None, participant=None):
2.29
2.30 """
3.1 --- a/tools/make_freebusy.py Wed Jun 14 00:21:20 2017 +0200
3.2 +++ b/tools/make_freebusy.py Wed Jun 14 00:30:32 2017 +0200
3.3 @@ -40,6 +40,7 @@
3.4 from imiptools.dates import get_default_timezone, to_utc_datetime
3.5 from imiptools.freebusy import FreeBusyCollection, FreeBusyGroupCollection, \
3.6 FreeBusyGroupPeriod
3.7 +from imiptools.period import Period
3.8 from imiptools.stores import get_store, get_publisher, get_journal
3.9
3.10 def make_freebusy(client, participants, storage, store_and_publish,
3.11 @@ -70,16 +71,14 @@
3.12 journal = client.get_journal()
3.13 publisher = client.get_publisher()
3.14 preferences = client.get_preferences()
3.15 -
3.16 - tzid = preferences.get("TZID") or get_default_timezone()
3.17 -
3.18 - # Get the size of the free/busy window.
3.19 + tzid = client.get_tzid()
3.20
3.21 - try:
3.22 - window_size = int(preferences.get("window_size"))
3.23 - except (TypeError, ValueError):
3.24 - window_size = 100
3.25 - window_end = get_window_end(tzid, window_size)
3.26 + # Get the start and end of the window. Note that the start is normally the
3.27 + # current moment in time, but for testing we may choose a specific point in
3.28 + # time instead.
3.29 +
3.30 + window_start = client.get_window_start()
3.31 + window_end = client.get_window_end()
3.32
3.33 providers = []
3.34
3.35 @@ -109,6 +108,10 @@
3.36 else:
3.37 fb = storage.get_freebusy_for_other_for_update(user, participant)
3.38
3.39 + # Remove periods before the window start.
3.40 +
3.41 + fb.remove_periods_before(Period(window_start, None))
3.42 +
3.43 # Obtain event objects.
3.44
3.45 objs = []
3.46 @@ -143,7 +146,8 @@
3.47
3.48 # Add each active period to the collection.
3.49
3.50 - for p in obj.get_active_periods(recurrenceids, tzid, window_end):
3.51 + for p in obj.get_active_periods(recurrenceids, tzid,
3.52 + start=window_start, end=window_end):
3.53
3.54 # Obtain a suitable period object.
3.55