def _to_case_export_instance_filters(self, can_access_all_locations, accessible_location_ids): emwf_selections = self.cleaned_data["emwf_case_filter"] return CaseExportInstanceFilters( date_period=DatePeriod( period_type=self.cleaned_data['date_range'], days=self.cleaned_data['days'], begin=self.cleaned_data['start_date'], end=self.cleaned_data['end_date'], ), users=CaseListFilter.selected_user_ids(emwf_selections), reporting_groups=CaseListFilter.selected_reporting_group_ids( emwf_selections), locations=CaseListFilter.selected_location_ids(emwf_selections), user_types=CaseListFilter.selected_user_types(emwf_selections), can_access_all_locations=can_access_all_locations, accessible_location_ids=accessible_location_ids, sharing_groups=CaseListFilter.selected_sharing_group_ids( emwf_selections), show_all_data=CaseListFilter.show_all_data(emwf_selections) or CaseListFilter.no_filters_selected(emwf_selections), show_project_data=CaseListFilter.show_project_data( emwf_selections), )
def _build_query(self): query = (self.search_class() .domain(self.domain) .size(self.pagination.count) .start(self.pagination.start)) query.es_query['sort'] = self.get_sorting_block() mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) user_types = EMWF.selected_user_types(mobile_user_and_group_slugs) if self.case_filter: query = query.filter(self.case_filter) query = query.NOT(case_es.case_type("user-owner-mapping-case")) if self.case_type: query = query.case_type(self.case_type) if self.case_status: query = query.is_closed(self.case_status == 'closed') if self.request.can_access_all_locations and (EMWF.show_all_data(mobile_user_and_group_slugs) or EMWF.no_filters_selected(mobile_user_and_group_slugs)): pass elif self.request.can_access_all_locations and EMWF.show_project_data(mobile_user_and_group_slugs): # Show everything but stuff we know for sure to exclude ids_to_exclude = self.get_special_owner_ids( admin=HQUserType.ADMIN not in user_types, unknown=HQUserType.UNKNOWN not in user_types, web=HQUserType.WEB not in user_types, demo=HQUserType.DEMO_USER not in user_types, commtrack=False, ) query = query.NOT(case_es.owner(ids_to_exclude)) elif self.request.can_access_all_locations and EMWF.show_deactivated_data(mobile_user_and_group_slugs): owner_ids = (user_es.UserES() .show_only_inactive() .domain(self.domain) .get_ids()) query = query.OR(case_es.owner(owner_ids)) else: # Only show explicit matches query = query.owner(self.case_owners) if not self.request.can_access_all_locations: query = query.OR(self.scope_filter()) search_string = CaseSearchFilter.get_value(self.request, self.domain) if search_string: query = query.set_query({"query_string": {"query": search_string}}) return query
def _build_query(self): query = (self.search_class().domain(self.domain).size( self.pagination.count).start(self.pagination.start)) query.es_query['sort'] = self.get_sorting_block() mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) user_types = EMWF.selected_user_types(mobile_user_and_group_slugs) if self.case_filter: query = query.filter(self.case_filter) query = query.NOT(case_es.case_type("user-owner-mapping-case")) if self.case_type: query = query.case_type(self.case_type) if self.case_status: query = query.is_closed(self.case_status == 'closed') if self.request.can_access_all_locations and ( EMWF.show_all_data(mobile_user_and_group_slugs) or EMWF.no_filters_selected(mobile_user_and_group_slugs)): pass elif self.request.can_access_all_locations and EMWF.show_project_data( mobile_user_and_group_slugs): # Show everything but stuff we know for sure to exclude ids_to_exclude = self.get_special_owner_ids( admin=HQUserType.ADMIN not in user_types, unknown=HQUserType.UNKNOWN not in user_types, web=HQUserType.WEB not in user_types, demo=HQUserType.DEMO_USER not in user_types, commtrack=False, ) query = query.NOT(case_es.owner(ids_to_exclude)) elif self.request.can_access_all_locations and EMWF.show_deactivated_data( mobile_user_and_group_slugs): owner_ids = (user_es.UserES().show_only_inactive().domain( self.domain).get_ids()) query = query.OR(case_es.owner(owner_ids)) else: # Only show explicit matches query = query.owner(self.case_owners) if not self.request.can_access_all_locations: query = query.OR(self.scope_filter()) search_string = CaseSearchFilter.get_value(self.request, self.domain) if search_string: query = query.set_query({"query_string": {"query": search_string}}) return query
def get_filtered_query(self, query): if self.request.can_access_all_locations and (EMWF.show_all_data( self.value) or EMWF.no_filters_selected(self.value)): return query if self.request.can_access_all_locations and EMWF.show_project_data( self.value): return query_all_project_data(query, self.domain, self.value) if self.request.can_access_all_locations and EMWF.show_deactivated_data( self.value): return query_deactivated_data(query, self.domain) # otherwise only return explicit matches case_owners = get_case_owners(self.request, self.domain, self.value) return query.owner(case_owners)
def get_filtered_query(self, query): if self.request.can_access_all_locations and ( EMWF.show_all_data(self.value) or EMWF.no_filters_selected(self.value) ): return query if self.request.can_access_all_locations and EMWF.show_project_data(self.value): return query_all_project_data(query, self.domain, self.value) if self.request.can_access_all_locations and EMWF.show_deactivated_data(self.value): return query_deactivated_data(query, self.domain) # otherwise only return explicit matches case_owners = get_case_owners(self.request, self.domain, self.value) return query.owner(case_owners)
def get_filtered_query(self, query): if self.request.can_access_all_locations and ( EMWF.show_all_data(self.value) or EMWF.no_filters_selected(self.value) ): return query if self.request.can_access_all_locations and EMWF.show_project_data(self.value): return query.filter(all_project_data_filter(self.domain, self.value)) if self.request.can_access_all_locations and EMWF.show_deactivated_data(self.value): return query.filter(deactivated_case_owners(self.domain)) selected_user_types = [v['id'] for v in self.value] case_owners = get_case_owners(self.request, self.domain, selected_user_types) return query.owner(case_owners)
def _build_query(self): query = (self.search_class() .domain(self.domain) .size(self.pagination.count) .start(self.pagination.start)) query.es_query['sort'] = self.get_sorting_block() mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) if self.case_filter: query = query.filter(self.case_filter) query = query.NOT(case_es.case_type("user-owner-mapping-case")) if self.case_type: query = query.case_type(self.case_type) if self.case_status: query = query.is_closed(self.case_status == 'closed') if self.request.can_access_all_locations and ( EMWF.show_all_data(mobile_user_and_group_slugs) or EMWF.no_filters_selected(mobile_user_and_group_slugs) ): pass elif (self.request.can_access_all_locations and EMWF.show_project_data(mobile_user_and_group_slugs)): query = query_all_project_data( query, self.domain, mobile_user_and_group_slugs ) elif (self.request.can_access_all_locations and EMWF.show_deactivated_data(mobile_user_and_group_slugs)): query = query_deactivated_data(query, self.domain) else: # Only show explicit matches query = query.owner(self.case_owners) if not self.request.can_access_all_locations: query = query_location_restricted_cases(query, self.request) search_string = CaseSearchFilter.get_value(self.request, self.domain) if search_string: query = query.set_query({"query_string": {"query": search_string}}) return query
def _build_query(self): query = (self.search_class() .domain(self.domain) .size(self.pagination.count) .start(self.pagination.start)) query.es_query['sort'] = self.get_sorting_block() mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) if self.case_filter: query = query.filter(self.case_filter) query = query.NOT(case_es.case_type("user-owner-mapping-case")) if self.case_type: query = query.case_type(self.case_type) if self.case_status: query = query.is_closed(self.case_status == 'closed') if self.request.can_access_all_locations and ( EMWF.show_all_data(mobile_user_and_group_slugs) or EMWF.no_filters_selected(mobile_user_and_group_slugs) ): pass elif (self.request.can_access_all_locations and EMWF.show_project_data(mobile_user_and_group_slugs)): query = query_all_project_data( query, self.domain, mobile_user_and_group_slugs ) elif (self.request.can_access_all_locations and EMWF.show_deactivated_data(mobile_user_and_group_slugs)): query = query_deactivated_data(query, self.domain) else: # Only show explicit matches query = query.owner(self.case_owners) if not self.request.can_access_all_locations: query = query_location_restricted_cases(query, self.request) search_string = CaseSearchFilter.get_value(self.request, self.domain) if search_string: query = query.set_query({"query_string": {"query": search_string}}) return query
def _to_case_export_instance_filters(self, can_access_all_locations, accessible_location_ids): emwf_selections = [x['id'] for x in self.cleaned_data["emwf_case_filter"]] return CaseExportInstanceFilters( date_period=DatePeriod( period_type=self.cleaned_data['date_range'], days=self.cleaned_data['days'], begin=self.cleaned_data['start_date'], end=self.cleaned_data['end_date'], ), users=CaseListFilter.selected_user_ids(emwf_selections), reporting_groups=CaseListFilter.selected_reporting_group_ids(emwf_selections), locations=CaseListFilter.selected_location_ids(emwf_selections), user_types=CaseListFilter.selected_user_types(emwf_selections), can_access_all_locations=can_access_all_locations, accessible_location_ids=accessible_location_ids, sharing_groups=CaseListFilter.selected_sharing_group_ids(emwf_selections), show_all_data=CaseListFilter.show_all_data(emwf_selections) or CaseListFilter.no_filters_selected(emwf_selections), show_project_data=CaseListFilter.show_project_data(emwf_selections), )