42
42
chart_filters_decoder ,
43
43
chart_permission_decorator ,
44
44
encode_ids ,
45
+ get_lowest_admin_area ,
45
46
get_model_choices_fields ,
46
47
get_program_id_from_headers ,
47
48
resolve_flex_fields_choices_to_string ,
48
49
sum_lists_with_values ,
49
- to_choice_object , get_lowest_admin_area ,
50
+ to_choice_object ,
50
51
)
52
+ from hct_mis_api .apps .geo .models import Area
51
53
from hct_mis_api .apps .geo .schema import AreaNode
52
54
from hct_mis_api .apps .grievance .models import GrievanceTicket
53
55
from hct_mis_api .apps .household .filters import (
@@ -345,9 +347,9 @@ def resolve_phone_no_alternative_valid(parent, info: Any) -> Boolean:
345
347
def resolve_delivery_mechanisms_data (parent , info : Any ) -> QuerySet [DeliveryMechanismData ]:
346
348
program_id = get_program_id_from_headers (info .context .headers )
347
349
if not info .context .user .has_permission (
348
- Permissions .POPULATION_VIEW_INDIVIDUAL_DELIVERY_MECHANISMS_SECTION .value ,
349
- parent .business_area ,
350
- program_id ,
350
+ Permissions .POPULATION_VIEW_INDIVIDUAL_DELIVERY_MECHANISMS_SECTION .value ,
351
+ parent .business_area ,
352
+ program_id ,
351
353
):
352
354
return parent .delivery_mechanisms_data .none ()
353
355
@@ -378,9 +380,9 @@ def check_node_permission(cls, info: Any, object_instance: Individual) -> None:
378
380
379
381
# if user can't simply view all individuals, we check if they can do it because of grievance or rdi details
380
382
if not user .has_permission (
381
- Permissions .POPULATION_VIEW_INDIVIDUALS_DETAILS .value ,
382
- object_instance .business_area ,
383
- object_instance .program_id ,
383
+ Permissions .POPULATION_VIEW_INDIVIDUALS_DETAILS .value ,
384
+ object_instance .business_area ,
385
+ object_instance .program_id ,
384
386
) and not user .has_permission (
385
387
Permissions .RDI_VIEW_DETAILS .value ,
386
388
object_instance .business_area ,
@@ -469,8 +471,8 @@ def resolve_sanction_list_confirmed_match(parent: Household, info: Any) -> bool:
469
471
return parent .sanction_list_confirmed_match
470
472
471
473
@staticmethod
472
- def resolve_admin_area (self , info : Any ) -> AreaNode :
473
- return get_lowest_admin_area (self )
474
+ def resolve_admin_area (parent : Household , info : Any ) -> Optional [ Area ] :
475
+ return get_lowest_admin_area (parent )
474
476
475
477
@staticmethod
476
478
def resolve_admin_area_title (parent : Household , info : Any ) -> str :
@@ -555,9 +557,9 @@ def check_node_permission(cls, info: Any, object_instance: Household) -> None:
555
557
556
558
# if user doesn't have permission to view all households or RDI details, we check based on their grievance tickets
557
559
if not user .has_permission (
558
- Permissions .POPULATION_VIEW_HOUSEHOLDS_DETAILS .value ,
559
- object_instance .business_area ,
560
- object_instance .program_id ,
560
+ Permissions .POPULATION_VIEW_HOUSEHOLDS_DETAILS .value ,
561
+ object_instance .business_area ,
562
+ object_instance .program_id ,
561
563
) and not user .has_permission (
562
564
Permissions .RDI_VIEW_DETAILS .value ,
563
565
object_instance .business_area ,
@@ -816,16 +818,19 @@ def resolve_all_households(self, info: Any, **kwargs: Any) -> QuerySet:
816
818
817
819
queryset = queryset .filter (filter_q )
818
820
819
- if does_path_exist_in_query ("edges.node.admin1" , info ) or does_path_exist_in_query ("edges.node.admin_area" ,
820
- info ):
821
+ if does_path_exist_in_query ("edges.node.admin1" , info ) or does_path_exist_in_query (
822
+ "edges.node.admin_area" , info
823
+ ):
821
824
queryset = queryset .select_related ("admin1" )
822
825
queryset = queryset .select_related ("admin1__area_type" )
823
- if does_path_exist_in_query ("edges.node.admin2" , info ) or does_path_exist_in_query ("edges.node.admin_area" ,
824
- info ):
826
+ if does_path_exist_in_query ("edges.node.admin2" , info ) or does_path_exist_in_query (
827
+ "edges.node.admin_area" , info
828
+ ):
825
829
queryset = queryset .select_related ("admin2" )
826
830
queryset = queryset .select_related ("admin2__area_type" )
827
- if does_path_exist_in_query ("edges.node.admin3" , info ) or does_path_exist_in_query ("edges.node.admin_area" ,
828
- info ):
831
+ if does_path_exist_in_query ("edges.node.admin3" , info ) or does_path_exist_in_query (
832
+ "edges.node.admin_area" , info
833
+ ):
829
834
queryset = queryset .select_related ("admin3" )
830
835
queryset = queryset .select_related ("admin3__area_type" )
831
836
@@ -899,7 +904,7 @@ def resolve_deduplication_status_choices(self, info: Any, **kwargs: Any) -> List
899
904
@chart_permission_decorator (permissions = [Permissions .DASHBOARD_VIEW_COUNTRY ])
900
905
@cached_in_django_cache (24 )
901
906
def resolve_section_households_reached (
902
- self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
907
+ self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
903
908
) -> Dict [str , int ]:
904
909
payment_items_qs : "QuerySet" = get_payment_items_for_dashboard (
905
910
year , business_area_slug , chart_filters_decoder (kwargs ), True
@@ -909,7 +914,7 @@ def resolve_section_households_reached(
909
914
@chart_permission_decorator (permissions = [Permissions .DASHBOARD_VIEW_COUNTRY ])
910
915
@cached_in_django_cache (24 )
911
916
def resolve_section_individuals_reached (
912
- self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
917
+ self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
913
918
) -> Dict [str , int ]:
914
919
payment_items_qs : "QuerySet" = get_payment_items_for_dashboard (
915
920
year , business_area_slug , chart_filters_decoder (kwargs ), True
@@ -920,7 +925,7 @@ def resolve_section_individuals_reached(
920
925
@chart_permission_decorator (permissions = [Permissions .DASHBOARD_VIEW_COUNTRY ])
921
926
@cached_in_django_cache (24 )
922
927
def resolve_section_people_reached (
923
- self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
928
+ self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
924
929
) -> Dict [str , int ]:
925
930
payment_items_qs : "QuerySet" = get_payment_items_for_dashboard (
926
931
year , business_area_slug , chart_filters_decoder (kwargs ), True
@@ -931,7 +936,7 @@ def resolve_section_people_reached(
931
936
@chart_permission_decorator (permissions = [Permissions .DASHBOARD_VIEW_COUNTRY ])
932
937
@cached_in_django_cache (24 )
933
938
def resolve_section_child_reached (
934
- self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
939
+ self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
935
940
) -> Dict [str , int ]:
936
941
households_child_params = [
937
942
"female_age_group_0_5_count" ,
@@ -951,7 +956,7 @@ def resolve_section_child_reached(
951
956
@chart_permission_decorator (permissions = [Permissions .DASHBOARD_VIEW_COUNTRY ])
952
957
@cached_in_django_cache (24 )
953
958
def resolve_chart_individuals_reached_by_age_and_gender (
954
- self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
959
+ self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
955
960
) -> Dict :
956
961
households_params = [
957
962
"female_age_group_0_5_count" ,
@@ -979,7 +984,7 @@ def resolve_chart_individuals_reached_by_age_and_gender(
979
984
@chart_permission_decorator (permissions = [Permissions .DASHBOARD_VIEW_COUNTRY ])
980
985
@cached_in_django_cache (24 )
981
986
def resolve_chart_people_reached_by_age_and_gender (
982
- self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
987
+ self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
983
988
) -> Dict :
984
989
households_params = [
985
990
"female_age_group_0_5_count" ,
@@ -1007,7 +1012,7 @@ def resolve_chart_people_reached_by_age_and_gender(
1007
1012
@chart_permission_decorator (permissions = [Permissions .DASHBOARD_VIEW_COUNTRY ])
1008
1013
@cached_in_django_cache (24 )
1009
1014
def resolve_chart_individuals_with_disability_reached_by_age (
1010
- self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
1015
+ self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
1011
1016
) -> Dict :
1012
1017
households_params_with_disability = [
1013
1018
"female_age_group_0_5_disabled_count" ,
@@ -1069,7 +1074,7 @@ def resolve_chart_individuals_with_disability_reached_by_age(
1069
1074
@chart_permission_decorator (permissions = [Permissions .DASHBOARD_VIEW_COUNTRY ])
1070
1075
@cached_in_django_cache (24 )
1071
1076
def resolve_chart_people_with_disability_reached_by_age (
1072
- self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
1077
+ self , info : Any , business_area_slug : str , year : int , ** kwargs : Any
1073
1078
) -> Dict :
1074
1079
households_params_with_disability = [
1075
1080
"female_age_group_0_5_disabled_count" ,
0 commit comments