def handle(self, *args, **options): domain_names = args or [d["key"] for d in Domain.get_all(include_docs=False)] for d in domain_names: print "Migrating cases in project space: %s" % d key = ["all", d] results = get_db().view('case/all_cases', startkey=key, endkey=key + [{}], reduce=False, include_docs=False, ) for case_ids in chunked([r['id'] for r in results], 100): for case in wrapped_docs(CommCareCase, case_ids): if add_to_case(case): case.save()
def __iter__(self): for case_ids in chunked(self.all_case_ids, 500): for case in wrapped_docs(CommCareCase, case_ids): yield case
def stream_cases(all_case_ids): for case_ids in chunked(all_case_ids, 1000): for case in wrapped_docs(CommCareCase, keys=case_ids): # for case in CommCareCase.view('_all_docs', keys=case_ids, include_docs=True): yield case