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


Python processor.FormProcessorInterface类代码示例

本文整理汇总了Python中corehq.form_processor.interfaces.processor.FormProcessorInterface的典型用法代码示例。如果您正苦于以下问题:Python FormProcessorInterface类的具体用法?Python FormProcessorInterface怎么用?Python FormProcessorInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: _handle_duplicate

def _handle_duplicate(new_doc, instance):
    """
    Handle duplicate xforms and xform editing ('deprecation')

    existing doc *must* be validated as an XFormInstance in the right domain
    and *must* include inline attachments

    """
    interface = FormProcessorInterface(new_doc.domain)
    conflict_id = new_doc.form_id
    existing_doc = FormAccessors(new_doc.domain).get_with_attachments(conflict_id)

    existing_md5 = existing_doc.xml_md5()
    new_md5 = hashlib.md5(instance).hexdigest()

    if existing_md5 != new_md5:
        # if the form contents are not the same:
        #  - "Deprecate" the old form by making a new document with the same contents
        #    but a different ID and a doc_type of XFormDeprecated
        #  - Save the new instance to the previous document to preserve the ID
        existing_doc, new_doc = apply_deprecation(existing_doc, new_doc, interface)

        return FormProcessingResult(new_doc, existing_doc)
    else:
        # follow standard dupe handling, which simply saves a copy of the form
        # but a new doc_id, and a doc_type of XFormDuplicate
        duplicate = interface.deduplicate_xform(new_doc)
        return FormProcessingResult(duplicate)
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:28,代码来源:form.py

示例2: test_xform_pillow_sql

    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'])
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:29,代码来源:test_xform_pillow.py

示例3: _perfom_post_save_actions

def _perfom_post_save_actions(form, save=True):
    interface = FormProcessorInterface(form.domain)
    cache = interface.casedb_cache(
        domain=form.domain, lock=False, deleted_ok=True, xforms=[form],
        load_src="reprocess_form_post_save",
    )
    with cache as casedb:
        case_stock_result = SubmissionPost.process_xforms_for_cases([form], casedb)
        case_models = case_stock_result.case_models

        if interface.use_sql_domain:
            forms = ProcessedForms(form, None)
            stock_result = case_stock_result.stock_result
            try:
                FormProcessorSQL.publish_changes_to_kafka(forms, case_models, stock_result)
            except Exception:
                error_message = "Error publishing to kafka"
                return ReprocessingResult(form, None, None, error_message)

        try:
            save and SubmissionPost.do_post_save_actions(casedb, [form], case_stock_result)
        except PostSaveError:
            error_message = "Error performing post save operations"
            return ReprocessingResult(form, None, None, error_message)
        return ReprocessingResult(form, case_models, None, None)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:25,代码来源:reprocess.py

示例4: safe_hard_delete

def safe_hard_delete(case):
    """
    Hard delete a case - by deleting the case itself as well as all forms associated with it
    permanently from the database.

    Will fail hard if the case has any reverse indices or if any of the forms associated with
    the case also touch other cases.

    This is used primarily for cleaning up system cases/actions (e.g. the location delegate case).
    """
    if not settings.UNIT_TESTING:
        from corehq.apps.commtrack.const import USER_LOCATION_OWNER_MAP_TYPE

        if not (case.is_deleted or case.type == USER_LOCATION_OWNER_MAP_TYPE):
            raise CommCareCaseError("Attempt to hard delete a live case whose type isn't white listed")

    if case.reverse_indices:
        raise CommCareCaseError("You can't hard delete a case that has other dependencies ({})!".format(case.case_id))
    interface = FormProcessorInterface(case.domain)
    forms = interface.get_case_forms(case.case_id)
    for form in forms:
        case_updates = get_case_updates(form)
        if any([c.id != case.case_id for c in case_updates]):
            raise CommCareCaseError("You can't hard delete a case that has shared forms with other cases!")

    interface.hard_delete_case_and_forms(case, forms)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:26,代码来源:cleanup.py

示例5: get_related_cases

