当前位置: 首页>>代码示例>>Python>>正文


Python CaseAccessors.get_case方法代码示例

本文整理汇总了Python中corehq.form_processor.interfaces.dbaccessors.CaseAccessors.get_case方法的典型用法代码示例。如果您正苦于以下问题:Python CaseAccessors.get_case方法的具体用法?Python CaseAccessors.get_case怎么用?Python CaseAccessors.get_case使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.form_processor.interfaces.dbaccessors.CaseAccessors的用法示例。


在下文中一共展示了CaseAccessors.get_case方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_edit_submissions_simple

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
    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:])
开发者ID:,项目名称:,代码行数:36,代码来源:

示例2: test_archiving_only_form

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
    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)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:32,代码来源:test_rebuild.py

示例3: lookup_case

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
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)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:32,代码来源:util.py

示例4: get_case_by_identifier

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
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
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:36,代码来源:utils.py

示例5: get_parent_of_case

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
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]
开发者ID:,项目名称:,代码行数:30,代码来源:

示例6: parent_cases

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
 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
     }
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:models.py

示例7: test_archived_form_gets_removed_from_case_xform_ids

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
    def test_archived_form_gets_removed_from_case_xform_ids(self):
        initial_amounts = [(p._id, float(100)) for p in self.products]
        instance_id = self.submit_xml_form(
            balance_submission(initial_amounts),
            timestamp=datetime.utcnow() + timedelta(-30)
        )

        case_accessors = CaseAccessors(self.domain.name)
        case = case_accessors.get_case(self.sp.case_id)
        self.assertIn(instance_id, case.xform_ids)

        form = FormAccessors(self.domain.name).get_form(instance_id)
        form.archive()

        case = case_accessors.get_case(self.sp.case_id)
        self.assertNotIn(instance_id, case.xform_ids)
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:18,代码来源:test_xml.py

示例8: _update_case

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
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)
开发者ID:,项目名称:,代码行数:9,代码来源:

示例9: Command

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
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)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:28,代码来源:phone_number_data_2.py

示例10: child_cases

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
 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
     }
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:models.py

示例11: ReadonlyCaseDocumentStore

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
class ReadonlyCaseDocumentStore(ReadOnlyDocumentStore):

    def __init__(self, domain):
        self.domain = domain
        self.case_accessors = CaseAccessors(domain=domain)

    def get_document(self, doc_id):
        return self.case_accessors.get_case(doc_id).to_json()
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:10,代码来源:document_stores.py

示例12: get_cases

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
def get_cases(request, domain):
    request_params = request.GET

    if request.couch_user.is_commcare_user():
        user_id = request.couch_user.get_id
    else:
        user_id = request_params.get("user_id", "")

    if not user_id and not request.couch_user.is_web_user():
        return HttpResponseBadRequest("Must specify user_id!")

    ids_only = string_to_boolean(request_params.get("ids_only", "false"))
    case_id = request_params.get("case_id", "")
    footprint = string_to_boolean(request_params.get("footprint", "false"))
    accessor = CaseAccessors(domain)

    if toggles.HSPH_HACK.enabled(domain):
        hsph_case_id = request_params.get('hsph_hack', None)
        if hsph_case_id != 'None' and hsph_case_id and user_id:
            case = accessor.get_case(hsph_case_id)
            usercase_id = CommCareUser.get_by_user_id(user_id).get_usercase_id()
            usercase = accessor.get_case(usercase_id) if usercase_id else None
            return json_response(map(
                lambda case: CaseAPIResult(domain=domain, id=case['_id'], couch_doc=case, id_only=ids_only),
                filter(None, [case, case.parent, usercase])
            ))

    if case_id and not footprint:
        # short circuit everything else and just return the case
        # NOTE: this allows any user in the domain to access any case given
        # they know its ID, which is slightly different from the previous
        # behavior (can only access things you own + footprint). If we want to
        # change this contract we would need to update this to check the
        # owned case list + footprint
        case = accessor.get_case(case_id)
        assert case.domain == domain
        cases = [CaseAPIResult(domain=domain, id=case_id, couch_doc=case, id_only=ids_only)]
    else:
        filters = get_filters_from_request_params(request_params)
        status = api_closed_to_status(request_params.get('closed', 'false'))
        case_type = filters.get('properties/case_type', None)
        cases = get_filtered_cases(domain, status=status, case_type=case_type,
                                   user_id=user_id, filters=filters,
                                   footprint=footprint, ids_only=ids_only,
                                   strip_history=True)
    return json_response(cases)
