imip-agent

Change of imip_manager.py

380:076eac8892de
imip_manager.py recurring-events
     1.1 --- a/imip_manager.py	Wed Mar 04 18:03:35 2015 +0100
     1.2 +++ b/imip_manager.py	Thu Mar 05 15:26:50 2015 +0100
     1.3 @@ -42,7 +42,8 @@
     1.4  from imiptools.period import add_day_start_points, add_empty_days, add_slots, \
     1.5                               convert_periods, get_freebusy_details, \
     1.6                               get_scale, have_conflict, get_slots, get_spans, \
     1.7 -                             partition_by_day, remove_period, update_freebusy
     1.8 +                             partition_by_day, remove_period, remove_affected_period, \
     1.9 +                             update_freebusy
    1.10  from imiptools.profile import Preferences
    1.11  import imip_store
    1.12  import markup
    1.13 @@ -357,6 +358,9 @@
    1.14          obj = self.objects[(uid, recurrenceid)] = fragment and Object(fragment)
    1.15          return obj
    1.16  
    1.17 +    def _get_recurrences(self, uid):
    1.18 +        return self.store.get_recurrences(self.user, uid)
    1.19 +
    1.20      def _get_requests(self):
    1.21          if self.requests is None:
    1.22              cancellations = self.store.get_cancellations(self.user)
    1.23 @@ -369,8 +373,16 @@
    1.24          for uid, recurrenceid in self._get_requests():
    1.25              obj = self._get_object(uid, recurrenceid)
    1.26              if obj:
    1.27 -                for start, end in obj.get_periods_for_freebusy(self.get_tzid(), self.get_window_end()):
    1.28 -                    summary.append((start, end, uid, obj.get_value("TRANSP"), recurrenceid))
    1.29 +                periods = obj.get_periods_for_freebusy(self.get_tzid(), self.get_window_end())
    1.30 +
    1.31 +                # Subtract any recurrences from the free/busy details of a parent
    1.32 +                # object.
    1.33 +
    1.34 +                recurrenceids = self._get_recurrences(uid)
    1.35 +
    1.36 +                for start, end in periods:
    1.37 +                    if recurrenceid or start not in recurrenceids:
    1.38 +                        summary.append((start, end, uid, obj.get_value("TRANSP"), recurrenceid))
    1.39          return summary
    1.40  
    1.41      # Preference methods.
    1.42 @@ -414,10 +426,18 @@
    1.43          is_only_organiser = self.user not in uri_values(obj.get_values("ATTENDEE"))
    1.44  
    1.45          freebusy = self.store.get_freebusy(self.user)
    1.46 +
    1.47          update_freebusy(freebusy,
    1.48              obj.get_periods_for_freebusy(self.get_tzid(), self.get_window_end()),
    1.49              is_only_organiser and "ORG" or obj.get_value("TRANSP"),
    1.50              uid, recurrenceid)
    1.51 +
    1.52 +        # Subtract any recurrences from the free/busy details of a parent
    1.53 +        # object.
    1.54 +
    1.55 +        for recurrenceid in self._get_recurrences(uid):
    1.56 +            remove_affected_period(freebusy, uid, recurrenceid)
    1.57 +
    1.58          self.store.set_freebusy(self.user, freebusy)
    1.59  
    1.60      def remove_from_freebusy(self, uid, recurrenceid=None):
    1.61 @@ -1086,10 +1106,11 @@
    1.62  
    1.63          # Obtain any parent object if this object is a specific recurrence.
    1.64  
    1.65 +        uid = obj.get_value("UID")
    1.66          recurrenceid = format_datetime(obj.get_utc_datetime("RECURRENCE-ID"))
    1.67  
    1.68          if recurrenceid:
    1.69 -            obj = self._get_object(obj.get_value("UID"))
    1.70 +            obj = self._get_object(uid)
    1.71              if not obj:
    1.72                  return
    1.73  
    1.74 @@ -1098,6 +1119,7 @@
    1.75          # Obtain the periods associated with the event in the user's time zone.
    1.76  
    1.77          periods = obj.get_periods(self.get_tzid(), self.get_window_end())
    1.78 +        recurrenceids = self._get_recurrences(uid)
    1.79  
    1.80          if len(periods) == 1:
    1.81              return
    1.82 @@ -1115,7 +1137,7 @@
    1.83  
    1.84          for start, end in periods:
    1.85              start_utc = format_datetime(to_timezone(start, "UTC"))
    1.86 -            css = recurrenceid and start_utc == recurrenceid and "replaced" or ""
    1.87 +            css = recurrenceids and start_utc in recurrenceids and "replaced" or ""
    1.88  
    1.89              page.tr()
    1.90              page.td(self.format_datetime(start, "long"), class_=css)