Mercurial > repos > pieterlukasse > nist_wrapper
comparison report_generator.py @ 0:cce6989ed423
new NIST wrapper demo tools
author | pieter.lukasse@wur.nl |
---|---|
date | Thu, 22 Jan 2015 16:14:57 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cce6989ed423 |
---|---|
1 ''' | |
2 Created on Nov 14, 2014 | |
3 | |
4 @author: linda | |
5 ''' | |
6 | |
7 import jinja2 | |
8 import sys | |
9 reload(sys) | |
10 sys.setdefaultencoding("utf-8") | |
11 | |
12 class ReportGenerator(object): | |
13 | |
14 def __init__(self, templatedir, templatename, hits_dict, spectra_dict): | |
15 self.templatename = templatename | |
16 self.hits_dict = hits_dict | |
17 self.spectra_dict = spectra_dict | |
18 | |
19 | |
20 self.loader = jinja2.FileSystemLoader(searchpath=templatedir) | |
21 self.environment = jinja2.Environment(loader=self.loader, | |
22 lstrip_blocks=True, | |
23 trim_blocks=True, | |
24 autoescape=True, | |
25 extensions=['jinja2.ext.autoescape']) | |
26 | |
27 | |
28 def render(self, output): | |
29 template = self.environment.get_template(self.templatename) | |
30 result = template.stream(hits_dict=self.hits_dict, spectra_dict=self.spectra_dict) | |
31 result.dump(output) |