/
Role.py
47 lines (39 loc) · 1.67 KB
/
Role.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
__author__ = 'Neil Butcher'
from HTMLObjects import HTMLObjects
from Abstract import AbstractMultiAppointmentReporter, person_name
from Rota_System.StandardTimes import time_string, date_string
class RoleReporter(AbstractMultiAppointmentReporter):
'''
produces a html from a role and a list of events
'''
def report_about(self, an_object):
if not self._events:
return HTMLObjects.HTMLNone()
self.role(an_object)
return self.html().html_string()
def role(self, role):
self._all_appointments = set()
self._role = role
for e in self._events:
correct_appointments = filter(lambda x: x.role == role, e.appointments)
self._all_appointments.update(correct_appointments)
def _html_header(self):
return HTMLObjects.HTMLTitle(self._role.description)
def _html_table(self):
table = HTMLObjects.HTMLTable()
row = HTMLObjects.HTMLTableRow(HTMLObjects.HTMLTableHeaderCell())
for t in self._times():
row.add(HTMLObjects.HTMLTableHeaderCell(time_string(t)))
table.add(row)
for d in self._dates():
row = HTMLObjects.HTMLTableRow(HTMLObjects.HTMLTableHeaderCell(date_string(d)))
for t in self._times():
correct_appointments = filter(lambda x: x.date == d and x.time == t, self._all_appointments)
names = map(person_name, correct_appointments)
if len(names) > 0:
string = '<br>'.join(names)
else:
string = ''
row.add(HTMLObjects.HTMLTableCell(string))
table.add(row)
return table