Example #1
0
    def rendered(self, values, template_name):
        """Return the rendered content of a Jinja2 Template.

        Per default the template is provided with the `uri` and `credential` variables plus everything
        which is given in `values`."""
        import jinja2
        import jinja_filters

        env = self.create_jinja2env()
        jinja_filters.register_custom_filters(env)
        try:
            template = env.get_template(template_name)
        except jinja2.TemplateNotFound:
            # better error reporting - we want to see the name of the base template
            raise jinja2.TemplateNotFound(template_name)
        myval = dict(uri=self.request.url, credential=self.credential)
        myval.update(self.default_template_vars(values))
        self._expire_messages()
        myval.update(dict(_gaetk_messages=self.session.get('_gaetk_messages', [])))
        try:
            content = template.render(myval)
        except jinja2.TemplateNotFound:
            # better error reporting
            logging.info('jinja environment: %s', env)
            logging.info('template dirs: %s', config.template_dirs)
            raise
        return content
Example #2
0
    def rendered(self, values, template_name):
        """Return the rendered content of a Jinja2 Template.

        Per default the template is provided with the `uri` and `credential` variables plus everything
        which is given in `values`."""
        import jinja2
        env = jinja2.Environment(loader=jinja2.FileSystemLoader(config.template_dirs))
        jinja_filters.register_custom_filters(env)
        try:
            template = env.get_template(template_name)
        except jinja2.TemplateNotFound:
            raise jinja2.TemplateNotFound(template_name)
        myval = dict(uri=self.request.url, credential=self.credential)
        myval.update(self.default_template_vars(values))
        content = template.render(myval)
        return content
Example #3
0
    def rendered(self, values, template_name):
        """Return the rendered content of a Jinja2 Template.

        Per default the template is provided with the `uri` and `credential` variables plus everything
        which is given in `values`."""
        import jinja2
        import jinja_filters

        env = self.create_jinja2env()
        jinja_filters.register_custom_filters(env)
        try:
            template = env.get_template(template_name)
        except jinja2.TemplateNotFound:
            raise jinja2.TemplateNotFound(template_name)
        myval = dict(uri=self.request.url, credential=self.credential)
        myval.update(self.default_template_vars(values))
        self._expire_messages()
        myval.update(dict(_gaetk_messages=self.session.get('_gaetk_messages', [])))
        content = template.render(myval)
        return content