Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#16726 closed Cleanup/optimization (duplicate)

Make is_safe decorator for filters

Reported by: kostia.balitsky@… Owned by: Jannis Leidel
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Why not turn boring process of coding

@register.filter('amazing')
def amazing(value):
    # Not doing anything unsafe ;)
    ...
    return new_value
amazing.is_safe = True

into something more interesting like

@register.safe_filter('amazing')
def amazing(value):
    # Not doing anything unsafe ;)
    ...
    return new_value 

?

Change History (9)

comment:1 Changed 5 years ago by Jannis Leidel

Triage Stage: UnreviewedAccepted
Type: New featureCleanup/optimization
Version: 1.2SVN

comment:2 Changed 5 years ago by Russell Keith-Magee

I'd much rather see a separate @is_safe decorator, rather than a single-purpose @safe_filter.

comment:3 Changed 5 years ago by Jannis Leidel

Sounds good to me, too.

comment:4 in reply to:  2 Changed 5 years ago by anonymous

Replying to russellm:

I'd much rather see a separate @is_safe decorator, rather than a single-purpose @safe_filter.

It's not a big deal to implement both of them :)

comment:5 Changed 5 years ago by Jannis Leidel

Owner: changed from nobody to Jannis Leidel
Status: newassigned

comment:6 Changed 5 years ago by Jannis Leidel

Resolution: duplicate
Status: assignedclosed

Actually this is a dupe of #6135.

comment:7 Changed 5 years ago by Jannis Leidel

.. at least in the sense that both is_safe and needs_autoescape only set a flag on the filter functions.

comment:8 in reply to:  7 Changed 5 years ago by anonymous

Replying to jezdez:

.. at least in the sense that both is_safe and needs_autoescape only set a flag on the filter functions.

But they are supposed to do different things, correct?

comment:9 Changed 5 years ago by Aymeric Augustin

In [17056]:

Fixed #17135 -- Made it possible to use decorators (like stringfilter) on template filter functions in combination with auto-escaping. Refs #16726.

Note: See TracTickets for help on using tickets.
Back to Top