开发者ID:,项目名称:,代码行数:48,代码来源:

示例13: TestHardDelete

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
class TestHardDelete(TestCase):

    def setUp(self):
        self.casedb = CaseAccessors(TEST_DOMAIN_NAME)
        self.formdb = FormAccessors(TEST_DOMAIN_NAME)

    @run_with_all_backends
    def test_simple_delete(self):
        factory = CaseFactory()
        case = factory.create_case()
        [case] = factory.create_or_update_case(
            CaseStructure(case_id=case.case_id, attrs={'update': {'foo': 'bar'}})
        )
        self.assertIsNotNone(self.casedb.get_case(case.case_id))
        self.assertEqual(2, len(case.xform_ids))
        for form_id in case.xform_ids:
            self.assertIsNotNone(self.formdb.get_form(form_id))
        safe_hard_delete(case)

        with self.assertRaises(CaseNotFound):
            self.casedb.get_case(case.case_id)

        for form_id in case.xform_ids:
            with self.assertRaises(XFormNotFound):
                self.formdb.get_form(form_id)

    @run_with_all_backends
    def test_delete_with_related(self):
        factory = CaseFactory()
        parent = factory.create_case()
        [child] = factory.create_or_update_case(
            CaseStructure(attrs={'create': True}, walk_related=False, indices=[
                CaseIndex(CaseStructure(case_id=parent.case_id))
            ]),
        )
        # deleting the parent should not be allowed because the child still references it
        with self.assertRaises(CommCareCaseError):
            safe_hard_delete(parent)

        # deleting the child is ok
        safe_hard_delete(child)
        self.assertIsNotNone(self.casedb.get_case(parent.case_id))
        with self.assertRaises(CaseNotFound):
            self.casedb.get_case(child.case_id)

    @run_with_all_backends
    def test_delete_sharing_form(self):
        factory = CaseFactory()
        c1, c2 = factory.create_or_update_cases([
            CaseStructure(attrs={'create': True}),
            CaseStructure(attrs={'create': True}),
        ])
        with self.assertRaises(CommCareCaseError):
            safe_hard_delete(c1)

        with self.assertRaises(CommCareCaseError):
            safe_hard_delete(c2)

        self.assertIsNotNone(self.casedb.get_case(c1.case_id))
        self.assertIsNotNone(self.casedb.get_case(c2.case_id))
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:62,代码来源:test_delete.py

示例14: test_soft_delete

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
    def test_soft_delete(self):
        _submit_case_block(True, 'c1', domain=DOMAIN)
        _submit_case_block(True, 'c2', domain=DOMAIN)
        _submit_case_block(True, 'c3', domain=DOMAIN)

        accessors = CaseAccessors(DOMAIN)

        # delete
        num = accessors.soft_delete_cases(['c1', 'c2'], deletion_id='123')
        self.assertEqual(num, 2)

        for case_id in ['c1', 'c2']:
            case = accessors.get_case(case_id)
            self.assertTrue(case.is_deleted)
            self.assertEqual(case.deletion_id, '123')

        case = accessors.get_case('c3')
        self.assertFalse(case.is_deleted)
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:20,代码来源:test_case_dbaccessor.py

示例15: test_archive_against_deleted_case

# 需要导入模块: from corehq.form_processor.interfaces.dbaccessors import CaseAccessors [as 别名]
# 或者: from corehq.form_processor.interfaces.dbaccessors.CaseAccessors import get_case [as 别名]
    def test_archive_against_deleted_case(self):
        now = datetime.utcnow()
        # make sure we timestamp everything so they have the right order
        case_id = _post_util(create=True, p1='p1', form_extras={'received_on': now})
        _post_util(case_id=case_id, p2='p2',
                  form_extras={'received_on': now + timedelta(seconds=1)})
        _post_util(case_id=case_id, p3='p3',
                  form_extras={'received_on': now + timedelta(seconds=2)})

        case_accessors = CaseAccessors(REBUILD_TEST_DOMAIN)
        case = case_accessors.get_case(case_id)
        case_accessors.soft_delete_cases([case_id])

        [f1, f2, f3] = case.xform_ids
        f2_doc = FormAccessors(REBUILD_TEST_DOMAIN).get_form(f2)
        f2_doc.archive()
        case = case_accessors.get_case(case_id)
        self.assertTrue(case.is_deleted)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:20,代码来源:test_rebuild.py


注:本文中的corehq.form_processor.interfaces.dbaccessors.CaseAccessors.get_case方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。