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


Python CommCareCase.get_db方法代码示例

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


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

示例1: test_rebuild_indicators

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
 def test_rebuild_indicators(self, datetime_mock):
     datetime_mock.utcnow.return_value = self.fake_time_now
     self.config.save()
     sample_doc, _ = get_sample_doc_and_indicators(self.fake_time_now)
     CommCareCase.get_db().save_doc(sample_doc)
     rebuild_indicators(self.config._id)
     self._check_sample_doc_state()
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:9,代码来源:test_pillow.py

示例2: test_rebuild_indicators

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
 def test_rebuild_indicators(self, datetime_mock):
     datetime_mock.utcnow.return_value = self.fake_time_now
     sample_doc, expected_indicators = get_sample_doc_and_indicators(self.fake_time_now)
     CommCareCase.get_db().save_doc(sample_doc)
     self.addCleanup(lambda id: CommCareCase.get_db().delete_doc(id), sample_doc['_id'])
     rebuild_indicators(self.config._id)
     self._check_sample_doc_state(expected_indicators)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:9,代码来源:test_pillow.py

示例3: process_form_unarchived

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
 def process_form_unarchived(self, form):
     from corehq.apps.commtrack.processing import process_stock
     from casexml.apps.case.models import CommCareCase
     result = process_stock([form])
     result.populate_models()
     result.commit()
     result.finalize()
     CommCareCase.get_db().bulk_save(result.relevant_cases)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:10,代码来源:ledger.py

示例4: _iter_raw_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
 def _iter_raw_cases(case_ids):
     if self.strip_history:
         for ids in chunked(case_ids, 100):
             for row in CommCareCase.get_db().view("case/get_lite", keys=ids, include_docs=False):
                 yield row["value"]
     else:
         for raw_case in iter_docs(CommCareCase.get_db(), case_ids):
             yield raw_case
开发者ID:kkaczmarczyk,项目名称:commcare-hq,代码行数:10,代码来源:xform.py

示例5: resave_case

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
def resave_case(domain, case, send_post_save_signal=True):
    from corehq.form_processor.change_publishers import publish_case_saved
    if should_use_sql_backend(domain):
        publish_case_saved(case, send_post_save_signal)
    else:
        if send_post_save_signal:
            case.save()
        else:
            CommCareCase.get_db().save_doc(case._doc)  # don't just call save to avoid signals
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:11,代码来源:utils.py

示例6: get_cases

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
def get_cases(domain):
    supply_point_ids = (case['id'] for case in CommCareCase.get_db().view(
        'supply_point_by_loc/view',
        startkey=[domain],
        endkey=[domain, {}],
        reduce=False,
        include_docs=False,
    ).all())
    return iter_docs(CommCareCase.get_db(), supply_point_ids)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:11,代码来源:update_supply_point_locations.py

示例7: reprocess_form

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
def reprocess_form(sender, xform, *args, **kwargs):
    from corehq.apps.commtrack.processing import process_stock
    result = process_stock([xform])
    for to_save in result.get_models_to_save():
        if to_save:
            to_save.commit()
    result.finalize()
    # todo: use LedgerProcessor
    CommCareCase.get_db().bulk_save(result.relevant_cases)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:11,代码来源:models.py

示例8: setUpClass

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
 def setUpClass(cls):
     cls.domain = 'lalksdjflakjsdf'
     cls.cases = [
         CommCareCase(domain=cls.domain, type='type1', name='Alice', user_id='XXX'),
         CommCareCase(domain=cls.domain, type='type2', name='Bob', user_id='XXX'),
         CommCareCase(domain=cls.domain, type='type1', name='Candice', user_id='ZZZ'),
         CommCareCase(domain=cls.domain, type='type1', name='Derek', user_id='XXX', closed=True),
         CommCareCase(domain='maleficent', type='type1', name='Mallory', user_id='YYY')
     ]
     CommCareCase.get_db().bulk_save(cls.cases)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:12,代码来源:test_dbaccessors.py

