def assign_case(case_or_case_id, owner_id, acting_user=None, include_subcases=True, include_parent_cases=False, exclude_function=None, update=None): """ Assigns a case to an owner. Optionally traverses through subcases and parent cases and reassigns those to the same owner. """ if isinstance(case_or_case_id, basestring): primary_case = CommCareCase.get(case_or_case_id) else: primary_case = case_or_case_id cases_to_assign = [primary_case] if include_subcases: cases_to_assign.extend( get_related_cases([primary_case], primary_case.domain, search_up=False).values()) if include_parent_cases: cases_to_assign.extend( get_related_cases([primary_case], primary_case.domain, search_up=True).values()) if exclude_function: cases_to_assign = [ c for c in cases_to_assign if not exclude_function(c) ] return assign_cases(cases_to_assign, owner_id, acting_user, update=update)
def assign_case( case_or_case_id, owner_id, acting_user=None, include_subcases=True, include_parent_cases=False, exclude_function=None, update=None, ): """ Assigns a case to an owner. Optionally traverses through subcases and parent cases and reassigns those to the same owner. """ if isinstance(case_or_case_id, basestring): primary_case = CommCareCase.get(case_or_case_id) else: primary_case = case_or_case_id cases_to_assign = [primary_case] if include_subcases: cases_to_assign.extend(get_related_cases([primary_case], primary_case.domain, search_up=False).values()) if include_parent_cases: cases_to_assign.extend(get_related_cases([primary_case], primary_case.domain, search_up=True).values()) if exclude_function: cases_to_assign = [c for c in cases_to_assign if not exclude_function(c)] return assign_cases(cases_to_assign, owner_id, acting_user, update=update)
def assign_case(case_or_case_id, owner_id, acting_user=None, include_subcases=True, include_parent_cases=False, exclude=()): """ Assigns a case to an owner. Optionally traverses through subcases and parent cases and reassigns those to the same owner. """ if isinstance(case_or_case_id, basestring): primary_case = CommCareCase.get(case_or_case_id) else: primary_case = case_or_case_id cases_to_assign = [primary_case] if include_subcases: cases_to_assign.extend(get_related_cases([primary_case], primary_case.domain, search_up=False).values()) if include_parent_cases: cases_to_assign.extend(get_related_cases([primary_case], primary_case.domain, search_up=True).values()) if exclude: cases_to_assign = filter(lambda case: case._id not in exclude, cases_to_assign) return assign_cases(cases_to_assign, owner_id, acting_user)
def _case_results(self, case_id_list): def _filter(res): if self.filters: for path, val in self.filters.items(): actual_val = safe_index(res.case_json, path.split("/")) if actual_val != val: # closed=false => case.closed == False if val in ('null', 'true', 'false'): if actual_val != json.loads(val): return False else: return False return True if not self.ids_only or self.filters or self.footprint: # optimization hack - we know we'll need the full cases eventually # so just grab them now. base_results = [CaseAPIResult(couch_doc=case, id_only=self.ids_only) \ for case in self.iter_cases(case_id_list)] else: base_results = [ CaseAPIResult(id=id, id_only=True) for id in case_id_list ] if self.filters and not self.footprint: base_results = filter(_filter, base_results) link_locations(base_results) if not self.footprint and not self.include_children: return base_results case_list = [res.couch_doc for res in base_results] if self.footprint: case_list = get_footprint( case_list, self.domain, strip_history=self.strip_history, ).values() if self.include_children: case_list = get_related_cases( case_list, self.domain, strip_history=self.strip_history, search_up=False, ).values() return [ CaseAPIResult(couch_doc=case, id_only=self.ids_only) for case in case_list ]
def _case_results(self, case_id_list): def _filter(res): if self.filters: for path, val in self.filters.items(): actual_val = safe_index(res.case_json, path.split("/")) if actual_val != val: # closed=false => case.closed == False if val in ('null', 'true', 'false'): if actual_val != json.loads(val): return False else: return False return True if not self.ids_only or self.filters or self.footprint: # optimization hack - we know we'll need the full cases eventually # so just grab them now. base_results = [CaseAPIResult(couch_doc=case, id_only=self.ids_only) \ for case in self.iter_cases(case_id_list)] else: base_results = [CaseAPIResult(id=id, id_only=True) for id in case_id_list] if self.filters and not self.footprint: base_results = filter(_filter, base_results) link_locations(base_results) if not self.footprint and not self.include_children: return base_results case_list = [res.couch_doc for res in base_results] if self.footprint: case_list = get_footprint( case_list, self.domain, strip_history=self.strip_history, ).values() if self.include_children: case_list = get_related_cases( case_list, self.domain, strip_history=self.strip_history, search_up=False, ).values() return [CaseAPIResult(couch_doc=case, id_only=self.ids_only) for case in case_list]