/
Event.py
65 lines (55 loc) · 2.31 KB
/
Event.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
__author__ = 'Neil Butcher'
from HTMLObjects import HTMLObjects
from Rota_System.StandardTimes import date_string, time_string
class EventReporter(object):
def event(self, event):
self._event = event
def report_about(self, an_object):
self.event(an_object)
return self.html().html_string()
def html(self):
if len(self._event.appointments) == 0:
return HTMLObjects.HTMLNone()
html = HTMLObjects.HTMLGroup()
html.add(self._html_header())
html.add(self._html_table())
html.add(self._html_footer())
return html
def _html_header(self):
title = 'Event '
title += date_string(self._event.date)
title += ' '
title += time_string(self._event.time)
title += ' '
title += self._event.title
return HTMLObjects.HTMLHeading(title)
def _html_table(self):
table = HTMLObjects.HTMLTable()
table.add(self._html_table_row_header())
sorted_appointments = sorted(self._event.appointments, key=lambda app: app.role.priority, reverse=True)
for appointment in sorted_appointments:
table.add(self._html_table_row(appointment))
return table
def _html_footer(self):
return None
def _html_table_row_header(self):
html = HTMLObjects.HTMLTableRow()
html.add(HTMLObjects.HTMLTableHeaderCell('Role'))
html.add(HTMLObjects.HTMLTableHeaderCell('Person'))
html.add(HTMLObjects.HTMLTableHeaderCell('Phone Number'))
html.add(HTMLObjects.HTMLTableHeaderCell('email'))
html.add(HTMLObjects.HTMLTableHeaderCell('note'))
return html
def _html_table_row(self, appointment):
html = HTMLObjects.HTMLTableRow()
if appointment.disabled and not (appointment.is_filled()):
return None
html.add(HTMLObjects.HTMLTableCell(appointment.role.description))
if appointment.is_filled():
html.add(HTMLObjects.HTMLTableCell(appointment.person.name))
html.add(HTMLObjects.HTMLTableCell(appointment.person.phone_number))
html.add(HTMLObjects.HTMLTableCell(appointment.person.email))
else:
html.add(HTMLObjects.HTMLTableCell('Not filled', 3, 1))
html.add(HTMLObjects.HTMLTableCell(appointment.note))
return html