def get_related_cases(initial_cases, domain, strip_history=False, search_up=True):
    """
    Gets the flat list of related cases based on a starting list.
    Walks all the referenced indexes recursively.
    If search_up is True, all cases and their parent cases are returned.
    If search_up is False, all cases and their child cases are returned.
    """
    if not initial_cases:
        return {}

    # infer whether to wrap or not based on whether the initial list is wrapped or not
    # initial_cases may be a list or a set
    wrap = isinstance(next(iter(initial_cases)), CommCareCase)

    # todo: should assert that domain exists here but this breaks tests
    case_db = FormProcessorInterface(domain).casedb_cache(
        domain=domain,
        strip_history=strip_history,
        deleted_ok=True,
        wrap=wrap,
        initial=initial_cases
    )

    def indices(case):
        return case['indices'] if search_up else get_reverse_indices_json(domain, case['_id'])

    relevant_cases = {}
    relevant_deleted_case_ids = []

    cases_to_process = list(case for case in initial_cases)
    directly_referenced_indices = itertools.chain(
        *[[index['referenced_id'] for index in indices(case)]
          for case in initial_cases]
    )
    case_db.populate(directly_referenced_indices)

    def process_cases(cases):
        new_relations = set()
        for case in cases:
            if case and case['_id'] not in relevant_cases:
                relevant_cases[case['_id']] = case
                if case['doc_type'] == 'CommCareCase-Deleted':
                    relevant_deleted_case_ids.append(case['_id'])
                new_relations.update(index['referenced_id'] for index in indices(case))

        if new_relations:
            case_db.populate(new_relations)
            return [case_db.get(related_case) for related_case in new_relations]

    while cases_to_process:
        cases_to_process = process_cases(cases_to_process)

    if relevant_deleted_case_ids:
        logging.info('deleted cases included in footprint (restore): %s' % (
            ', '.join(relevant_deleted_case_ids)
        ))

    return relevant_cases
开发者ID:,项目名称:,代码行数:58,代码来源:

示例6: create_form_and_sync_to_es

 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
开发者ID:,项目名称:,代码行数:9,代码来源:

示例7: test_sync_log_invalidation_bug

    def test_sync_log_invalidation_bug(self):
        sync_log = FormProcessorInterface().sync_log_model(user_id="6dac4940-913e-11e0-9d4b-005056aa7fb5")
        sync_log.save()
        self.addCleanup(FormProcessorTestUtils.delete_all_sync_logs)

        _, case = self._doCreateCaseWithMultimedia()

        # this used to fail before we fixed http://manage.dimagi.com/default.asp?158373
        self._doSubmitUpdateWithMultimedia(new_attachments=["commcare_logo_file"], removes=[], sync_token=sync_log._id)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:9,代码来源:test_multimedia.py

示例8: create_form_and_sync_to_es

 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
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:test_analytics.py

示例9: _create_form_and_sync_to_es

 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
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:9,代码来源:test_xform_pillow.py

示例10: process_stock

def process_stock(xforms, case_db=None):
    """
    process the commtrack xml constructs in an incoming submission
    """
    if not case_db:
        case_db = FormProcessorInterface(xforms[0].domain).casedb_cache()
    else:
        assert isinstance(case_db, AbstractCaseDbCache)

    sorted_forms = sorted(xforms, key=lambda f: 0 if f.is_deprecated else 1)
    stock_report_helpers = []
    case_action_intents = []
    for xform in sorted_forms:
        actions_for_form = get_stock_actions(xform)
        stock_report_helpers += actions_for_form.stock_report_helpers
        case_action_intents += actions_for_form.case_action_intents

    # omitted: normalize_transactions (used for bulk requisitions?)

    # validate the parsed transactions
    for stock_report_helper in stock_report_helpers:
        stock_report_helper.validate()

    relevant_cases = []
    # touch every case for proper ota restore logic syncing to be preserved
    for action_intent in case_action_intents:
        case_id = action_intent.case_id
        case = case_db.get(action_intent.case_id)
        relevant_cases.append(case)
        if case is None:
            raise IllegalCaseId(
                _('Ledger transaction references invalid Case ID "{}"')
                .format(case_id))

        if action_intent.is_deprecation:
            # just remove the old stock actions for the form from the case
            case.actions = [
                a for a in case.actions if not
                (a.xform_id == action_intent.form_id and a.action_type == CASE_ACTION_COMMTRACK)
            ]
        else:
            case_action = action_intent.action
            # hack: clear the sync log id so this modification always counts
            # since consumption data could change server-side
            case_action.sync_log_id = ''
            case.actions.append(case_action)
            if action_intent.form_id not in case.xform_ids:
                case.xform_ids.append(action_intent.form_id)

        case_db.mark_changed(case)

    return StockProcessingResult(
        xform=sorted_forms[-1],
        relevant_cases=relevant_cases,
        stock_report_helpers=stock_report_helpers,
    )
