Decorators¶
decorators
¶
parametrized(decorator)
¶
Meta-decorator that allows decorators to accept arguments while preserving IDE intellisense.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decorator
|
The decorator function to wrap. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
A wrapper that accepts decorator arguments and returns the decorated function. |
cache_data(func, timeout, by_args=False, enabled=True, custom_cache=None)
¶
Cache the return value of a function using Django's cache framework.
Useful for expensive calculations or database queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
The function to decorate (injected by |
required | |
timeout
|
int
|
Cache timeout in seconds. |
required |
by_args
|
If True, cache separately per unique arguments. Defaults to False. |
False
|
|
enabled
|
Toggle caching on/off. Defaults to True. |
True
|
|
custom_cache
|
Optional custom cache backend instance. Defaults to Django's default cache. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Wrapped function with caching. |
log_exec_time(func, func_name=None, enabled=getattr(settings, 'DR_LOG_EXEC_TIME', False), log_args=False)
¶
Log the execution time of a function via PrintLogger.
Can be enabled globally by setting DR_LOG_EXEC_TIME = True in Django settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
The function to decorate (injected by |
required | |
func_name
|
Custom name for log output. Defaults to the function's |
None
|
|
enabled
|
Toggle logging on/off. Defaults to |
getattr(settings, 'DR_LOG_EXEC_TIME', False)
|
|
log_args
|
If True, include function arguments in the log key. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Wrapped function that logs its execution time. |