-
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.
Merge pull request #52 from onehealthtoolkit/fix_issues
OSDAS-291 report/case filter include child authorities.
- Loading branch information
Showing
3 changed files
with
70 additions
and
19 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
from graphene.types.generic import GenericScalar | ||
from graphene_django import DjangoObjectType | ||
from django.db.models import Q | ||
from accounts.models import Authority | ||
|
||
from accounts.schema.types import UserType, AuthorityType | ||
from common.types import AdminValidationProblem | ||
|
@@ -77,6 +78,36 @@ class Meta: | |
] | ||
|
||
|
||
## Report type | ||
class IncidentReportTypeFilter(django_filters.FilterSet): | ||
include_child_authorities = django_filters.BooleanFilter( | ||
method="child_authorities_filter" | ||
) | ||
|
||
class Meta: | ||
model = IncidentReport | ||
fields = { | ||
"created_at": ["lte", "gte"], | ||
"incident_date": ["lte", "gte"], | ||
"relevant_authorities__name": ["istartswith", "exact"], | ||
"relevant_authorities__id": ["in"], | ||
"report_type__id": ["in"], | ||
"test_flag": ["exact"], | ||
} | ||
|
||
def child_authorities_filter(self, queryset, name, value): | ||
relevant_authorities = self.data["relevant_authorities__id__in"] | ||
if relevant_authorities and len(relevant_authorities) == 1: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pphetra
Author
Contributor
|
||
include_child_authorities = self.data["include_child_authorities"] | ||
if include_child_authorities: | ||
authority = Authority.objects.get(pk=relevant_authorities[0]) | ||
child_authorities = authority.all_inherits_down() | ||
queryset = queryset.filter(relevant_authorities__in=child_authorities) | ||
print(queryset.query) | ||
|
||
return queryset | ||
|
||
|
||
class IncidentReportType(DjangoObjectType): | ||
data = GenericScalar() | ||
original_data = GenericScalar() | ||
|
@@ -115,14 +146,7 @@ class Meta: | |
"followups", | ||
"is_followable", | ||
] | ||
filter_fields = { | ||
"created_at": ["lte", "gte"], | ||
"incident_date": ["lte", "gte"], | ||
"relevant_authorities__name": ["istartswith", "exact"], | ||
"relevant_authorities__id": ["in"], | ||
"report_type__id": ["in"], | ||
"test_flag": ["exact"], | ||
} | ||
filterset_class = IncidentReportTypeFilter | ||
|
||
def resolve_gps_location(self, info): | ||
return self.gps_location_str | ||
|
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
@wattana ให้ loop relevant_authorities และหา down authorities มา merge รวมกันก้อน query