本文整理汇总了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)
示例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)
示例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)
示例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