Пример #1
0
 def render(self, context):
     # flatten the Django Context into a single dictionary.
     #~ logger.info("20130118 %s",context)
     context_dict = {}
     for d in context.dicts:
         context_dict.update(d)
     # extend_context(context_dict)
     ar = requests.BaseRequest(
         renderer=settings.SITE.plugins.jinja.renderer)
     # renderer=settings.SITE.kernel.default_renderer)
     context_dict = ar.get_printable_context(**context_dict)
     context_dict.setdefault('request', None)
     #context_dict.setdefault('ar', ar)
     #~ logger.info("20130118 %s",context_dict.keys())
     return self.jt.render(context_dict)
Пример #2
0
    def render_from_request(self, request, template_name, **context):
        """Adds some more context names.

        Replaces ar.renderer is not a HtmlRenderer but the Site's
        default_renderer.

        """
        from lino.core import requests
        context.update(request=request)
        ar = requests.BaseRequest(
            # renderer=settings.SITE.plugins.jinja.renderer,
            renderer=self.site.kernel.default_renderer,
            request=request)
        context = ar.get_printable_context(**context)
        context.update(ar=ar)
        template = self.renderer.jinja_env.get_template(template_name)
        return template.render(**context)
Пример #3
0
    def render_from_request(self, request, template_name, **context):
        """Render the named Jinja template, replacing ar.renderer by the
        Site's default renderer.
        Adds some more context names.
        """
        from lino.core import requests
        context.update(request=request)
        ar = requests.BaseRequest(
            # renderer=settings.SITE.plugins.jinja.renderer,
            renderer=self.site.kernel.default_renderer,
            request=request)
        # self.site.logger.info(
        #     "20160529 render_from_request() %s",
        #     self.site.kernel.default_renderer)

        context = ar.get_printable_context(**context)
        context.update(ar=ar)
        template = self.renderer.jinja_env.get_template(template_name)
        return template.render(**context)