Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It looks like the secretary tool doesn't work with the latest Jinja #73

Open
M-Startc opened this issue Aug 22, 2021 · 5 comments · May be fixed by #74
Open

It looks like the secretary tool doesn't work with the latest Jinja #73

M-Startc opened this issue Aug 22, 2021 · 5 comments · May be fixed by #74

Comments

@M-Startc
Copy link

M-Startc commented Aug 22, 2021

I have Jinja2=3.0.1 and I see "jinja2.nodes.EvalContext object at ...." in the document fields instead of the needed content.
I could get the secretary tool working after Jinja2 downgrade to 2.11.2
I use python 3.8 in my project and use the tool with OpenOffice odt document

Thank you

@Jonathan-Cortex
Copy link

I second this, exact same symptoms in a project I'm working on, jinja >3 doesn't work and gives "jinja2.nodes.EvalContext object at ..." but works fine after downgrade. I used the same version as M-Startc to be sure (Your comment saved me btw, thank you !). Python 3.8 as well.

@tigerfoot
Copy link

same

@Jenselme Jenselme linked a pull request Sep 25, 2021 that will close this issue
@Jenselme
Copy link

In addition to my PR #74, if you can't apply it, you should be able to prevent the issue by passing a custom environment:

from secretary import Renderer, UndefinedSilently, pad_string
from jinja2 import Environment
# markupsafe is a dependency of jinja2.
from markupsafe import Markup

def finalize_value(value):
    if isinstance(value, Markup):
            return value

    # get_escaped_var_value is a static method.
    return Markup(Renderer.get_escaped_var_value(value))

environment = Environment(undefined=UndefinedSilently,
                                           autoescape=True,
                                           finalize=finalize_value)
environment.filters['pad'] = pad_string
environment.globals['SafeValue'] = Markup
renderer = Renderer(environment)
# Those are standard method, we need to have a proper instance for them to work.
environment.filters['markdown'] = renderer.markdown_filter
environment.filters['image'] = renderer.image_filter

I haven't tested it but it should work and provide you the same level of functionality.

@raffienficiaud
Copy link

@Jenselme tested and it works, thanks!

@PhE
Copy link

PhE commented Aug 2, 2022

You can also patch jinja before importing secretary:

    import jinja2
    import markupsafe
    jinja2.Markup = markupsafe.Markup
    jinja2.evalcontextfilter = jinja2.pass_context
    import secretary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants