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


Python FormAccessorSQL.update_form方法代码示例

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


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

示例1: test_save_form_deprecated

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL import update_form [as 别名]
    def test_save_form_deprecated(self):
        existing_form, new_form = _simulate_form_edit()

        FormAccessorSQL.update_form(existing_form, publish_changes=False)
        FormAccessorSQL.save_new_form(new_form)

        self._validate_deprecation(existing_form, new_form)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:test_form_dbaccessor.py

示例2: test_update_form

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL import update_form [as 别名]
    def test_update_form(self):
        form = create_form_for_test(DOMAIN)
        form.user_id = 'user2'
        operation_date = datetime.utcnow()
        form.track_create(XFormOperationSQL(
            user_id='user2',
            date=operation_date,
            operation=XFormOperationSQL.EDIT
        ))
        FormAccessorSQL.update_form(form)

        saved_form = FormAccessorSQL.get_form(form.form_id)
        self.assertEqual('user2', saved_form.user_id)
        self.assertEqual(1, len(saved_form.history))
        self.assertEqual(operation_date, saved_form.history[0].date)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:17,代码来源:test_form_dbaccessor.py

示例3: save_processed_models

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL import update_form [as 别名]
    def save_processed_models(cls, processed_forms, cases=None, stock_result=None, publish_to_kafka=True):
        db_names = {processed_forms.submitted.db}
        if processed_forms.deprecated:
            db_names |= {processed_forms.deprecated.db}

        if cases:
            db_names |= {case.db for case in cases}

        if stock_result:
            db_names |= {
                ledger_value.db for ledger_value in stock_result.models_to_save
            }

        with ExitStack() as stack:
            for db_name in db_names:
                stack.enter_context(transaction.atomic(db_name))

            # Save deprecated form first to avoid ID conflicts
            if processed_forms.deprecated:
                FormAccessorSQL.update_form(processed_forms.deprecated, publish_changes=False)

            FormAccessorSQL.save_new_form(processed_forms.submitted)
            if cases:
                for case in cases:
                    CaseAccessorSQL.save_case(case)

            if stock_result:
                ledgers_to_save = stock_result.models_to_save
                LedgerAccessorSQL.save_ledger_values(ledgers_to_save, stock_result)

        if cases:
            sort_submissions = toggles.SORT_OUT_OF_ORDER_FORM_SUBMISSIONS_SQL.enabled(
                processed_forms.submitted.domain, toggles.NAMESPACE_DOMAIN)
            if sort_submissions:
                for case in cases:
                    if SqlCaseUpdateStrategy(case).reconcile_transactions_if_necessary():
                        CaseAccessorSQL.save_case(case)

        if publish_to_kafka:
            try:
                cls.publish_changes_to_kafka(processed_forms, cases, stock_result)
            except Exception as e:
                raise KafkaPublishingError(e)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:45,代码来源:processor.py

示例4: undo_form_edits

# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL import update_form [as 别名]
def undo_form_edits(form_tuples, logger):
    cases_to_rebuild = defaultdict(set)
    ledgers_to_rebuild = defaultdict(set)
    operation_date = datetime.utcnow()
    for live_form, deprecated_form in form_tuples:
        # undo corehq.form_processor.parsers.form.apply_deprecation
        case_cache = CaseDbCacheSQL(live_form.domain)
        live_case_updates = get_case_updates(live_form)
        deprecated_case_updates = get_case_updates(deprecated_form)
        case_cache.populate(
            set(cu.id for cu in live_case_updates) | set(cu.id for cu in deprecated_case_updates)
        )

        deprecated_form.form_id = new_id_in_same_dbalias(deprecated_form.form_id)
        deprecated_form.state = XFormInstanceSQL.NORMAL
        deprecated_form.orig_id = None
        deprecated_form.edited_on = None

        live_form.deprecated_form_id = None
        live_form.received_on = live_form.edited_on
        live_form.edited_on = None

        affected_cases, affected_ledgers = update_case_transactions_for_form(
            case_cache, live_case_updates, deprecated_case_updates, live_form, deprecated_form
        )

        for form in (live_form, deprecated_form):
            form.track_create(XFormOperationSQL(
                user_id='system',
                operation=XFormOperationSQL.UUID_DATA_FIX,
                date=operation_date)
            )
            FormAccessorSQL.update_form(form)

        logger.log('Form edit undone: {}, {}({})'.format(
            live_form.form_id, deprecated_form.form_id, deprecated_form.original_form_id
        ))
        cases_to_rebuild[live_form.domain].update(affected_cases)
        ledgers_to_rebuild[live_form.domain].update(affected_ledgers)
        logger.log('Cases to rebuild: {}'.format(','.join(affected_cases)))
        logger.log('Ledgers to rebuild: {}'.format(','.join([l.as_id() for l in affected_ledgers])))

    return cases_to_rebuild, ledgers_to_rebuild
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:45,代码来源:undo_uuid_clash.py


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