Merge lp:~justas.sadzevicius/schooltool.lyceum.journal/journal_overlap_fix into lp:schooltool.lyceum.journal/flourish

Proposed by Justas Sadzevičius
Status: Merged
Merged at revision: 367
Proposed branch: lp:~justas.sadzevicius/schooltool.lyceum.journal/journal_overlap_fix
Merge into: lp:schooltool.lyceum.journal/flourish
Diff against target: 522 lines (+202/-173)
7 files modified
CHANGES.txt (+2/-1)
src/schooltool/lyceum/journal/browser/journal.py (+10/-1)
src/schooltool/lyceum/journal/ftests/advanced-sections.txt (+36/-37)
src/schooltool/lyceum/journal/generations/__init__.py (+2/-2)
src/schooltool/lyceum/journal/generations/evolve3.py (+138/-0)
src/schooltool/lyceum/journal/journal.py (+13/-55)
src/schooltool/lyceum/journal/tests/test_journal.py (+1/-77)
To merge this branch: bzr merge lp:~justas.sadzevicius/schooltool.lyceum.journal/journal_overlap_fix
Reviewer Review Type Date Requested Status
Gediminas Paulauskas (community) Approve
Review via email: mp+155534@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Gediminas Paulauskas (menesis) :
review: Approve

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 2013-02-18 22:52:54 +0000
3+++ CHANGES.txt 2013-03-26 15:54:32 +0000
4@@ -5,7 +5,8 @@
5 2.3.2 (unreleased)
6 ------------------
7
8-- Nothing changed yet.
9+- Fix journals when section out-of-term-bounds schedules overlap
10+- Journals now display all scheduled dates for selected section
11
12
13 2.3.1 (2013-02-19)
14
15=== modified file 'src/schooltool/lyceum/journal/browser/journal.py'
16--- src/schooltool/lyceum/journal/browser/journal.py 2012-10-12 14:28:51 +0000
17+++ src/schooltool/lyceum/journal/browser/journal.py 2013-03-26 15:54:32 +0000
18@@ -743,6 +743,15 @@
19 def has_header(self):
20 return not self.render_journal
21
22+ def allMeetings(self):
23+ term = removeSecurityProxy(self.selected_term)
24+ if not term:
25+ return ()
26+ by_uid = dict([(removeSecurityProxy(e).unique_id, e)
27+ for e in self.context.meetings])
28+ meetings = sorted(by_uid.values())
29+ return meetings
30+
31 def updateGradebook(self):
32 members = self.members()
33 for meeting in self.meetings:
34@@ -1080,7 +1089,7 @@
35 'selected': term is currentTerm and 'selected' or None}
36 for term in sorted(terms, key=lambda x:x.first)]
37
38- def getCourse(self, section):
39+ def getCourse(self, section):
40 try:
41 return list(section.courses)[0]
42 except (IndexError,):
43
44=== modified file 'src/schooltool/lyceum/journal/ftests/advanced-sections.txt'
45--- src/schooltool/lyceum/journal/ftests/advanced-sections.txt 2012-04-17 16:59:21 +0000
46+++ src/schooltool/lyceum/journal/ftests/advanced-sections.txt 2013-03-26 15:54:32 +0000
47@@ -135,12 +135,12 @@
48 'http://localhost/schoolyears/2005/2005-fall-1/sections/1/journal/index.html?month=10'
49 >>> teacher.getLink('October').click()
50 >>> printGradebookTable(teacher.contents) # doctest: -REPORT_NDIFF
51- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
52- | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 05 B | 06 A | 06 B | 11 A | 11 B | 12 A | 12 B | 13 A | 13 B | 18 A | 18 B | 19 A | 19 B | 20 A | 20 B | 25 A | 25 B | 26 A | 26 B | 27 A | 27 B | Average | Absences | Tardies |
53- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
54- | 1 | Frum | Student | | | | | X | X | | | | | X | X | | | | | X | X | | | | | X | X | | | |
55- | 2 | Grum | Student | | | | X | | | | | | X | | | | | | X | | | | | | X | | | | | |
56- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
57+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
58+ | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 11 A | 11 B | 12 A | 18 A | 18 B | 19 A | 25 A | 25 B | 26 A | Average | Absences | Tardies |
59+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
60+ | 1 | Frum | Student | | | | | | | | | | | | | | | |
61+ | 2 | Grum | Student | | | | | | | | | | | | | | | |
62+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
63
64 >>> unquote(teacher.getLink('04').url)
65 'http://localhost/schoolyears/2005/2005-fall-1/sections/1/journal/index.html?event_id=...&month=10'
66@@ -151,12 +151,12 @@
67
68 >>> teacher.getLink('18').click()
69 >>> printGradebookTable(teacher.contents)
70- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
71- | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 05 B | 06 A | 06 B | 11 A | 11 B | 12 A | 12 B | 13 A | 13 B | 18 | 18 B | 19 A | 19 B | 20 A | 20 B | 25 A | 25 B | 26 A | 26 B | 27 A | 27 B | Average | Absences | Tardies |
72- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
73- | 1 | Frum | Student | | | | | X | X | | | | | X | X | [_____] | | | | X | X | | | | | X | X | | | |
74- | 2 | Grum | Student | | | | X | | | | | | X | | | [_____] | | | X | | | | | | X | | | | | |
75- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
76+ +-----+------------+-----------+------+------+------+------+------+------+---------+------+------+------+------+------+---------+----------+---------+
77+ | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 11 A | 11 B | 12 A | 18 | 18 B | 19 A | 25 A | 25 B | 26 A | Average | Absences | Tardies |
78+ +-----+------------+-----------+------+------+------+------+------+------+---------+------+------+------+------+------+---------+----------+---------+
79+ | 1 | Frum | Student | | | | | | | [_____] | | | | | | | | |
80+ | 2 | Grum | Student | | | | | | | [_____] | | | | | | | | |
81+ +-----+------------+-----------+------+------+------+------+------+------+---------+------+------+------+------+------+---------+----------+---------+
82
83 >>> cells = analyze.queryHTML('//table[@class="data"]//input[@type="text"]/@name', teacher.contents)
84 >>> teacher.getControl(name=cells[0]).value = '10'
85@@ -167,23 +167,23 @@
86 >>> teacher.getControl(name=cells[0]).value = '5'
87 >>> teacher.getControl('Update').click()
88 >>> printGradebookTable(teacher.contents)
89- +-----+------------+-----------+------+------+------+------+------+------+---------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
90- | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 05 B | 06 A | 06 B | 11 | 11 B | 12 A | 12 B | 13 A | 13 B | 18 A | 18 B | 19 A | 19 B | 20 A | 20 B | 25 A | 25 B | 26 A | 26 B | 27 A | 27 B | Average | Absences | Tardies |
91- +-----+------------+-----------+------+------+------+------+------+------+---------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
92- | 1 | Frum | Student | | | | | X | X | [5____] | | | | X | X | 10 | | | | X | X | | | | | X | X | 7.500 | | |
93- | 2 | Grum | Student | | | | X | | | [_____] | | | X | | | | | | X | | | | | | X | | | | | |
94- +-----+------------+-----------+------+------+------+------+------+------+---------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
95+ +-----+------------+-----------+------+------+------+---------+------+------+------+------+------+------+------+------+---------+----------+---------+
96+ | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 11 | 11 B | 12 A | 18 A | 18 B | 19 A | 25 A | 25 B | 26 A | Average | Absences | Tardies |
97+ +-----+------------+-----------+------+------+------+---------+------+------+------+------+------+------+------+------+---------+----------+---------+
98+ | 1 | Frum | Student | | | | [5____] | | | 10 | | | | | | 7.500 | | |
99+ | 2 | Grum | Student | | | | [_____] | | | | | | | | | | | |
100+ +-----+------------+-----------+------+------+------+---------+------+------+------+------+------+------+------+------+---------+----------+---------+
101
102 >>> teacher.open('http://localhost/schoolyears/2005/2005-fall-1/sections/1')
103 >>> teacher.getLink('Journal', index=1).click()
104 >>> teacher.getLink('October').click()
105 >>> printGradebookTable(teacher.contents) # doctest: -REPORT_NDIFF
106- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
107- | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 05 B | 06 A | 06 B | 11 A | 11 B | 12 A | 12 B | 13 A | 13 B | 18 A | 18 B | 19 A | 19 B | 20 A | 20 B | 25 A | 25 B | 26 A | 26 B | 27 A | 27 B | Average | Absences | Tardies |
108- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
109- | 1 | Frum | Student | | | | | X | X | 5 | | | | X | X | 10 | | | | X | X | | | | | X | X | 7.500 | | |
110- | 2 | Grum | Student | | | | X | | | | | | X | | | | | | X | | | | | | X | | | | | |
111- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
112+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
113+ | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 11 A | 11 B | 12 A | 18 A | 18 B | 19 A | 25 A | 25 B | 26 A | Average | Absences | Tardies |
114+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
115+ | 1 | Frum | Student | | | | 5 | | | 10 | | | | | | 7.500 | | |
116+ | 2 | Grum | Student | | | | | | | | | | | | | | | |
117+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
118
119 A test for a regresion when teacher has no permission to see one of
120 the sections, even though he is teaching another one:
121@@ -198,12 +198,12 @@
122
123 >>> teacher2.open(teacher.url)
124 >>> printGradebookTable(teacher2.contents)
125- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
126- | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 05 B | 06 A | 06 B | 11 A | 11 B | 12 A | 12 B | 13 A | 13 B | 18 A | 18 B | 19 A | 19 B | 20 A | 20 B | 25 A | 25 B | 26 A | 26 B | 27 A | 27 B | Average | Absences | Tardies |
127- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
128- | 1 | Frum | Student | | | | | X | X | 5 | | | | X | X | 10 | | | | X | X | | | | | X | X | 7.500 | | |
129- | 2 | Grum | Student | | | | X | | | | | | X | | | | | | X | | | | | | X | | | | | |
130- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
131+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
132+ | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 11 A | 11 B | 12 A | 18 A | 18 B | 19 A | 25 A | 25 B | 26 A | Average | Absences | Tardies |
133+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
134+ | 1 | Frum | Student | | | | 5 | | | 10 | | | | | | 7.500 | | |
135+ | 2 | Grum | Student | | | | | | | | | | | | | | | |
136+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
137
138 Now let's change the teacher for the adjacent section section:
139
140@@ -216,10 +216,9 @@
141
142 >>> teacher2.reload()
143 >>> printGradebookTable(teacher2.contents)
144- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
145- | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 06 A | 06 B | 11 A | 11 B | 12 A | 13 A | 13 B | 18 A | 18 B | 19 A | 20 A | 20 B | 25 A | 25 B | 26 A | 27 A | 27 B | Average | Absences | Tardies |
146- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
147- | 1 | Frum | Student | | | | X | X | 5 | | | X | X | 10 | | | X | X | | | | X | X | 7.500 | | |
148- | 2 | Grum | Student | | | | | | | | | | | | | | | | | | | | | | | |
149- +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
150-
151+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
152+ | Nr. | First Name | Last Name | 04 A | 04 B | 05 A | 11 A | 11 B | 12 A | 18 A | 18 B | 19 A | 25 A | 25 B | 26 A | Average | Absences | Tardies |
153+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
154+ | 1 | Frum | Student | | | | 5 | | | 10 | | | | | | 7.500 | | |
155+ | 2 | Grum | Student | | | | | | | | | | | | | | | |
156+ +-----+------------+-----------+------+------+------+------+------+------+------+------+------+------+------+------+---------+----------+---------+
157
158=== modified file 'src/schooltool/lyceum/journal/generations/__init__.py'
159--- src/schooltool/lyceum/journal/generations/__init__.py 2011-07-06 09:52:15 +0000
160+++ src/schooltool/lyceum/journal/generations/__init__.py 2013-03-26 15:54:32 +0000
161@@ -24,6 +24,6 @@
162
163
164 schemaManager = SchemaManager(
165- minimum_generation=2,
166- generation=2,
167+ minimum_generation=3,
168+ generation=3,
169 package_name='schooltool.lyceum.journal.generations')
170
171=== added file 'src/schooltool/lyceum/journal/generations/evolve3.py'
172--- src/schooltool/lyceum/journal/generations/evolve3.py 1970-01-01 00:00:00 +0000
173+++ src/schooltool/lyceum/journal/generations/evolve3.py 2013-03-26 15:54:32 +0000
174@@ -0,0 +1,138 @@
175+#
176+# - common information systems platform for school administration
177+# Copyright (c) 2013 Shuttleworth Foundation
178+#
179+# This program is free software; you can redistribute it and/or modify
180+# it under the terms of the GNU General Public License as published by
181+# the Free Software Foundation; either version 2 of the License, or
182+# (at your option) any later version.
183+#
184+# This program is distributed in the hope that it will be useful,
185+# but WITHOUT ANY WARRANTY; without even the implied warranty of
186+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
187+# GNU General Public License for more details.
188+#
189+# You should have received a copy of the GNU General Public License
190+# along with this program; if not, write to the Free Software
191+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
192+#
193+"""
194+Move grades from overlapped journal schedules to respective journals.
195+"""
196+from zope.app.generations.utility import findObjectsProviding
197+from zope.app.publication.zopepublication import ZopePublication
198+from zope.component.hooks import getSite, setSite
199+from zope.component import getUtility
200+from zope.intid.interfaces import IIntIds
201+
202+from schooltool.app.interfaces import ISchoolToolApplication
203+from schooltool.app.interfaces import ISchoolToolCalendar
204+from schooltool.course.interfaces import ISection
205+from schooltool.person.interfaces import IPerson
206+from schooltool.lyceum.journal.interfaces import ISectionJournalData
207+from schooltool.term.interfaces import ITerm
208+
209+
210+def student_sections(students):
211+ sections = set()
212+ for student in students:
213+ for section in student.groups:
214+ if ISection.providedBy(section):
215+ sections.add(section)
216+ return sections
217+
218+
219+def adjacent_sections(section):
220+ courses = section.courses
221+ instructors = section.instructors
222+ sections = set()
223+ sections.add(section)
224+ members = [member for member in section.members
225+ if IPerson.providedBy(member)]
226+ for section in student_sections(members):
227+ for course in section.courses:
228+ if course in courses:
229+ for instructor in section.instructors:
230+ if instructor in instructors:
231+ sections.add(section)
232+ break
233+ return sections
234+
235+
236+def collect_meeting_ids(section):
237+ calendar = ISchoolToolCalendar(section)
238+ unique_meeting_ids = set()
239+ for event in sorted(calendar, key=lambda e: e.dtstart):
240+ entry_id = event.meeting_id
241+ if entry_id is None:
242+ entry_id = event.unique_id
243+ if entry_id not in unique_meeting_ids:
244+ unique_meeting_ids.add(entry_id)
245+ return unique_meeting_ids
246+
247+
248+def collect_student_names(section):
249+ return set([person.__name__ for person in section.members])
250+
251+
252+def evolveSectionJournal(section, journal):
253+ adjacent_journals = sorted([
254+ (ITerm(adj_sec).first,
255+ ISectionJournalData(adj_sec),
256+ collect_meeting_ids(adj_sec),
257+ collect_student_names(adj_sec))
258+ for adj_sec in adjacent_sections(section)
259+ if ITerm(adj_sec).first > ITerm(section).first
260+ ])
261+
262+ for key in journal.__grade_data__:
263+ person_name, grade_date = key
264+ for adj_date, adj_journal, adj_eids, adj_students in reversed(adjacent_journals):
265+ if adj_date > grade_date:
266+ continue # journal starts later then grade recorded
267+
268+ if person_name not in adj_students:
269+ continue # person is not attending this section
270+
271+ # process day records
272+ recorded_entries = list(journal.__grade_data__.get(key, ()))
273+ for eid, entries in recorded_entries:
274+ # is the move possible for this grade?
275+ if eid not in adj_eids:
276+ continue
277+ journal.__grade_data__[key] = tuple([
278+ (k, v)
279+ for k, v in journal.__grade_data__[key]
280+ if k != eid])
281+ adj_journal.__grade_data__[key] = tuple(sorted(
282+ [(k, v)
283+ for k, v in adj_journal.__grade_data__.get(key, ())
284+ if k != eid] +
285+ [(eid, entries)]
286+ ))
287+
288+
289+def evolveJournals(app):
290+ container = app['schooltool.lyceum.journal']
291+ int_ids = getUtility(IIntIds)
292+
293+ for section_id, journal in container.items():
294+ section = int_ids.queryObject(int(section_id))
295+ if section:
296+ evolveSectionJournal(section, journal)
297+ else:
298+ # Section was deleted, delete journal data for it
299+ del container[section_id]
300+
301+
302+def evolve(context):
303+ root = context.connection.root().get(ZopePublication.root_name, None)
304+ old_site = getSite()
305+
306+ apps = findObjectsProviding(root, ISchoolToolApplication)
307+ for app in apps:
308+ setSite(app)
309+ if 'schooltool.lyceum.journal' in app:
310+ evolveJournals(app)
311+
312+ setSite(old_site)
313
314=== modified file 'src/schooltool/lyceum/journal/journal.py'
315--- src/schooltool/lyceum/journal/journal.py 2012-05-16 16:03:21 +0000
316+++ src/schooltool/lyceum/journal/journal.py 2013-03-26 15:54:32 +0000
317@@ -70,33 +70,6 @@
318 ann[CURRENT_SECTION_TAUGHT_KEY] = removeSecurityProxy(section)
319
320
321-def student_sections(students):
322- sections = set()
323- for student in students:
324- for section in student.groups:
325- if ISection.providedBy(section):
326- sections.add(section)
327- return sections
328-
329-
330-def adjacent_sections(section):
331- courses = section.courses
332- instructors = section.instructors
333- sections = set()
334- sections.add(section)
335- members = [member for member in section.members
336- if IPerson.providedBy(member)]
337- for section in student_sections(members):
338- section = removeSecurityProxy(section)
339- for course in section.courses:
340- if course in courses:
341- for instructor in section.instructors:
342- if instructor in instructors:
343- sections.add(section)
344- break
345- return sections
346-
347-
348 class LyceumJournalContainer(BTreeContainer):
349 """A container for all the journals in the system."""
350
351@@ -255,36 +228,26 @@
352 if IPerson.providedBy(member)]
353
354 @Lazy
355- def adjacent_sections(self):
356- """Sections in the same course that share members and at least one
357- teacher with this section."""
358- return adjacent_sections(removeSecurityProxy(self.section))
359-
360- @Lazy
361 def meetings(self):
362- """Ordered list of all meetings for this and adjacent sections with
363+ """Ordered list of all meetings for this section with
364 consecutive periods removed if the timetable is so configured."""
365 events = []
366 unique_meetings = set()
367- calendars = [ISchoolToolCalendar(section)
368- for section in self.adjacent_sections]
369- for calendar in calendars:
370- sorted_events = sorted(calendar, key=lambda e: e.dtstart)
371- for event in sorted_events:
372- if event.meeting_id not in unique_meetings:
373- events.append(event)
374- unique_meetings.add(event.meeting_id)
375+ calendar = ISchoolToolCalendar(removeSecurityProxy(self.section))
376+ sorted_events = sorted(calendar, key=lambda e: e.dtstart)
377+ for event in sorted_events:
378+ if event.meeting_id not in unique_meetings:
379+ events.append(event)
380+ unique_meetings.add(event.meeting_id)
381 return sorted(events)
382
383 def recordedMeetings(self, person):
384 """Ordered list of all recorded meetings for this person.
385
386- For this and adjacent sections.
387+ For this section.
388 """
389- meetings = []
390- for section in self.adjacent_sections:
391- sd = ISectionJournalData(section)
392- meetings.extend(sd.recordedMeetings(person))
393+ sd = ISectionJournalData(removeSecurityProxy(self.section))
394+ meetings = sd.recordedMeetings(person)
395 return sorted(meetings)
396
397 def hasMeeting(self, person, meeting):
398@@ -293,14 +256,9 @@
399 return owner in ILearner(person).sections()
400
401 def findMeeting(self, meeting_id):
402- calendars = [ISchoolToolCalendar(section)
403- for section in self.adjacent_sections]
404- for calendar in calendars:
405- try:
406- return calendar.find(meeting_id)
407- except KeyError:
408- pass
409- raise KeyError("Could not find a meeting.")
410+ calendar = ISchoolToolCalendar(removeSecurityProxy(self.section))
411+ meeting = calendar.find(meeting_id)
412+ return meeting
413
414
415 def getSectionJournalData(section):
416
417=== modified file 'src/schooltool/lyceum/journal/tests/test_journal.py'
418--- src/schooltool/lyceum/journal/tests/test_journal.py 2012-04-04 22:19:32 +0000
419+++ src/schooltool/lyceum/journal/tests/test_journal.py 2013-03-26 15:54:32 +0000
420@@ -244,70 +244,6 @@
421 """
422
423
424-def doctest_SectionJournal_adjacent_sections():
425- """Tests for SectionJournal.adjacent_sections:
426-
427- >>> from schooltool.lyceum.journal.journal import SectionJournal
428- >>> from schooltool.course.interfaces import ISection
429- >>> class SectionStub(object):
430- ... implements(ISection)
431- ... def __init__(self, name):
432- ... self.name = name
433- ... def __repr__(self):
434- ... return "<Section %s>" % self.name
435- ... def __cmp__(self, other):
436- ... return cmp(self.name, other.name)
437- ... courses = []
438- ... members = []
439- ... instructors = []
440- >>> section = SectionStub("Math 1a")
441- >>> section.courses = ["math"]
442- >>> sj = SectionJournal(section)
443- >>> sorted(sj.adjacent_sections)
444- [<Section Math 1a>]
445-
446- >>> from schooltool.person.interfaces import IPerson
447- >>> class PersonStub(object):
448- ... implements(IPerson)
449- ... groups = []
450- >>> john = PersonStub()
451- >>> pete = PersonStub()
452- >>> teacher = PersonStub()
453- >>> section.members = [john, pete, "something-else"]
454- >>> section.instructors = [teacher]
455- >>> sj = SectionJournal(section)
456- >>> sorted(sj.adjacent_sections)
457- [<Section Math 1a>]
458-
459- >>> sj = SectionJournal(section)
460- >>> section2 = SectionStub("Math 1a A")
461- >>> john.groups = [section2, "something-else"]
462- >>> sorted(sj.adjacent_sections)
463- [<Section Math 1a>]
464-
465- >>> sj = SectionJournal(section)
466- >>> section2.courses = ["math"]
467- >>> section2.instructors = [teacher]
468- >>> sorted(sj.adjacent_sections)
469- [<Section Math 1a>, <Section Math 1a A>]
470-
471- >>> sj = SectionJournal(section)
472- >>> section2.courses = ["math", "history"]
473- >>> section.courses = ["math", "history"]
474- >>> sorted(sj.adjacent_sections)
475- [<Section Math 1a>, <Section Math 1a A>]
476-
477- >>> sj = SectionJournal(section)
478- >>> section3 = SectionStub("Math 1a B")
479- >>> section3.courses = ["math"]
480- >>> section3.instructors = [teacher]
481- >>> pete.groups = [section3]
482- >>> sorted(sj.adjacent_sections)
483- [<Section Math 1a>, <Section Math 1a A>, <Section Math 1a B>]
484-
485- """
486-
487-
488 def doctest_SectionJournal_findMeeting():
489 """Test for SectionJournal.findMeeting
490
491@@ -328,14 +264,13 @@
492 >>> section1.calendar = CalendarStub()
493 >>> section1.calendar.events = ["section-meeting"]
494 >>> sj = SectionJournal(section1)
495- >>> sj.adjacent_sections = [section1]
496
497 If there is no such meeting, a key error is raised:
498
499 >>> sj.findMeeting("some-meeting-id")
500 Traceback (most recent call last):
501 ...
502- KeyError: 'Could not find a meeting.'
503+ KeyError: 'Event not found!'
504
505 But if we are looking for a meeting that belongs to the calendar
506 of the context section, we should get it:
507@@ -343,17 +278,6 @@
508 >>> sj.findMeeting("section-meeting")
509 '<Event uid=section-meeting>'
510
511- If meeting belongs to some other section that is adjacent, we
512- should still get it's instance:
513-
514- >>> section2 = SectionStub()
515- >>> section2.calendar = CalendarStub()
516- >>> section2.calendar.events = ["section2-meeting"]
517- >>> sj.adjacent_sections = [section1, section2]
518-
519- >>> sj.findMeeting("section2-meeting")
520- '<Event uid=section2-meeting>'
521-
522 """
523
524

Subscribers

People subscribed via source and target branches