开发者ID:nnestle,项目名称:commcare-hq,代码行数:56,代码来源:processing.py

示例11: test_xform_locked

 def test_xform_locked(self):
     from corehq.form_processor.interfaces.processor import FormProcessorInterface
     form_id = 'ad38211be256653bceac8e2156475664'
     proc = FormProcessorInterface(self.domain)
     lock = proc.acquire_lock_for_xform(form_id)
     try:
         _, response = self._submit('simple_form.xml')
     finally:
         lock.release()
     self.assertEqual(response.status_code, 423)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:10,代码来源:test_submit_errors.py

示例12: acquire_lock_for_xform

def acquire_lock_for_xform(xform_id):
    from corehq.form_processor.interfaces.processor import FormProcessorInterface

    # this is high, but I want to test if MVP conflicts disappear
    lock = FormProcessorInterface().xform_model.get_obj_lock_by_id(xform_id, timeout_seconds=2 * 60)
    try:
        lock.acquire()
    except RedisError:
        lock = None
    return lock
开发者ID:nnestle,项目名称:commcare-hq,代码行数:10,代码来源:xform.py

示例13: test_cant_own_case

    def test_cant_own_case(self):
        interface = FormProcessorInterface()
        _, _, [case] = interface.submit_form_locally(ALICE_XML, ALICE_DOMAIN)
        response, form, cases = interface.submit_form_locally(EVE_XML, EVE_DOMAIN)

        self.assertIn('IllegalCaseId', response.content)
        self.assertFalse(hasattr(case, 'plan_to_buy_gun'))

        _, _, [case] = interface.submit_form_locally(ALICE_UPDATE_XML, ALICE_DOMAIN)
        self.assertEqual(case.plan_to_buy_gun, 'no')
开发者ID:nnestle,项目名称:commcare-hq,代码行数:10,代码来源:test_domains.py

示例14: get_models_to_save

    def get_models_to_save(self):
        processor = FormProcessorInterface(domain=self.domain).ledger_processor
        ledger_db = LedgerDB(processor=processor)
        update_results = []

        for stock_report_helper in self.stock_report_helpers:
            this_result = processor.get_models_to_update(stock_report_helper, ledger_db)
            if this_result:
                update_results.append(this_result)
        return update_results
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:10,代码来源:processing.py

示例15: testOutOfOrderSubmissions

    def testOutOfOrderSubmissions(self):
        dir = os.path.join(os.path.dirname(__file__), "data", "ordering")
        interface = FormProcessorInterface()
        for fname in ('update_oo.xml', 'create_oo.xml'):
            with open(os.path.join(dir, fname), "rb") as f:
                xml_data = f.read()
            interface.submit_form_locally(xml_data)

        case = interface.case_model.get('30bc51f6-3247-4966-b4ae-994f572e85fe')
        self.assertEqual('from the update form', case.pupdate)
        self.assertEqual('from the create form', case.pcreate)
        self.assertEqual('overridden by the update form', case.pboth)
开发者ID:nnestle,项目名称:commcare-hq,代码行数:12,代码来源:test_out_of_order_processing.py


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