def test_get_open_case_ids_in_domain__owner_id(self): # this is actually in the 'case' app, but testing here self.assertEqual( set(get_open_case_ids_in_domain(self.domain, 'type1', owner_id='XXX')), {case.get_id for case in self.cases if case.domain == self.domain and case.type == 'type1' and not case.closed and case.user_id == 'XXX'}, ) self.assertEqual( set(get_open_case_ids_in_domain(self.domain, owner_id='XXX')), {case.get_id for case in self.cases if case.domain == self.domain and not case.closed and case.user_id == 'XXX'}, )
def get_open_case_ids_in_domain_by_type(domain, case_type, owner_ids=None): owner_ids = owner_ids if owner_ids else [None] return [ case_id for owner_id in owner_ids for case_id in get_open_case_ids_in_domain(domain, type=case_type, owner_id=owner_id) ]
def get_all(self): status = self.status or CASE_STATUS_ALL if status == CASE_STATUS_ALL: case_ids = get_case_ids_in_domain(self.domain, type=self.case_type) elif status == CASE_STATUS_OPEN: case_ids = get_open_case_ids_in_domain(self.domain, type=self.case_type) elif status == CASE_STATUS_CLOSED: _assert = soft_assert('@'.join(['droberts', 'dimagi.com'])) _assert(False, "I'm surprised CaseAPIHelper " "ever gets called with status=closed") # this is rare so we don't care if it requires two calls to get # all the ids case_ids = ( set(get_case_ids_in_domain(self.domain, type=self.case_type)) - set(get_open_case_ids_in_domain(self.domain, type=self.case_type)) ) else: raise ValueError("Invalid value for 'status': '%s'" % status) return self._case_results(case_ids)
def get_all(self): status = self.status or CASE_STATUS_ALL if status == CASE_STATUS_ALL: case_ids = get_case_ids_in_domain(self.domain, type=self.case_type) elif status == CASE_STATUS_OPEN: case_ids = get_open_case_ids_in_domain(self.domain, type=self.case_type) else: raise ValueError("Invalid value for 'status': '%s'" % status) return self._case_results(case_ids)
def get_all(self): status = self.status or CASE_STATUS_ALL if status == CASE_STATUS_ALL: case_ids = get_case_ids_in_domain(self.domain, type=self.case_type) elif status == CASE_STATUS_OPEN: case_ids = get_open_case_ids_in_domain(self.domain, type=self.case_type) elif status == CASE_STATUS_CLOSED: _assert = soft_assert('@'.join(['droberts', 'dimagi.com'])) _assert( False, "I'm surprised CaseAPIHelper " "ever gets called with status=closed") # this is rare so we don't care if it requires two calls to get # all the ids case_ids = ( set(get_case_ids_in_domain(self.domain, type=self.case_type)) - set( get_open_case_ids_in_domain(self.domain, type=self.case_type))) else: raise ValueError("Invalid value for 'status': '%s'" % status) return self._case_results(case_ids)
def obj_get_list(self, bundle, **kwargs): domain = kwargs['domain'] include_closed = { 'true': True, 'false': False, 'any': True }[bundle.request.GET.get('closed', 'false')] case_type = bundle.request.GET.get('case_type') key = [domain] if case_type: key.append(case_type) if include_closed: case_ids = get_case_ids_in_domain(domain, type=case_type) else: case_ids = get_open_case_ids_in_domain(domain, type=case_type) cases = imap(CommCareCase.wrap, iter_docs(CommCareCase.get_db(), case_ids)) return list(cases)