def write_pdf(self, fi): factory = ReportFactory() # define lists separately for tests for i in self.tests_dict.keys(): exec '%s=self.tests_dict[i]' % i # build data string data_string = '' for i in range(1, self.FRAME_ID+1): data_string = data_string + ', data' + str(i) + '=data' + str(i) exec 'factory.render_template(template_file=fi %s , main=self.main_data)' % (data_string) # output will be like 'factory.render_template(template_file=fi, data1=data1, data2=data2) factory.render_document('test.pdf') factory.cleanup()
def genAveSingleReportTonly(self, tname): aves = model.getAves() template = initpath + tname + '.xml' factory = ReportFactory() factory.render_template(template_file=template, aves=aves) # print dir(factory) factory.render_document("gen_" + tname + ".pdf") factory.cleanup()
def genOneAveReportT(self, id, tname): aves = model.getAves() template = initpath + tname + '.xml' factory = ReportFactory() #bh=range(1,len(ave.singles)+1) factory.render_template(template_file=template, aves=aves) factory.render_document("gen_" + tname + ".pdf") factory.cleanup() os.system("start " + "gen_" + tname + ".pdf")
def genAveSingleReportTonly(self,tname): aves=model.getAves() template = initpath+tname+'.xml' factory = ReportFactory() factory.render_template( template_file=template, aves=aves) # print dir(factory) factory.render_document("gen_"+tname+".pdf") factory.cleanup()
def genOneAveReportT(self,id,tname): aves=model.getAves() template = initpath+tname+'.xml' factory = ReportFactory() #bh=range(1,len(ave.singles)+1) factory.render_template( template_file=template, aves=aves) factory.render_document("gen_"+tname+".pdf") factory.cleanup() os.system("start "+"gen_"+tname+".pdf")
def main(): factory = ReportFactory() name = "tombola" nombre_ticket = 400 # name = "repas" template = os.path.join(PATH_CURRENT, 'template', "%s.xml" % name) datas = [] num_random = generate_numbers(nombre_ticket) for item in xrange(nombre_ticket): datas.append({'numero': item + 1, 'num_rand': num_random.next()}) factory.render_template( template_file=template, title=u'tickets', data=datas, path_current = PATH_CURRENT) factory.render_document('%s.pdf' % name) factory.cleanup()
def generate_sacosta_report(config, polygon): """ Generate a pdf from sacosta data :param config: app config :param polygon: shapely polygon :returns: temporary file """ template = 'templates/pdf_template_sacosta.xml' # generate image layers = config['MAP_LAYERS']['sacosta'] img = maputils.generate_map_with_selected_polygon(layers, polygon, max_size=(400, 300)) img_tf = tempfile.NamedTemporaryFile(suffix='.png') img.save(img_tf) data_sacosta = gisdata.get_data_sacosta(config, polygon) units = 'm' if data_sacosta: max_longitud = max([tc['longitud'] for tc in data_sacosta]) if max_longitud > 1000: units = 'km' factory = ReportFactory() factory.render_template(template_file=template, map=img, map_filename=img_tf.name, data_sacosta=data_sacosta, units_longitud=units) tf = tempfile.NamedTemporaryFile() factory.render_document(tf.name) factory.cleanup() return tf
def generate_proteccion_report(config, polygon): """ Generate a pdf from grados de proteccion data :param config: app config :param polygon: shapely polygon :returns: temporary file """ template = 'templates/pdf_template_proteccion.xml' # generate image layers = config['MAP_LAYERS']['proteccion'] img = maputils.generate_map_with_selected_polygon(layers, polygon, max_size=(400, 300)) img_tf = tempfile.NamedTemporaryFile(suffix='.png') img.save(img_tf) # get sacosta legend (changed. No legend, the colors will be shown at the table) img_proteccion_legend = maputils.get_layer_legend(layers[-1], max_size=(470, 400)) img_proteccion_legend_tf = tempfile.NamedTemporaryFile(suffix='.png') img_proteccion_legend.save(img_proteccion_legend_tf) data = gisdata.get_data_proteccion(config, polygon) factory = ReportFactory() factory.render_template(template_file=template, map=img, map_filename=img_tf.name, legend=img_proteccion_legend, legend_filename=img_proteccion_legend_tf.name, data=data) tf = tempfile.NamedTemporaryFile() factory.render_document(tf.name) factory.cleanup() return tf
from pyjon.reports import ReportFactory template = 'basic1.xml' testdata = [range(10)] * 100 if __name__ == '__main__': factory = ReportFactory() factory.render_template(template_file=template, title=u'THE TITLE', data=testdata, dummy='foo') factory.render_template(template_file=template, title=u'THE TITLE 2 :)', data=testdata, dummy='foo') factory.render_document('basic1.pdf') factory.cleanup()
from pyjon.reports import ReportTemplate from pyjon.reports import ReportFactory import sys testdata = [range(10)] * 100 def render_template(factory, template, title): factory.render_template(template_file=template, title=title, data=testdata, truc="bidule") if __name__ == "__main__": factory = ReportFactory() args = sys.argv if len(sys.argv) > 1: render_template(factory, sys.argv[1], sys.argv[2]) factory.render_document(sys.argv[2]) else: render_template(factory, "test1.xml", "doc 1") print "doc 1 done" render_template(factory, "test1.xml", "doc 2") print "doc 2 done" render_template(factory, "test1.xml", "doc 3") print "doc 3 done" factory.render_document("test.pdf") print "file done"
from pyjon.reports import ReportFactory template = 'basic1.xml' testdata = [range(10)] * 100 if __name__ == '__main__': factory = ReportFactory() factory.render_template( template_file=template, title=u'THE TITLE', data=testdata, dummy='foo' ) factory.render_template( template_file=template, title=u'THE TITLE 2 :)', data=testdata, dummy='foo' ) factory.render_document( 'basic1.pdf') factory.cleanup()
from pyjon.reports import ReportFactory template = 'basic2.xml' if __name__ == '__main__': factory = ReportFactory() factory.render_template( template_file=template, toto='tata' ) factory.render_document( 'basic2.pdf') factory.cleanup()
from pyjon.reports import ReportFactory template = 'basic2.xml' if __name__ == '__main__': factory = ReportFactory() factory.render_template(template_file=template, toto='tata') factory.render_document('basic2.pdf') factory.cleanup()
from pyjon.reports import ReportFactory import sys testdata = [range(10)] * 100 def render_template(factory, template, title): factory.render_template(template_file=template, title=title, data=testdata, truc="bidule") if __name__ == '__main__': factory = ReportFactory() args = sys.argv if len(sys.argv) > 1: render_template(factory, sys.argv[1], sys.argv[2]) factory.render_document(sys.argv[2]) else: render_template(factory, 'test1.xml', "doc 1") print "doc 1 done" render_template(factory, 'test1.xml', "doc 2") print "doc 2 done" render_template(factory, 'test1.xml', "doc 3") print "doc 3 done" factory.render_document("test.pdf") print "file done"