本文整理汇总了Python中corehq.form_processor.interfaces.processor.FormProcessorInterface.save_processed_models方法的典型用法代码示例。如果您正苦于以下问题:Python FormProcessorInterface.save_processed_models方法的具体用法?Python FormProcessorInterface.save_processed_models怎么用?Python FormProcessorInterface.save_processed_models使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.form_processor.interfaces.processor.FormProcessorInterface
的用法示例。
在下文中一共展示了FormProcessorInterface.save_processed_models方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_xform_pillow_sql
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import save_processed_models [as 别名]
def test_xform_pillow_sql(self):
consumer = get_test_kafka_consumer(topics.FORM_SQL)
# have to get the seq id before the change is processed
kafka_seq = consumer.offsets()['fetch'][(topics.FORM_SQL, 0)]
metadata = TestFormMetadata(domain=self.domain)
form = get_form_ready_to_save(metadata, is_db_test=True)
form_processor = FormProcessorInterface(domain=self.domain)
form_processor.save_processed_models([form])
# confirm change made it to kafka
message = consumer.next()
change_meta = change_meta_from_kafka_message(message.value)
self.assertEqual(form.form_id, change_meta.document_id)
self.assertEqual(self.domain, change_meta.domain)
# send to elasticsearch
sql_pillow = get_sql_xform_to_elasticsearch_pillow()
sql_pillow.process_changes(since=kafka_seq, forever=False)
self.elasticsearch.indices.refresh(self.pillow.es_index)
# confirm change made it to elasticserach
results = FormES().run()
self.assertEqual(1, results.total)
form_doc = results.hits[0]
self.assertEqual(self.domain, form_doc['domain'])
self.assertEqual(metadata.xmlns, form_doc['xmlns'])
self.assertEqual('XFormInstance', form_doc['doc_type'])
示例2: create_form_and_sync_to_es
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import save_processed_models [as 别名]
def create_form_and_sync_to_es(received_on):
with process_kafka_changes('XFormToElasticsearchPillow'):
with process_couch_changes('DefaultChangeFeedPillow'):
metadata = TestFormMetadata(domain=cls.domain, app_id=cls.app_id,
xmlns=cls.xmlns, received_on=received_on)
form = get_form_ready_to_save(metadata, is_db_test=True)
form_processor = FormProcessorInterface(domain=cls.domain)
form_processor.save_processed_models([form])
return form
示例3: create_form_and_sync_to_es
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import save_processed_models [as 别名]
def create_form_and_sync_to_es(received_on):
with process_pillow_changes('xform-pillow', {'skip_ucr': True}):
with process_pillow_changes('DefaultChangeFeedPillow'):
metadata = TestFormMetadata(domain=cls.domain, app_id=cls.app_id,
xmlns=cls.xmlns, received_on=received_on)
form = get_form_ready_to_save(metadata, is_db_test=True)
form_processor = FormProcessorInterface(domain=cls.domain)
form_processor.save_processed_models([form])
return form
示例4: _create_form_and_sync_to_es
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import save_processed_models [as 别名]
def _create_form_and_sync_to_es(self):
with process_pillow_changes('xform-pillow', {'skip_ucr': True}):
with process_pillow_changes('DefaultChangeFeedPillow'):
metadata = TestFormMetadata(domain=self.domain)
form = get_form_ready_to_save(metadata, is_db_test=True)
form_processor = FormProcessorInterface(domain=self.domain)
form_processor.save_processed_models([form])
self.elasticsearch.indices.refresh(XFORM_INDEX_INFO.index)
return form, metadata
示例5: get_simple_wrapped_form
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import save_processed_models [as 别名]
def get_simple_wrapped_form(form_id, case_id=None, metadata=None, save=True):
from corehq.form_processor.interfaces.processor import FormProcessorInterface
xml = get_simple_form_xml(form_id=form_id, metadata=metadata)
form_json = convert_xform_to_json(xml)
interface = FormProcessorInterface(domain=metadata.domain)
wrapped_form = interface.new_xform(form_json)
wrapped_form.domain = metadata.domain
interface.store_attachments(wrapped_form, [Attachment('form.xml', xml, 'text/xml')])
if save:
interface.save_processed_models([wrapped_form])
return wrapped_form
示例6: get_simple_wrapped_form
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import save_processed_models [as 别名]
def get_simple_wrapped_form(form_id, metadata=None, save=True, simple_form=SIMPLE_FORM):
from corehq.form_processor.interfaces.processor import FormProcessorInterface
metadata = metadata or TestFormMetadata()
xml = get_simple_form_xml(form_id=form_id, metadata=metadata, simple_form=simple_form)
form_json = convert_xform_to_json(xml)
interface = FormProcessorInterface(domain=metadata.domain)
wrapped_form = interface.new_xform(form_json)
wrapped_form.domain = metadata.domain
wrapped_form.received_on = metadata.received_on
interface.store_attachments(wrapped_form, [Attachment('form.xml', xml, 'text/xml')])
if save:
interface.save_processed_models([wrapped_form])
return wrapped_form
示例7: SubmissionPost
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import save_processed_models [as 别名]
class SubmissionPost(object):
failed_auth_response = HttpResponseForbidden('Bad auth')
def __init__(self, instance=None, attachments=None, auth_context=None,
domain=None, app_id=None, build_id=None, path=None,
location=None, submit_ip=None, openrosa_headers=None,
last_sync_token=None, received_on=None, date_header=None,
partial_submission=False):
assert domain, domain
assert instance, instance
assert not isinstance(instance, HttpRequest), instance
self.domain = domain
self.app_id = app_id
self.build_id = build_id
# get_location has good default
self.location = location or couchforms.get_location()
self.received_on = received_on
self.date_header = date_header
self.submit_ip = submit_ip
self.last_sync_token = last_sync_token
self.openrosa_headers = openrosa_headers or {}
self.instance = instance
self.attachments = attachments or {}
self.auth_context = auth_context or DefaultAuthContext()
self.path = path
self.interface = FormProcessorInterface(domain)
self.formdb = FormAccessors(domain)
self.partial_submission = partial_submission
def _set_submission_properties(self, xform):
# attaches shared properties of the request to the document.
# used on forms and errors
xform.auth_context = self.auth_context.to_json()
xform.submit_ip = self.submit_ip
xform.path = self.path
xform.openrosa_headers = self.openrosa_headers
xform.last_sync_token = self.last_sync_token
if self.received_on:
xform.received_on = self.received_on
if self.date_header:
xform.date_header = self.date_header
xform.app_id = self.app_id
xform.build_id = self.build_id
xform.export_tag = ["domain", "xmlns"]
xform.partial_submission = self.partial_submission
return xform
def _handle_known_error(self, error, instance, xforms):
# errors we know about related to the content of the form
# log the error and respond with a success code so that the phone doesn't
# keep trying to send the form
instance = _transform_instance_to_error(self.interface, error, instance)
xforms[0] = instance
# this is usually just one document, but if an edit errored we want
# to save the deprecated form as well
self.interface.save_processed_models(xforms)
def _handle_basic_failure_modes(self):
if timezone_migration_in_progress(self.domain):
# keep submissions on the phone
# until ready to start accepting again
return HttpResponse(status=503), None, []
if not self.auth_context.is_valid():
return self.failed_auth_response, None, []
if isinstance(self.instance, BadRequest):
return HttpResponseBadRequest(self.instance.message), None, []
def _post_process_form(self, xform):
self._set_submission_properties(xform)
if xform.is_submission_error_log:
found_old = scrub_meta(xform)
legacy_notification_assert(not found_old, 'Form with old metadata submitted', xform.form_id)
def run(self):
failure_result = self._handle_basic_failure_modes()
if failure_result:
return failure_result
result = process_xform_xml(self.domain, self.instance, self.attachments)
submitted_form = result.submitted_form
self._post_process_form(submitted_form)
if submitted_form.is_submission_error_log:
self.formdb.save_new_form(submitted_form)
response = self.get_exception_response_and_log(submitted_form, self.path)
return response, None, []
cases = []
with result.get_locked_forms() as xforms:
instance = xforms[0]
if instance.xmlns == DEVICE_LOG_XMLNS:
try:
#.........这里部分代码省略.........
示例8: SubmissionPost
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import save_processed_models [as 别名]
class SubmissionPost(object):
def __init__(self, instance=None, attachments=None, auth_context=None,
domain=None, app_id=None, build_id=None, path=None,
location=None, submit_ip=None, openrosa_headers=None,
last_sync_token=None, received_on=None, date_header=None,
partial_submission=False, case_db=None):
assert domain, "'domain' is required"
assert instance, instance
assert not isinstance(instance, HttpRequest), instance
self.domain = domain
self.app_id = app_id
self.build_id = build_id
# get_location has good default
self.location = location or couchforms.get_location()
self.received_on = received_on
self.date_header = date_header
self.submit_ip = submit_ip
self.last_sync_token = last_sync_token
self.openrosa_headers = openrosa_headers or {}
self.instance = instance
self.attachments = attachments or {}
self.auth_context = auth_context or DefaultAuthContext()
self.path = path
self.interface = FormProcessorInterface(domain)
self.formdb = FormAccessors(domain)
self.partial_submission = partial_submission
# always None except in the case where a system form is being processed as part of another submission
# e.g. for closing extension cases
self.case_db = case_db
if case_db:
assert case_db.domain == domain
self.is_openrosa_version3 = self.openrosa_headers.get(OPENROSA_VERSION_HEADER, '') == OPENROSA_VERSION_3
self.track_load = form_load_counter("form_submission", domain)
def _set_submission_properties(self, xform):
# attaches shared properties of the request to the document.
# used on forms and errors
xform.submit_ip = self.submit_ip
xform.path = self.path
xform.openrosa_headers = self.openrosa_headers
xform.last_sync_token = self.last_sync_token
if self.received_on:
xform.received_on = self.received_on
if self.date_header:
xform.date_header = self.date_header
xform.app_id = self.app_id
xform.build_id = self.build_id
xform.export_tag = ["domain", "xmlns"]
xform.partial_submission = self.partial_submission
return xform
def _handle_known_error(self, error, instance, xforms):
# errors we know about related to the content of the form
# log the error and respond with a success code so that the phone doesn't
# keep trying to send the form
xforms[0] = _transform_instance_to_error(self.interface, error, instance)
# this is usually just one document, but if an edit errored we want
# to save the deprecated form as well
self.interface.save_processed_models(xforms)
def _handle_basic_failure_modes(self):
if any_migrations_in_progress(self.domain):
# keep submissions on the phone
# until ready to start accepting again
return HttpResponse(status=503)
if not self.auth_context.is_valid():
return HttpResponseForbidden('Bad auth')
if isinstance(self.instance, BadRequest):
return HttpResponseBadRequest(self.instance.message)
def _post_process_form(self, xform):
self._set_submission_properties(xform)
found_old = scrub_meta(xform)
legacy_notification_assert(not found_old, 'Form with old metadata submitted', xform.form_id)
def _get_success_message(self, instance, cases=None):
'''
Formplayer requests get a detailed success message pointing to the form/case affected.
All other requests get a generic message.
Message is formatted with markdown.
'''
if not instance.metadata or instance.metadata.deviceID != FORMPLAYER_DEVICE_ID:
return ' √ '
messages = []
user = CouchUser.get_by_user_id(instance.user_id)
if not user or not user.is_web_user():
return _('Form successfully saved!')
from corehq.apps.export.views.list import CaseExportListView, FormExportListView
#.........这里部分代码省略.........