def generate_preview(template, layout): if template not in templates.templates(): return "Specified template does not exist.", 400 if layout is None: layout = templates.templates()[template].layouts[0].__name__ if layout not in layouts.layouts(): return "Specified layout does not exist.", 400 return send_file(pdf_builder.get_preview(template, layout), mimetype="image/jpeg")
#!/usr/bin/env python3 # pregen_previews.py -- pregenerates all previews that don't yet exist. import pdf_builder, templates print("Generating previews...") for template_name, template in templates.templates().items(): for layout in template.layouts: print("- generated " + pdf_builder.get_preview(template_name, layout.__name__))