onconova.core.anonymization.decorator
AnonymizationBase(*, pass_parameter=None, **kwargs)
¶
Bases: ABC
Base class for implementing anonymization logic in data access layers.
Attributes:
Name | Type | Description |
---|---|---|
InputSource |
Query parameter for input source (type: Query). |
|
Input |
Schema
|
Nested schema class with an 'anonymized' boolean field to indicate whether data should be anonymized. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str | None
|
Optional parameter to pass through the anonymization process. |
None
|
|
Any
|
Additional keyword arguments. |
{}
|
Methods:
Name | Description |
---|---|
anonymize_queryset |
|
Source code in onconova/core/anonymization/decorator.py
InputSource
class-attribute
instance-attribute
¶
pass_parameter
instance-attribute
¶
anonymize_queryset(data, anonymized=True, **params)
¶
Anonymizes the provided data (QuerySet, DjangoModel, or Schema) based on the user's permissions and the anonymized
flag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
QuerySet | Model | Schema
|
The data to be anonymized. Can be a Django QuerySet, a Django model instance, or a Schema object. |
required |
|
bool
|
If True, the data will be marked as anonymized. If False, checks if the user has permission to access non-anonymized data. Defaults to True. |
True
|
|
Any
|
Additional parameters. Must include 'request' containing the HTTP request object. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The anonymized data, with an 'anonymized' attribute or annotation set to True if applicable. |
Raises:
Type | Description |
---|---|
HttpError
|
If the 'request' parameter is missing or if the user lacks permission to access non-anonymized data. |
Source code in onconova/core/anonymization/decorator.py
AnonymizationOperation(*, anonymization, view_func, anonymization_kwargs_name='anonymization')
¶
AnonymizationOperation is a decorator class that wraps a view function to apply anonymization logic to its output.
This class is designed to integrate with a view function, intercept its output (typically a queryset), and apply an anonymization process before returning the result. It supports injecting anonymization parameters into the view function and ensures compatibility with frameworks that use request or controller objects.
Source code in onconova/core/anonymization/decorator.py
anonymization
instance-attribute
¶
anonymization_kwargs_name
instance-attribute
¶
as_view
instance-attribute
¶
view_func
instance-attribute
¶
view_func_has_kwargs
property
¶
get_view_function()
¶
Source code in onconova/core/anonymization/decorator.py
anonymize(func_or_pgn_class=NOT_SET, **anonymization_params)
¶
Decorator to inject anonymization logic into a function or class.
This decorator can be used without parameters: @anonymize
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Any
|
The function or class to be decorated. Defaults to NOT_SET. |
NOT_SET
|
|
Any
|
Additional parameters for anonymization. |
{}
|
Returns:
Type | Description |
---|---|
Callable[..., Any]
|
Callable[..., Any]: The decorated function or class with anonymization logic applied. |