本文整理汇总了Python中corehq.form_processor.interfaces.dbaccessors.CaseAccessors类的典型用法代码示例。如果您正苦于以下问题:Python CaseAccessors类的具体用法?Python CaseAccessors怎么用?Python CaseAccessors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CaseAccessors类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_xform_ids_diff
def test_xform_ids_diff(self):
case_id = uuid.uuid4().hex
submit_case_blocks(
CaseBlock(
case_id,
case_type='migrate',
create=True,
update={'p1': 1},
).as_string(),
self.domain_name
)
submit_case_blocks(
CaseBlock(
case_id,
update={'p2': 2},
).as_string(),
self.domain_name
)
case = CaseAccessors(self.domain_name).get_case(case_id)
removed_form_id = case.xform_ids.pop(1)
case.save()
self.assertEqual(1, len(self._get_case_ids()))
self._do_migration_and_assert_flags(self.domain_name)
self.assertEqual(1, len(self._get_case_ids()))
self._compare_diffs([
(u'CommCareCase', FormJsonDiff(
diff_type=u'set_mismatch', path=[u'xform_ids', u'[*]'],
old_value=u'', new_value=removed_form_id
))
])
示例2: recalculate_stagnant_cases
def recalculate_stagnant_cases():
domain = 'icds-cas'
config_ids = [
'static-icds-cas-static-ccs_record_cases_monthly_v2',
'static-icds-cas-static-ccs_record_cases_monthly_tableau_v2',
'static-icds-cas-static-child_cases_monthly_v2',
]
stagnant_cases = set()
for config_id in config_ids:
config, is_static = get_datasource_config(config_id, domain)
adapter = get_indicator_adapter(config)
case_ids = _find_stagnant_cases(adapter)
celery_task_logger.info(
"Found {} stagnant cases in config {}".format(len(case_ids), config_id)
)
stagnant_cases = stagnant_cases.union(set(case_ids))
celery_task_logger.info(
"Total number of stagant cases is now {}".format(len(stagnant_cases))
)
case_accessor = CaseAccessors(domain)
num_stagnant_cases = len(stagnant_cases)
current_case_num = 0
for case_ids in chunked(stagnant_cases, 1000):
current_case_num += len(case_ids)
cases = case_accessor.get_cases(list(case_ids))
for case in cases:
publish_case_saved(case, send_post_save_signal=False)
celery_task_logger.info(
"Resaved {} / {} cases".format(current_case_num, num_stagnant_cases)
)
示例3: _delete_all_cases
def _delete_all_cases(domain_name):
logger.info('Deleting cases...')
case_accessor = CaseAccessors(domain_name)
case_ids = case_accessor.get_case_ids_in_domain()
for case_id_chunk in chunked(with_progress_bar(case_ids, stream=silence_during_tests()), 500):
case_accessor.soft_delete_cases(list(case_id_chunk))
logger.info('Deleting cases complete.')
示例4: Command
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('infile')
parser.add_argument('outfile')
def handle(self, infile, outfile, *args, **options):
self.case_accessor = CaseAccessors('icds-cas')
with open(infile, 'r', encoding='utf-8') as old, open(outfile, 'w', encoding='utf-8') as new:
reader = csv.reader(old)
writer = csv.writer(new)
headers = next(reader)
writer.writerow(headers)
for row in reader:
case_id = row[4]
hh_id = row[10]
if hh_id:
person, hh = self.case_accessor.get_cases([case_id, hh_id], ordered=True)
else:
person = self.case_accessor.get_case(case_id)
hh = None
if hh:
row[18] = hh.get_case_property('name')
row[19] = hh.get_case_property('hh_num')
row[20] = person.get_case_property('name')
writer.writerow(row)
示例5: get_case_by_identifier
def get_case_by_identifier(domain, identifier):
# circular import
from corehq.apps.api.es import CaseES
case_es = CaseES(domain)
case_accessors = CaseAccessors(domain)
def _query_by_type(i_type):
q = case_es.base_query(
terms={
i_type: identifier,
},
fields=['_id', i_type],
size=1
)
response = case_es.run_query(q)
raw_docs = response['hits']['hits']
if raw_docs:
return case_accessors.get_case(raw_docs[0]['_id'])
# Try by any of the allowed identifiers
for identifier_type in ALLOWED_CASE_IDENTIFIER_TYPES:
case = _query_by_type(identifier_type)
if case is not None:
return case
# Try by case id
try:
case_by_id = case_accessors.get_case(identifier)
if case_by_id.domain == domain:
return case_by_id
except (CaseNotFound, KeyError):
pass
return None
示例6: _update_case
def _update_case(domain, case_id, server_modified_on, last_visit_date=None):
accessors = CaseAccessors(domain)
case = accessors.get_case(case_id)
case.server_modified_on = server_modified_on
if last_visit_date:
set_case_property_directly(case, 'last_visit_date', last_visit_date.strftime('%Y-%m-%d'))
_save_case(domain, case)
示例7: case_types
def case_types(self):
"""
:return: Set of all case types for the domain excluding the CallCenter case type.
"""
case_types = CaseAccessors(self.domain).get_case_types()
case_types.remove(self.cc_case_type)
return case_types
示例8: get_parent_of_case
def get_parent_of_case(domain, case_id, parent_case_type):
case_accessor = CaseAccessors(domain)
try:
if not isinstance(case_id, basestring):
case_id = case_id.case_id
child_case = case_accessor.get_case(case_id)
except CaseNotFound:
raise ENikshayCaseNotFound(
"Couldn't find case: {}".format(case_id)
)
parent_case_ids = [
indexed_case.referenced_id for indexed_case in child_case.indices
if indexed_case.referenced_type == parent_case_type
]
parent_cases = case_accessor.get_cases(parent_case_ids)
open_parent_cases = [
occurrence_case for occurrence_case in parent_cases
if not occurrence_case.closed
]
if not open_parent_cases:
raise ENikshayCaseNotFound(
"Couldn't find any open {} cases for id: {}".format(parent_case_type, case_id)
)
return open_parent_cases[0]
示例9: test_edit_submissions_simple
def test_edit_submissions_simple(self):
initial_quantity = 100
form = submit_case_blocks(
case_blocks=get_single_balance_block(quantity=initial_quantity, **self._stock_state_key),
domain=self.domain,
)[0]
self._assert_stats(1, initial_quantity, initial_quantity)
case_accessors = CaseAccessors(self.domain)
case = case_accessors.get_case(self.case.case_id)
try:
self.assertTrue(any([action.is_ledger_transaction for action in case.actions]))
except AttributeError:
self.assertTrue('commtrack' in [action.action_type for action in case.actions])
self.assertEqual([form.form_id], case.xform_ids[1:])
# change the value to 50
edit_quantity = 50
submit_case_blocks(
case_blocks=get_single_balance_block(quantity=edit_quantity, **self._stock_state_key),
domain=self.domain,
form_id=form.form_id,
)
case = case_accessors.get_case(self.case.case_id)
try:
# CaseTransaction
self.assertTrue(any([action.is_ledger_transaction for action in case.actions]))
except AttributeError:
# CaseAction
self.assertTrue('commtrack' in [action.action_type for action in case.actions])
self._assert_stats(1, edit_quantity, edit_quantity)
self.assertEqual([form.form_id], case.xform_ids[1:])
示例10: test_archiving_only_form
def test_archiving_only_form(self):
"""
Checks that archiving the only form associated with the case archives
the case and unarchiving unarchives it.
"""
case_id = _post_util(create=True, p1='p1-1', p2='p2-1')
case_accessors = CaseAccessors(REBUILD_TEST_DOMAIN)
case = case_accessors.get_case(case_id)
self.assertFalse(case.is_deleted)
if should_use_sql_backend(REBUILD_TEST_DOMAIN):
self.assertEqual(1, len(case.actions))
else:
self.assertEqual(2, len(case.actions))
[form_id] = case.xform_ids
form = FormAccessors(REBUILD_TEST_DOMAIN).get_form(form_id)
form.archive()
case = case_accessors.get_case(case_id)
self.assertTrue(case.is_deleted)
# should just have the 'rebuild' action
self.assertEqual(1, len(case.actions))
self.assertTrue(case.actions[0].is_case_rebuild)
form.unarchive()
case = case_accessors.get_case(case_id)
self.assertFalse(case.is_deleted)
self.assertEqual(3, len(case.actions))
self.assertTrue(case.actions[-1].is_case_rebuild)
示例11: parent_cases
def parent_cases(self):
from corehq.apps.api.util import case_to_es_case
accessor = CaseAccessors(self.domain)
return {
index['identifier']: case_to_es_case(accessor.get_case(index['referenced_id']))
for index in self.indices
}
示例12: test_update_adherence_confidence
def test_update_adherence_confidence(self):
self.create_case_structure()
case_accessor = CaseAccessors(self.domain)
adherence_dates = [
datetime(2005, 7, 10),
datetime(2016, 8, 10),
datetime(2016, 8, 11),
]
adherence_cases = self.create_adherence_cases(adherence_dates)
update_adherence_confidence_level(
self.domain,
self.person_id,
datetime(2016, 8, 10, tzinfo=pytz.UTC),
datetime(2016, 8, 11, tzinfo=pytz.UTC),
"new_confidence_level",
)
adherence_case_ids = [adherence_date.strftime("%Y-%m-%d") for adherence_date in adherence_dates]
adherence_cases = {case.case_id: case for case in case_accessor.get_cases(adherence_case_ids)}
self.assertEqual(
adherence_cases[adherence_case_ids[0]].dynamic_case_properties()['adherence_confidence'],
'medium',
)
self.assertEqual(
adherence_cases[adherence_case_ids[1]].dynamic_case_properties()['adherence_confidence'],
'new_confidence_level',
)
self.assertEqual(
adherence_cases[adherence_case_ids[2]].dynamic_case_properties()['adherence_confidence'],
'new_confidence_level',
)
示例13: child_cases
def child_cases(self):
from corehq.apps.api.util import case_to_es_case
accessor = CaseAccessors(self.domain)
return {
index.case_id: case_to_es_case(accessor.get_case(index.case_id))
for index in self._reverse_indices
}
示例14: lookup_case
def lookup_case(search_field, search_id, domain, case_type):
"""
Attempt to find the case in CouchDB by the provided search_field and search_id.
Returns a tuple with case (if found) and an
error code (if there was an error in lookup).
"""
found = False
case_accessors = CaseAccessors(domain)
if search_field == 'case_id':
try:
case = case_accessors.get_case(search_id)
if case.domain == domain and case.type == case_type:
found = True
except CaseNotFound:
pass
elif search_field == EXTERNAL_ID:
cases_by_type = case_accessors.get_cases_by_external_id(search_id, case_type=case_type)
if not cases_by_type:
return (None, LookupErrors.NotFound)
elif len(cases_by_type) > 1:
return (None, LookupErrors.MultipleResults)
else:
case = cases_by_type[0]
found = True
if found:
return (case, None)
else:
return (None, LookupErrors.NotFound)
示例15: _get_direct_dependencies
def _get_direct_dependencies(domain, cases):
case_accessor = CaseAccessors(domain)
extension_cases = set(case_accessor.get_extension_case_ids(cases))
indexed_cases = set(case_accessor.get_indexed_case_ids(cases))
return DirectDependencies(
all=extension_cases | indexed_cases, indexed_cases=indexed_cases, extension_cases=extension_cases
)