-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor for decorator and determining no queryset action names
- Loading branch information
1 parent
9bbce0e
commit 042e598
Showing
2 changed files
with
42 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from functools import wraps | ||
from types import FunctionType | ||
|
||
|
||
NO_QUERYSET_ACTION_ATTRIBUTE = "no_queryset_action" | ||
|
||
|
||
def no_queryset_action(action_function: FunctionType): | ||
""" | ||
Decorator to remove `queryset` parameter from being passed to action function. | ||
""" | ||
|
||
if getattr(action_function, NO_QUERYSET_ACTION_ATTRIBUTE, None) is not None: | ||
return action_function | ||
|
||
@wraps(action_function) | ||
def wrapper(*args, **kwargs): | ||
modeladmin, request, queryset, *rest = args | ||
return action_function(modeladmin, request, *rest, **kwargs) | ||
|
||
setattr(wrapper, NO_QUERYSET_ACTION_ATTRIBUTE, True) | ||
|
||
return wrapper |