-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dobson
committed
Jun 3, 2024
1 parent
fd6f068
commit 155271e
Showing
2 changed files
with
38 additions
and
25 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,33 @@ | ||
def model_attribute(obj, attribute_name): | ||
""" | ||
Decorator to extend or modify a model attribute. | ||
Args: | ||
obj: The model object whose attribute should be modified. | ||
attribute_name (str): The name of the attribute to modify. | ||
Returns: | ||
A decorator function that takes the extension function as an argument. | ||
""" | ||
def decorator(func): | ||
""" | ||
Decorator function that applies the extension function to the model attribute. | ||
Args: | ||
func: The extension function that modifies the model attribute. | ||
""" | ||
attribute = getattr(obj, attribute_name) | ||
|
||
def wrapped_attribute(*args, **kwargs): | ||
return func(attribute, *args, **kwargs) | ||
|
||
setattr(obj, attribute_name, wrapped_attribute) | ||
return wrapped_attribute | ||
|
||
return decorator | ||
|
||
|
||
@model_attribute(obj=my_fwtw, attribute_name="pull_distributed") | ||
def new_distributed(pull_distributed, vqip): | ||
"""pull_distributed with the tag 'FWTW'.""" | ||
return pull_distributed(vqip, tag="FWTW") |