[CalendarServer-changes] [2755] CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/ ical.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Jul 23 07:13:07 PDT 2008


Revision: 2755
          http://trac.macosforge.org/projects/calendarserver/changeset/2755
Author:   cdaboo at apple.com
Date:     2008-07-23 07:13:06 -0700 (Wed, 23 Jul 2008)
Log Message:
-----------
Make sure equality test includes property parameters. Add a method to derive an overridden instance from
the master.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/ical.py

Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/ical.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/ical.py	2008-07-23 00:50:22 UTC (rev 2754)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/ical.py	2008-07-23 14:13:06 UTC (rev 2755)
@@ -88,7 +88,7 @@
     def __ne__(self, other): return not self.__eq__(other)
     def __eq__(self, other):
         if not isinstance(other, Property): return False
-        return self.name() == other.name() and self.value() == other.value()
+        return self.name() == other.name() and self.value() == other.value() and self.params() == other.params()
 
     def __gt__(self, other): return not (self.__eq__(other) or self.__lt__(other))
     def __lt__(self, other):
@@ -708,7 +708,7 @@
         newcomp = instance.component.duplicate()
  
         # Strip out unwanted recurrence properties
-        for property in newcomp.properties():
+        for property in tuple(newcomp.properties()):
             if property.name() in ["RRULE", "RDATE", "EXRULE", "EXDATE", "RECURRENCE-ID"]:
                 newcomp.removeProperty(property)
         
@@ -763,6 +763,41 @@
         instances.expandTimeRanges(componentSet, limit)
         return instances
 
+    def deriveInstance(self, rid):
+        """
+        Derive an instance from the master component that has the provided RECURRENCE-ID, but
+        with all other properties, components etc from the master.
+
+        @param rid: recurrence-id value
+        @type rid: L{datetime.datetime}
+        """
+        
+        # Must have a master component
+        master = self.masterComponent()
+        if master is None:
+            return None
+
+        # TODO: Check that the recurrence-id is a valid instance
+        
+        # Create the derived instance
+        newcomp = master.duplicate()
+
+        # Strip out unwanted recurrence properties
+        for property in tuple(newcomp.properties()):
+            if property.name() in ["RRULE", "RDATE", "EXRULE", "EXDATE", "RECURRENCE-ID"]:
+                newcomp.removeProperty(property)
+        
+        # Adjust times
+        offset = rid - newcomp.getStartDateUTC()
+        dtstart = newcomp.getProperty("DTSTART")
+        dtstart.setValue(dtstart.value() + offset)
+        if newcomp.hasProperty("DTEND"):
+            dtend = newcomp.getProperty("DTEND")
+            dtend.setValue(dtend.value() + offset)
+        newcomp.addProperty(Property("RECURRENCE-ID", dtstart.value()))
+            
+        return newcomp
+        
     def resourceUID(self):
         """
         @return: the UID of the subcomponents in this component.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080723/5e47bd10/attachment.html 


More information about the calendarserver-changes mailing list