Exemplo n.º 1
0
    def render(self, ar, output_file):
        context = {
            'action': self,
            'ar': ar,
            'as_html_table': self.as_html_table,
        }

        extend_context(context)

        template = settings.SITE.plugins.jinja.renderer.jinja_env.get_template(
            self.template_name)
        html = template.render(**context).encode('utf-8')

        with open(output_file + '.html', "w") as file:
            file.write(html)

        result = io.StringIO()
        h = logging.FileHandler(output_file + '.log', 'w')
        pisa.log.addHandler(h)
        pdf = pisa.pisaDocument(
            io.StringIO(html), result, encoding='utf-8')
        pisa.log.removeHandler(h)
        h.close()

        with open(output_file, 'wb') as file:
            file.write(result.getvalue())
            file.close()

        if pdf.err:
            raise Exception("pisa.pisaDocument.err is %r" % pdf.err)
Exemplo n.º 2
0
    def render(self, ar, output_file):
        context = {
            'action': self,
            'ar': ar,
            'as_html_table': self.as_html_table,
        }

        extend_context(context)

        template = settings.SITE.plugins.jinja.renderer.jinja_env.get_template(
            self.template_name)
        html = template.render(**context).encode('utf-8')

        with open(output_file + '.html', "w") as file:
            file.write(html)

        result = io.StringIO()
        h = logging.FileHandler(output_file + '.log', 'w')
        pisa.log.addHandler(h)
        pdf = pisa.pisaDocument(
            io.StringIO(html), result, encoding='utf-8')
        pisa.log.removeHandler(h)
        h.close()

        with open(output_file, 'wb') as file:
            file.write(result.getvalue())
            file.close()

        if pdf.err:
            raise Exception("pisa.pisaDocument.err is %r" % pdf.err)
Exemplo n.º 3
0
Arquivo: views.py Projeto: cuchac/lino
def plain_response(ui, request, tplname, context):
    "Deserves a docstring"
    u = request.subst_user or request.user
    lang = get_language()
    k = (u.profile, lang)
    menu = PLAIN_MENUS.get(k, None)
    if menu is None:
        menu = settings.SITE.get_site_menu(ui, u.profile)
        #~ url = settings.SITE.plain_prefix + '/'
        plain = settings.SITE.plugins.plain
        assert plain.renderer is not None
        url = plain.build_plain_url()
        menu.add_url_button(url, label=_("Home"))
        menu = menu.as_bootstrap_html(plain.renderer, request)
        menu = E.tostring(menu)
        PLAIN_MENUS[k] = menu
    context.update(menu=menu, E=E)
    web.extend_context(context)
    template = settings.SITE.jinja_env.get_template(tplname)

    response = http.HttpResponse(
        template.render(**context),
        content_type='text/html;charset="utf-8"')

    return response
Exemplo n.º 4
0
def plain_response(ui,request,tplname,context):        
    u = request.subst_user or request.user
    menu = MENUS.get(u.profile,None)
    if menu is None:
        menu = settings.LINO.get_site_menu(ui,u.profile)
        url = settings.LINO.plain_prefix + '/'
        menu.add_url_button(url,label=_("Home"))
        menu = menu.as_html(ui,request)
        menu = E.tostring(menu)
        MENUS[u.profile] = menu
    context.update(menu=menu,E=E)
    web.extend_context(context)
    template = settings.LINO.jinja_env.get_template(tplname)
    
    response = http.HttpResponse(
        template.render(**context),
        content_type='text/html;charset="utf-8"')
    
    return response
Exemplo n.º 5
0
    def render(self, ar, output_file):
        context = {"action": self, "ar": ar, "as_html_table": self.as_html_table}

        extend_context(context)

        template = settings.SITE.plugins.jinja.renderer.jinja_env.get_template(self.template_name)
        html = template.render(**context).encode("utf-8")

        with open(output_file + ".html", "w") as file:
            file.write(html)

        result = cStringIO.StringIO()
        h = logging.FileHandler(output_file + ".log", "w")
        pisa.log.addHandler(h)
        pdf = pisa.pisaDocument(cStringIO.StringIO(html), result, encoding="utf-8")
        pisa.log.removeHandler(h)
        h.close()

        with open(output_file, "wb") as file:
            file.write(result.getvalue())
            file.close()

        if pdf.err:
            raise Exception("pisa.pisaDocument.err is %r" % pdf.err)