view 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
line wrap: on
line source

'''
Created on Nov 14, 2014

@author: linda
'''

import jinja2    
import sys
reload(sys)
sys.setdefaultencoding("utf-8")   
        
class ReportGenerator(object):
    
    def __init__(self, templatedir, templatename, hits_dict, spectra_dict):
        self.templatename = templatename
        self.hits_dict = hits_dict
        self.spectra_dict = spectra_dict
        

        self.loader = jinja2.FileSystemLoader(searchpath=templatedir)
        self.environment = jinja2.Environment(loader=self.loader,
                                              lstrip_blocks=True,
                                              trim_blocks=True,
                                              autoescape=True, 
                                              extensions=['jinja2.ext.autoescape'])


    def render(self, output):
        template = self.environment.get_template(self.templatename)
        result = template.stream(hits_dict=self.hits_dict, spectra_dict=self.spectra_dict)
        result.dump(output)