annotate report_generator.py @ 11:a62374fcee9c

change
author pieter.lukasse@wur.nl
date Fri, 23 Jan 2015 09:48:58 +0100
parents cce6989ed423
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
1 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
2 Created on Nov 14, 2014
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
3
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
4 @author: linda
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
5 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
6
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
7 import jinja2
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
8 import sys
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
9 reload(sys)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
10 sys.setdefaultencoding("utf-8")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
11
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
12 class ReportGenerator(object):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
13
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
14 def __init__(self, templatedir, templatename, hits_dict, spectra_dict):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
15 self.templatename = templatename
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
16 self.hits_dict = hits_dict
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
17 self.spectra_dict = spectra_dict
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
18
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
19
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
20 self.loader = jinja2.FileSystemLoader(searchpath=templatedir)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
21 self.environment = jinja2.Environment(loader=self.loader,
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
22 lstrip_blocks=True,
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
23 trim_blocks=True,
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
24 autoescape=True,
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
25 extensions=['jinja2.ext.autoescape'])
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
26
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
27
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
28 def render(self, output):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
29 template = self.environment.get_template(self.templatename)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
30 result = template.stream(hits_dict=self.hits_dict, spectra_dict=self.spectra_dict)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
31 result.dump(output)