Commits

Luke Plant committed 9831cec

Made use of calendar.search in 'thissunday' view

Comments (0)

Files changed (2)

christchurch/calendar.py

 
 def search(calendar, start_date, end_date):
     """
-    Searches a vobject calendar for events between the specified datetime objects,
-    hanlding recurring events as necessary.
+    Searches a vobject calendar for events starting between the specified
+    datetime objects, hanlding recurring events as necessary.
 
     Returns a list of 2 tuples containing (datetime/date of event, vevent object)
     """

christchurch/views.py

 
     c = {}
     if cal is not None:
-        events = []
-        for vevent in cal.vevent_list:
-            d = vevent.dtstart.value.astimezone(local_timezone)
-            # Clock should 'tick over' to the next week at the end of Sunday,
-            # not part way through, so truncate hour to zero
-            today = datetime.now(local_timezone).replace(hour=0)
-            if d > today and d < today + timedelta(7):
-                events.append(Event(vevent.summary.value, d))
+        # Clock should 'tick over' to the next week at the end of Sunday,
+        # not part way through, so truncate hour to zero.
+        today = datetime.now(local_timezone).replace(hour=0)
+        raw_events = search(cal, today, today + timedelta(7))
+        events = [Event(vevent.summary.value, dt)
+                  for (dt, vevent) in raw_events]
         events.sort()
         c['events'] = events
     else:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.