-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add executed filter to SafeOperation
- Add also more filters - Closes #2314
- Loading branch information
Showing
6 changed files
with
130 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import django_filters | ||
from django_filters import rest_framework as filters | ||
from safe_eth.eth.django.filters import Keccak256Filter | ||
|
||
from safe_transaction_service.utils.filters import filter_overrides | ||
|
||
from .models import SafeOperation | ||
|
||
|
||
class SafeOperationFilter(filters.FilterSet): | ||
executed = django_filters.BooleanFilter(method="filter_executed") | ||
has_confirmations = django_filters.BooleanFilter(method="filter_confirmations") | ||
execution_date__gte = django_filters.IsoDateTimeFilter( | ||
field_name="user_operation__ethereum_tx__block__timestamp", lookup_expr="gte" | ||
) | ||
execution_date__lte = django_filters.IsoDateTimeFilter( | ||
field_name="user_operation__ethereum_tx__block__timestamp", lookup_expr="lte" | ||
) | ||
submission_date__gte = django_filters.IsoDateTimeFilter( | ||
field_name="created", lookup_expr="gte" | ||
) | ||
submission_date__lte = django_filters.IsoDateTimeFilter( | ||
field_name="created", lookup_expr="lte" | ||
) | ||
transaction_hash = Keccak256Filter(field_name="user_operation__ethereum_tx_id") | ||
|
||
def filter_confirmations(self, queryset, _name: str, value: bool): | ||
if value: | ||
return queryset.with_confirmations() | ||
else: | ||
return queryset.without_confirmations() | ||
|
||
def filter_executed(self, queryset, _name: str, value: bool): | ||
if value: | ||
return queryset.executed() | ||
else: | ||
return queryset.not_executed() | ||
|
||
class Meta: | ||
model = SafeOperation | ||
fields = { | ||
"modified": ["lt", "gt", "lte", "gte"], | ||
"valid_after": ["lt", "gt", "lte", "gte"], | ||
"valid_until": ["lt", "gt", "lte", "gte"], | ||
"module_address": ["exact"], | ||
} | ||
filter_overrides = filter_overrides |
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
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
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,13 @@ | ||
import django_filters | ||
from safe_eth.eth.django.filters import EthereumAddressFilter, Keccak256Filter | ||
from safe_eth.eth.django.models import ( | ||
EthereumAddressBinaryField, | ||
Keccak256Field, | ||
Uint256Field, | ||
) | ||
|
||
filter_overrides = { | ||
Uint256Field: {"filter_class": django_filters.NumberFilter}, | ||
Keccak256Field: {"filter_class": Keccak256Filter}, | ||
EthereumAddressBinaryField: {"filter_class": EthereumAddressFilter}, | ||
} |