Merge lp:~aelkner/schooltool/daily_calendar_bug into lp:schooltool/1.7

Proposed by Alan Elkner
Status: Merged
Merged at revision: 2738
Proposed branch: lp:~aelkner/schooltool/daily_calendar_bug
Merge into: lp:schooltool/1.7
Diff against target: 127 lines (+35/-20)
3 files modified
CHANGES.txt (+1/-1)
src/schooltool/app/browser/cal.py (+22/-11)
src/schooltool/app/browser/tests/test_cal.py (+12/-8)
To merge this branch: bzr merge lp:~aelkner/schooltool/daily_calendar_bug
Reviewer Review Type Date Requested Status
SchoolTool Owners Pending
Review via email: mp+38302@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CHANGES.txt'
2--- CHANGES.txt 2010-10-04 13:48:16 +0000
3+++ CHANGES.txt 2010-10-13 07:40:34 +0000
4@@ -5,7 +5,7 @@
5 1.5.3 (unreleased)
6 ------------------
7
8-- Nothing changed yet.
9+- Fixed Section meeting time misalignment in calendar (https://launchpad.net/bugs/611797)
10
11
12 1.5.2 (2010-10-04)
13
14=== modified file 'src/schooltool/app/browser/cal.py'
15--- src/schooltool/app/browser/cal.py 2010-08-30 16:09:34 +0000
16+++ src/schooltool/app/browser/cal.py 2010-10-13 07:40:34 +0000
17@@ -1337,31 +1337,34 @@
18 break
19 return max(width) or 1
20
21- def _setRange(self, events):
22- """Set the starthour and endhour attributes according to events.
23+ def _setRange(self, events, periods):
24+ """Set the starthour and endhour attributes according to events and
25+ periods.
26
27 The range of the hours to display is the union of the range
28 8:00-18:00 and time spans of all the events in the events
29- list.
30+ list and all the periods as well.
31 """
32- for event in events:
33+ time_blocks = ([(event.dtstart, event.duration) for event in events] +
34+ [(dtstart, duration) for id, dtstart, duration in periods])
35+ for dtstart, duration in time_blocks:
36 start = self.timezone.localize(datetime.combine(self.cursor,
37 time(self.starthour)))
38 end = self.timezone.localize(datetime.combine(self.cursor,
39 time()) + timedelta(hours=self.endhour)) # endhour may be 24
40- if event.dtstart < start:
41+ if dtstart < start:
42 newstart = max(self.timezone.localize(
43 datetime.combine(self.cursor, time())),
44- event.dtstart.astimezone(self.timezone))
45+ dtstart.astimezone(self.timezone))
46 self.starthour = newstart.hour
47
48- if event.dtstart + event.duration > end and \
49- event.dtstart.astimezone(self.timezone).day <= self.cursor.day:
50+ if dtstart + duration > end and \
51+ dtstart.astimezone(self.timezone).day <= self.cursor.day:
52 newend = min(self.timezone.localize(
53 datetime.combine(self.cursor,
54 time())) + timedelta(1),
55- event.dtstart.astimezone(self.timezone) +
56- event.duration + timedelta(0, 3599))
57+ dtstart.astimezone(self.timezone) +
58+ duration + timedelta(0, 3599))
59 self.endhour = newend.hour
60 if self.endhour == 0:
61 self.endhour = 24
62@@ -1403,7 +1406,15 @@
63 # Filter allday events
64 simple_events = [event for event in all_events
65 if not event.allday]
66- self._setRange(simple_events)
67+ # use daily_calendar_rows view to get the periods
68+ view = getMultiAdapter((self.context, self.request),
69+ name='daily_calendar_rows')
70+ if 'getPeriods' in dir(view):
71+ periods = view.getPeriods(self.cursor)
72+ else:
73+ periods = []
74+ # set this view's start and end hours from the events and periods
75+ self._setRange(simple_events, periods)
76 slots = Slots()
77 top = 0
78 for title, start, duration in self.calendarRows(simple_events):
79
80=== modified file 'src/schooltool/app/browser/tests/test_cal.py'
81--- src/schooltool/app/browser/tests/test_cal.py 2010-01-10 17:31:54 +0000
82+++ src/schooltool/app/browser/tests/test_cal.py 2010-10-13 07:40:34 +0000
83@@ -3517,24 +3517,28 @@
84 view = DailyCalendarView(cal, TestRequest())
85 view.cursor = date(2004, 8, 16)
86
87- def do_test(events, expected):
88+ def do_test(events, periods, expected):
89 view.starthour, view.endhour = 8, 19
90- view._setRange(events)
91+ view._setRange(events, periods)
92 self.assertEquals((view.starthour, view.endhour), expected)
93
94- do_test([], (8, 19))
95+ do_test([], [], (8, 19))
96
97 events = [createEvent('2004-08-16 7:00', '1min', 'workout')]
98- do_test(events, (7, 19))
99+ do_test(events, [], (7, 19))
100
101 events = [createEvent('2004-08-15 8:00', '1d', "long workout")]
102- do_test(events, (0, 19))
103+ do_test(events, [], (0, 19))
104
105 events = [createEvent('2004-08-16 20:00', '30min', "late workout")]
106- do_test(events, (8, 21))
107+ do_test(events, [], (8, 21))
108
109 events = [createEvent('2004-08-16 20:00', '5h', "long late workout")]
110- do_test(events, (8, 24))
111+ do_test(events, [], (8, 24))
112+
113+ dummy_event = createEvent('2004-08-16 7:00', '1min', 'workout')
114+ periods = [('', dummy_event.dtstart, dummy_event.duration)]
115+ do_test(events, periods, (7, 24))
116
117 def test__setRange_timezones(self):
118 from schooltool.app.browser.cal import DailyCalendarView
119@@ -3550,7 +3554,7 @@
120
121 def do_test(events, expected):
122 view.starthour, view.endhour = 8, 19
123- view._setRange(events)
124+ view._setRange(events, [])
125 self.assertEquals((view.starthour, view.endhour), expected)
126
127 for tz in (utc, london, vilnius, eastern):

Subscribers

People subscribed via source and target branches