Code

Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#16726 closed Cleanup/optimization (duplicate)

Make is_safe decorator for filters

Reported by: kostia.balitsky@… Owned by: jezdez
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 

?

Attachments (0)

Change History (9)

comment:1 Changed 3 years ago by jezdez

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from New feature to Cleanup/optimization
  • Version changed from 1.2 to SVN

comment:2 follow-up: Changed 3 years ago by russellm

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

comment:3 Changed 3 years ago by jezdez

Sounds good to me, too.

comment:4 in reply to: ↑ 2 Changed 3 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 3 years ago by jezdez

  • Owner changed from nobody to jezdez
  • Status changed from new to assigned

comment:6 Changed 3 years ago by jezdez

  • Resolution set to duplicate
  • Status changed from assigned to closed

Actually this is a dupe of #6135.

comment:7 follow-up: Changed 3 years ago by jezdez

.. 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 3 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 2 years ago by aaugustin

In [17056]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.