示例9: _update_case

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [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'))
    if should_use_sql_backend(domain):
        CaseAccessorSQL.save_case(case)
    else:
        # can't call case.save() since it overrides the server_modified_on property
        CommCareCase.get_db().save_doc(case.to_json())
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:13,代码来源:test_auto_case_updates.py

示例10: tag_cases_as_deleted_and_remove_indices

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
def tag_cases_as_deleted_and_remove_indices(domain, docs, deletion_id):
    from corehq.apps.sms.tasks import delete_phone_numbers_for_owners
    from corehq.apps.reminders.tasks import delete_reminders_for_cases
    for doc in docs:
        doc['doc_type'] += DELETED_SUFFIX
        doc['-deletion_id'] = deletion_id
    CommCareCase.get_db().bulk_save(docs)
    case_ids = [doc['_id'] for doc in docs]
    _remove_indices_from_deleted_cases_task.delay(domain, case_ids)
    delete_phone_numbers_for_owners.delay(case_ids)
    delete_reminders_for_cases.delay(domain, case_ids)
开发者ID:nnestle,项目名称:commcare-hq,代码行数:13,代码来源:tasks.py

示例11: test_simple_delete

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
 def test_simple_delete(self):
     factory = CaseFactory()
     case = factory.create_case()
     [case] = factory.create_or_update_case(CaseStructure(case_id=case._id, attrs={'update': {'foo': 'bar'}}))
     self.assertTrue(CommCareCase.get_db().doc_exist(case._id))
     self.assertEqual(2, len(case.xform_ids))
     for form_id in case.xform_ids:
         self.assertTrue(XFormInstance.get_db().doc_exist(form_id))
     safe_hard_delete(case)
     self.assertFalse(CommCareCase.get_db().doc_exist(case._id))
     for form_id in case.xform_ids:
         self.assertFalse(XFormInstance.get_db().doc_exist(form_id))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:14,代码来源:test_delete.py

示例12: test_delete_sharing_form

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
    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.assertTrue(CommCareCase.get_db().doc_exist(c1._id))
        self.assertTrue(CommCareCase.get_db().doc_exist(c2._id))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:16,代码来源:test_delete.py

示例13: handle

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
    def handle(self, *args, **options):
        with open('bihar_case_cleanup.csv', 'wb') as f:
            csv_file = csv.writer(f)
            csv_file.writerow(CaseRow.headers)

            blank_case_ids = get_case_ids_in_domain('care-bihar',
                                                    type=('', None))
            task_case_ids = get_case_ids_in_domain('care-bihar', type='task')

            case_ids = set(blank_case_ids) | set(task_case_ids)
            to_save = []

            logger.info("Total cases to process: {}".format(len(case_ids)))
            for i, doc in enumerate(iter_docs(CommCareCase.get_db(), case_ids)):
                case = CommCareCase.wrap(doc)

                if case.type and case.type != "task":
                    continue
    
                parent = None
                if case.indices:
                    parent_id = case.indices[0].referenced_id
                    try:
                        parent = CommCareCase.get(parent_id)
                    except ResourceNotFound:
                        parent = MissingParent(get_id=parent_id, owner_id='Parent Missing')

                case_row = CaseRow(case, parent)

                if case.type != 'task':
                    if case.user_id == MOTECH_ID:
                        case_row.update_type('task')

                if parent and not isinstance(parent, MissingParent) and parent.owner_id != case.owner_id:
                    case_row.update_owner(parent.owner_id)

                if case_row.save:
                    csv_file.writerow(case_row.to_row())
                    to_save.append(case_row.case)

                if len(to_save) > 100:
                    CommCareCase.get_db().bulk_save(to_save)
                    to_save = []

                if i % 100 == 0:
                    logger.info("{current}/{count} cases completed".format(current=i, count=len(case_ids)))

            if to_save:
                CommCareCase.get_db().bulk_save(to_save)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:51,代码来源:bihar_cleanup_case.py

示例14: testDocTypeCheck

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
    def testDocTypeCheck(self):
        id = uuid.uuid4().hex
        CommCareCase.get_db().save_doc({
            "_id": id,
            "doc_type": "AintNoCasesHere"
        })
        doc_back = CommCareCase.get_db().get(id)
        self.assertEqual("AintNoCasesHere", doc_back['doc_type'])

        cache = CaseDbCacheCouch()
        try:
            cache.get(id)
            self.fail('doc type security check failed to raise exception')
        except IllegalCaseId:
            pass
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:17,代码来源:test_dbcache.py

示例15: filter_cases_modified_elsewhere_since_sync

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get_db [as 别名]
def filter_cases_modified_elsewhere_since_sync(cases, last_sync):
    # this function is pretty ugly and is heavily optimized to reduce the number
    # of queries to couch.
    if not last_sync:
        return cases
    else:
        case_ids = [case['_id'] for case in cases]
        case_log_map = CommCareCase.get_db().view(
            'phone/cases_to_sync_logs',
            keys=case_ids,
            reduce=False,
        )
        # incoming format is a list of objects that look like this:
        # {
        #   'value': '[log id]',
        #   'key': '[case id]',
        # }
        unique_combinations = set((row['key'], row['value']) for row in case_log_map)
        modification_dates = CommCareCase.get_db().view(
            'phone/case_modification_status',
            keys=[list(combo) for combo in unique_combinations],
            reduce=True,
            group=True,
        )
        # we'll build a structure that looks like this for efficiency:
        # { case_id: [{'token': 'token value', 'date': 'date value'}, ...]}
        all_case_updates_by_sync_token = defaultdict(list)
        for row in modification_dates:
            # incoming format is a list of objects that look like this:
            # {
            #   'value': '2012-08-22T08:55:14Z', (most recent date updated)
            #   'key': ['[case id]', '[sync token id]']
            # }
            if row['value']:
                all_case_updates_by_sync_token[row['key'][0]].append(
                    {'token': row['key'][1], 'date': datetime.strptime(row['value'], '%Y-%m-%dT%H:%M:%SZ')}
                )

        def case_modified_elsewhere_since_sync(case_id):
            # NOTE: uses closures
            return any([row['date'] >= last_sync.date and row['token'] != last_sync._id
                        for row in all_case_updates_by_sync_token[case_id]])

        def relevant(case):
            case_id = case['_id']
            return case_modified_elsewhere_since_sync(case_id) or not last_sync.phone_is_holding_case(case_id)

        return filter(relevant, cases)
开发者ID:jmaina,项目名称:commcare-hq,代码行数:50,代码来源:caselogic.py


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