blob: 7e988eb7c5f133f672a0830ca6202c22d65917b6 (
plain)
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
|
from cStringIO import StringIO
from .._activitybase import Analysis, parse_rows
DAY_TEMPLATE_TOP = """
<h2>{day}</h2>
<table class="timecsv">
<thead>
<tr>
<th>Project</th>
<th>Time Spent</th>
</tr>
</thead>
<tbody>
"""
DAY_TEMPLATE_BOTTOM = """\
</tbody>
</table>
"""
ROW_TEMPLATE = '\t<tr class="{active}"><td>{task}</td><td>{time}</td></tr>\n'
class Parser:
def __init__(self, raw, request, **kw):
self.request = request
self.analysis = Analysis(parse_rows(raw))
self.analysis.process()
def format(self, formatter, **kw):
output = StringIO()
for day, rows in self.analysis:
output.write(DAY_TEMPLATE_TOP.format(day=day.strftime('%A %B %d, %Y')))
for task, (time, still_active) in rows.items():
output.write(ROW_TEMPLATE.format(task=task, time=time,
active='active' if still_active else ''))
output.write(DAY_TEMPLATE_BOTTOM)
self.request.write(output.getvalue())
|