Add label/description decorator for "cleaner" code
See original GitHub issuePerhaps it’s something that only irks me, but I find that this syntax quickly becomes readable after the function goes beyond a few lines:
def publish_this(self, request, obj):
publish_obj(obj)
publish_this.label = "Publish" # optional
publish_this.short_description = "Submit this article" # optional
I’m currently using this little decorator to take care of the labels and description which works great:
def create_action(label=None, short_description=None):
def _create_action(function):
if label:
function.label = label
if short_description:
function.short_description = short_description
return function
return _create_action
Usage is like this:
@create_action('Publish', 'Submit this article')
def publish_this(self, request, obj):
publish_obj(obj)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:14 (11 by maintainers)
Top Results From Across the Web
NestJS: Clean Code With Decorators | by LiftOff LLC - Medium
TL;DR Decorator is a sort of declaration that can be used changing behaviour of a property or adding meta data to a class/property/method...
Read more >VS Code API | Visual Studio Code Extension API
VS Code API is a set of JavaScript APIs that you can invoke in your Visual Studio Code extension. This page lists all...
Read more >Decorators in Python: A Complete Guide (with Examples)
Python decorators offer a way to extend the behavior of a function or method. Use decorators avoid repetition and improve the code quality....
Read more >Toyota bZ4X - Take Charge of the Future | Toyota.com
Visit the official Toyota site to explore the features of the new bZ4X, or find a local dealer to learn more about this...
Read more >Primer on Python Decorators
As you saw in the previous section, when a decorator uses arguments, you need to add an extra outer function. The challenge is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There was some sort of cleanup thing I was going to do before a release but now I can’t remember. So I’ll just hit the button to release!
New release on pypi?