示例#1
0
    def get_closed_and_deleted_ids(domain, case_ids):
        """Get the subset of given list of case ids that are closed or deleted

        WARNING this is inefficient (better version in SQL).
        """
        return [(case.case_id, case.closed, case.is_deleted)
            for case in iter_cases(case_ids)
            if case.domain == domain and (case.closed or case.is_deleted)]
示例#2
0
 def _populate_results(self, case_id_list):
     if should_use_sql_backend(self.domain):
         base_results = [CaseAPIResult(domain=self.domain, couch_doc=case, id_only=self.ids_only)
                         for case in self.case_accessors.iter_cases(case_id_list)]
     else:
         base_results = [CaseAPIResult(domain=self.domain, couch_doc=case, id_only=self.ids_only)
                         for case in iter_cases(case_id_list, self.strip_history, self.wrap)]
     return base_results
示例#3
0
    def get_closed_and_deleted_ids(domain, case_ids):
        """Get the subset of given list of case ids that are closed or deleted

        WARNING this is inefficient (better version in SQL).
        """
        return [(case.case_id, case.closed, case.is_deleted)
            for case in iter_cases(case_ids)
            if case.domain == domain and (case.closed or case.is_deleted)]
示例#4
0
 def _populate_results(self, case_id_list):
     if should_use_sql_backend(self.domain):
         base_results = [CaseAPIResult(domain=self.domain, couch_doc=case, id_only=self.ids_only)
                         for case in self.case_accessors.iter_cases(case_id_list)]
     else:
         base_results = [CaseAPIResult(domain=self.domain, couch_doc=case, id_only=self.ids_only)
                         for case in iter_cases(case_id_list, self.strip_history, self.wrap)]
     return base_results
示例#5
0
 def populate(self, case_ids):
     """
     Populates a set of IDs in the cache in bulk.
     Use this if you know you are going to need to access these later for performance gains.
     Does NOT overwrite what is already in the cache if there is already something there.
     """
     case_ids = set(case_ids) - set(self.cache.keys())
     for case in iter_cases(case_ids, self.strip_history, self.wrap):
         self.set(case['_id'], case)
示例#6
0
 def populate(self, case_ids):
     """
     Populates a set of IDs in the cache in bulk.
     Use this if you know you are going to need to access these later for performance gains.
     Does NOT overwrite what is already in the cache if there is already something there.
     """
     case_ids = set(case_ids) - set(self.cache.keys())
     for case in iter_cases(case_ids, self.strip_history, self.wrap):
         self.set(case['_id'], case)
示例#7
0
    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 iter_cases(
                                  case_id_list, self.strip_history, self.wrap)
            ]

        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)

        if not self.footprint:
            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()

        return [
            CaseAPIResult(couch_doc=case, id_only=self.ids_only)
            for case in case_list
        ]
示例#8
0
文件: api.py 项目: jmaina/commcare-hq
    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 or self.include_children:
            # 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 iter_cases(case_id_list, self.strip_history, self.wrap)]

        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)

        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]
示例#9
0
 def _iter_cases(self, case_ids):
     for case in iter_cases(case_ids, self.strip_history, self.wrap):
         yield case
示例#10
0
 def _iter_cases(self, case_ids):
     for case in iter_cases(case_ids, self.strip_history, self.wrap):
         yield case
示例#11
0
 def _iter_cases(self, case_ids):
     for case in iter_cases(case_ids, self.wrap):
         yield case
示例#12
0
 def _iter_cases(self, case_ids):
     for case in iter_cases(case_ids, self.wrap):
         yield case