本文整理汇总了Python中casexml.apps.case.models.CommCareCase.bulk_get_lite方法的典型用法代码示例。如果您正苦于以下问题:Python CommCareCase.bulk_get_lite方法的具体用法?Python CommCareCase.bulk_get_lite怎么用?Python CommCareCase.bulk_get_lite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.case.models.CommCareCase
的用法示例。
在下文中一共展示了CommCareCase.bulk_get_lite方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: case_block_ok
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import bulk_get_lite [as 别名]
def case_block_ok(case_updates):
case_ids = set()
for case_update in case_updates:
case_ids.add(case_update.id)
create_action = case_update.get_create_action()
update_action = case_update.get_update_action()
index_action = case_update.get_index_action()
if create_action:
if create_action.user_id not in ('demo_user', None):
return False
if create_action.owner_id not in ('demo_user', None):
return False
if update_action:
if update_action.owner_id not in ('demo_user', None):
return False
if index_action:
for index in index_action.indices:
case_ids.add(index.referenced_id)
cases = CommCareCase.bulk_get_lite(list(case_ids))
for case in cases:
if case.domain != domain:
return False
if case.owner_id or case.user_id != 'demo_user':
return False
return True
示例2: case_block_ok
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import bulk_get_lite [as 别名]
def case_block_ok(case_updates):
"""
Check for all cases that we are submitting as demo_user and that the domain we
are submitting against for any previously existing cases matches the submission
domain.
"""
allowed_ids = ('demo_user', 'demo_user_group_id', None)
case_ids = set()
for case_update in case_updates:
case_ids.add(case_update.id)
create_action = case_update.get_create_action()
update_action = case_update.get_update_action()
index_action = case_update.get_index_action()
if create_action:
if create_action.user_id not in allowed_ids:
return False
if create_action.owner_id not in allowed_ids:
return False
if update_action:
if update_action.owner_id not in allowed_ids:
return False
if index_action:
for index in index_action.indices:
case_ids.add(index.referenced_id)
# todo: consider whether we want to remove this call, and/or pass the result
# through to the next function so we don't have to get the cases again later
cases = CommCareCase.bulk_get_lite(list(case_ids))
for case in cases:
if case.domain != domain:
return False
if case.owner_id or case.user_id not in allowed_ids:
return False
return True
示例3: case_updates_to_sync
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import bulk_get_lite [as 别名]
def case_updates_to_sync(self):
other_case_ids_on_phone = set([
case_id
for case_id in self.last_sync.get_footprint_of_cases_on_phone()
if case_id not in self.global_state.actual_relevant_cases_dict
])
logger.debug("%s other cases on phone", len(other_case_ids_on_phone))
if not other_case_ids_on_phone:
return []
if self.use_minimal_cases:
other_cases_on_phone = [
self.global_state.minimal_cases[case_id] for case_id in other_case_ids_on_phone
]
else:
other_cases_on_phone = CommCareCase.bulk_get_lite(
other_case_ids_on_phone,
wrap=False,
chunksize=len(other_case_ids_on_phone)
)
potential_to_sync = self._get_potential_cases(other_cases_on_phone)
cases_to_sync = self._fetch_missing_cases_and_wrap(potential_to_sync)
case_sync_updates = self._case_sync_updates(cases_to_sync)
self.global_state.update_synced_cases(case_sync_updates)
return case_sync_updates
示例4: iter_cases
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import bulk_get_lite [as 别名]
def iter_cases(case_ids, strip_history=False, wrap=True):
from casexml.apps.case.models import CommCareCase
if not strip_history:
for doc in iter_docs(CommCareCase.get_db(), case_ids):
yield CommCareCase.wrap(doc) if wrap else doc
else:
for case in CommCareCase.bulk_get_lite(case_ids, wrap=wrap):
yield case
示例5: iter_cases
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import bulk_get_lite [as 别名]
def iter_cases(self, ids):
database = CommCareCase.get_db()
if not self.strip_history:
for doc in iter_docs(database, ids):
yield CommCareCase.wrap(doc)
else:
for doc_ids in chunked(ids, 100):
for case in CommCareCase.bulk_get_lite(doc_ids):
yield case
示例6: _fetch_missing_cases_and_wrap
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import bulk_get_lite [as 别名]
def _fetch_missing_cases_and_wrap(self, casedoc_list):
cases = []
to_fetch = []
for doc in casedoc_list:
if doc['doc_type'] == 'CommCareCase':
cases.append(CommCareCase.wrap(doc))
else:
to_fetch.append(doc['_id'])
cases.extend(CommCareCase.bulk_get_lite(to_fetch, wrap=True, chunksize=self.chunksize))
return cases
示例7: _actual_owned_cases
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import bulk_get_lite [as 别名]
def _actual_owned_cases(self):
"""
This returns a list of case dicts. Each dict will either be an actual case dict or else
a dict containing only these keys: '_id', 'type', 'indices'. These 'minimal cases' are
created from CaseState objects from the previous SyncLog.
"""
def _case_domain_match(case):
return not self.domain or self.domain == case.get('domain')
case_ids = self._get_case_ids()
if self.use_minimal_cases:
# First we check to see if there is a case state available that we can use
# rather than fetching the whole case.
minimal_cases = []
cases_to_fetch = []
for case_id in case_ids:
minimal_case = self.global_state.minimal_cases.get(case_id)
if minimal_case:
minimal_cases.append(minimal_case)
else:
cases_to_fetch.append(case_id)
logger.debug(
"%s cases found in previous SyncLog. %s still to fetch",
len(minimal_cases), len(cases_to_fetch)
)
if cases_to_fetch:
cases = CommCareCase.bulk_get_lite(cases_to_fetch, wrap=False, chunksize=self.chunksize)
minimal_cases.extend(
case_doc for case_doc in cases
if _case_domain_match(case_doc)
)
return minimal_cases
else:
lite_cases = list(iter_lite_cases_json(case_ids, self.chunksize))
logger.debug("No previous SyncLog. Fetched %s cases", len(lite_cases))
return lite_cases