Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#3009 closed enhancement (wontfix)

Add a decorator for alters_data

Reported by: gulopine@… Owned by: Adrian Holovaty
Component: Tools Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It seems reasonable to me that functions which alter data should be able to use a decorator to denote that, rather than needing to set alters_data = True on a separate line after the function declaration. The following function, avaialble somewhere within Django, could be imported and used as a decorator to enable the alters_data functionality in a more understandable manner.

def alters_data(func):
    func.alters_data = True
    return func

Change History (7)

comment:1 by gulopine@…, 18 years ago

Type: defectenhancement

comment:2 by Adrian Holovaty, 18 years ago

Resolution: wontfix
Status: newclosed

Ehh, this isn't worth it. If people are too lazy to do it by setting a function attribute, they can include this decorator in their own code.

comment:3 by Orestis Markou <orestis@…>, 18 years ago

Resolution: wontfix
Status: closedreopened

Adrian: Why force people to do that ? There already are decorators the define attitude, like requires_login, user_passes_test, transaction.commit_on_success etc.

Providing this out of the box (as well as other decorators) provides a consistent experience on describing view function behavior.

comment:4 by Adrian Holovaty, 18 years ago

Resolution: wontfix
Status: reopenedclosed

Orestis: Those other decorators you mention all do complex things, whereas the alters_data decorator suggested in this ticket only does a simple thing that's already easy enough to do a different way.

comment:5 by James Bennett, 18 years ago

(stepping in after watching this one for a day or so)

I guess I'm kinda confused about what the efficiency gain is; regardless of which way it's done it's a single line of code to apply alters_data to a function; the only difference is that right now there's one way to do it (func.alters_data = True) while introducing a decorator would bump that to three (the original, plus each of the 2.3 and 2.4 decorator syntaxes).

What's the perceived gain from this?

comment:6 by gulopine@…, 18 years ago

Thank you for your prompt responses on this matter, and for giving it appropriate consideration.

comment:7 by Orestis Markou <orestis@…>, 18 years ago

Oops my bad. alter_data isn't defined in a view function, it's defined in a model/object function. So yes, creating a decorator for it seems unnecessary.

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