Skip to content
Myr

Add non-decorator template filter methods.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Suggested by @Poincare on GitHub, on @Reisen's pull request: https://github.com/mitsuhiko/flask/pull/272

authored by Ron DuPlain · committed by Ron DuPlain · parent 2a4d3ef · Browse files · 2 files+30 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+30 added−7 removed

  • other:+30 added−7 removed

2 files+30 added−7 removed

modified:flask/app.py+11 added-1 removed
1016 unmodified lines
1017 :param name: the optional name of the filter, otherwise the1018 function name will be used.1019 """1020 def decorator(f):1021 self.jinja_env.filters[name or f.__name__] = f1021 self.add_template_filter(f, name=name)1022 return f1023 return decorator10241025 @setupmethod1026 def add_template_filter(self, f, name=None):1027 """Register a custom template filter. Works exactly like the1028 :meth:`template_filter` decorator.10291030 :param name: the optional name of the filter, otherwise the1031 function name will be used.1032 """1033 self.jinja_env.filters[name or f.__name__] = f10341035 @setupmethod1036 def before_request(self, f):1037 """Registers a function to run before each request."""1038 self.before_request_funcs.setdefault(None, []).append(f)1039 return f
489 unmodified lines
modified:flask/blueprints.py+19 added-6 removed
183 unmodified lines
184 self.record_once(register_endpoint)185 return f186 return decorator187188 def app_template_filter(self, name = None):189 """Like :meth:`Flask.template_filter` but for a blueprint. The filter190 is available for the entire application.188 def app_template_filter(self, name=None):189 """Register a custom template filter, available application wide. Like190 :meth:`Flask.template_filter` but for a blueprint.191192 :param name: the optional name of the filter, otherwise the193 function name will be used.194 """195 def decorator(f):193 def register_template(state):194 state.app.jinja_env.filters[name or f.__name__] = f195 self.record_once(register_template)196 self.add_app_template_filter(f, name=name)197 return f198 return decorator199200 def add_app_template_filter(self, f, name=None):201 """Register a custom template filter, available application wide. Like202 :meth:`Flask.add_template_filter` but for a blueprint. Works exactly203 like the :meth:`app_template_filter` decorator.204205 :param name: the optional name of the filter, otherwise the206 function name will be used.207 """208 def register_template(state):209 state.app.jinja_env.filters[name or f.__name__] = f210 self.record_once(register_template)211212 def before_request(self, f):213 """Like :meth:`Flask.before_request` but for a blueprint. This function214 is only executed before each request that is handled by a function of215 that blueprint.
130 unmodified lines