move feed_template to texenv

This commit is contained in:
Benjamin Bertrand 2016-11-26 17:40:35 +03:00
parent 989a2e6c1b
commit 39969777d8
2 changed files with 22 additions and 20 deletions

View File

@ -2,7 +2,7 @@
# encoding: utf-8
from notes_tools.tools import extract_flat_marks, get_class_ws, digest_flat_df, students_pov, select_eval
from .texenv import texenv
from .texenv import feed_template
import pandas as pd
import numpy as np
import xlrd
@ -63,27 +63,9 @@ def eval_bilan(classe, evalname, path = Path('./'), template = "tpl_bilan_eval.t
"quest_df":quest_df, "exo_df":exo_df, "eval_df":eval_df}
target = build_target_name(classe, evalname, path)
feed_bilan(target, datas, template)
feed_template(target, datas, template)
def feed_bilan(target, datas, template):
""" Get the template and feed it to create bilans
:param target: path where the bilan will be saved
:param datas: dictonnary to feed the template
:param template: the template
"""
logger.info("Getting template {}".format(template))
bilan = texenv.get_template(template)
path_to_target = target.dirname()
if not path_to_target.exists():
path_to_target.mkdir()
with open(target, "w") as f:
f.write(bilan.render(**datas, directory=path_to_target))
logger.info("{} est construit! Ya plus qu'à compiler!".format(target))
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:

View File

@ -4,6 +4,9 @@
import jinja2, os
from .filters import includegraphics
import logging
logger = logging.getLogger("generate_bilan")
__all__ = ["texenv"]
# Definition of jinja syntax for latex
@ -32,6 +35,23 @@ from notes_tools.tools.marks_plottings import comp_radar, marks_hist
texenv.filters['comp_radar'] = comp_radar
texenv.filters['marks_hist'] = marks_hist
def feed_template(target, datas, template):
""" Get the template and feed it to create bilans
:param target: path where the bilan will be saved
:param datas: dictonnary to feed the template
:param template: the template
"""
logger.info("Getting template {}".format(template))
bilan = texenv.get_template(template)
path_to_target = target.dirname()
if not path_to_target.exists():
path_to_target.mkdir()
with open(target, "w") as f:
f.write(bilan.render(**datas, directory=path_to_target))
logger.info("{} est construit! Ya plus qu'à compiler!".format(target))
if __name__ == '__main__':
print(texenv.list_templates())
texenv.get_template("tpl_bilan.tex")