On Monday, May 2, 2016 at 3:48:04 PM UTC-4, Waylan Limberg wrote:
>
> [snip]
>
> Then I used a subclass of the Context class which overrides the `resolve`
> method. If the `key` name is in the list of known deprecated variables,
> then a warning is logged. In either case, the parent classes `resolve`
> method is then called and everything works as before. This works, but
> causes the same warning to be issued for every page that the template is
> used. If a user has a lot of pages, that is a lot of warnings. Anyone have
> any better suggestions and/or know of any existing working solutions.
>
>
For completeness, this is essentially what we have now:
deprecated_vars = ["foo_name", "foo_bar", "foo_baz"]
class DeprecationContext(Context):
def resolve(self, key):
""" Log a warning when acessing any deprecated variable name.
"""
if key in deprecated_vars:
replacement = key.replace('_', '.')
log.warn(
"Template variable warning: '{0}' is being deprecated
and will not be "
"available in a future version. Use '{1}'
instead.".format(key, replacement)
)
return super(DeprecationContext, self).resolve(key)
env = jinja2.Environment(loader=loader)
env.context_class = DeprecationContext
I suppose we could create some sort of simple cache and only issue the
warning if a warning has not yet been issued for the given variable. But
ideally, we would be able to indicate which template file the variable was
used and even a location (line, column) in the warning message. However, I
don't see how that information would even be available without a much more
complex solution.
I'm not really interested in developing a complex solution for the entire
thing to be deleted in a version or two. However, if there is an existing
solution that already have the kinks worked out, I'd be very interested in
that.
Waylan
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.