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


Python CommCareCase.xform_ids方法代码示例

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


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

示例1: rebuild_case

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import xform_ids [as 别名]
def rebuild_case(case_id):
    """
    Given a case ID, rebuild the entire case state based on all existing forms
    referencing it. Useful when things go wrong or when you need to manually
    rebuild a case after archiving / deleting it
    """

    try:
        case = CommCareCase.get(case_id)
        found = True
    except ResourceNotFound:
        case = CommCareCase()
        case._id = case_id
        found = False

    # clear actions, xform_ids, close state, and all dynamic properties
    dynamic_properties = set([k for action in case.actions for k in action.updated_unknown_properties.keys()])
    for k in dynamic_properties:
        try:
            delattr(case, k)
        except KeyError:
            pass

    # already deleted means it was explicitly set to "deleted",
    # as opposed to getting set to that because it has no actions
    already_deleted = case.doc_type == 'CommCareCase-Deleted' and primary_actions(case)
    if not already_deleted:
        case.doc_type = 'CommCareCase'
    case.xform_ids = []
    case.actions = []
    case.closed = False
    case.closed_on = None
    case.closed_by = ''

    form_ids = get_case_xform_ids(case_id)
    forms = [fetch_and_wrap_form(id) for id in form_ids]
    filtered_forms = [f for f in forms if f.doc_type == "XFormInstance"]
    sorted_forms = sorted(filtered_forms, key=lambda f: f.received_on)
    for form in sorted_forms:
        if not found and case.domain is None:
            case.domain = form.domain
        assert form.domain == case.domain

        case_updates = get_case_updates(form)
        filtered_updates = [u for u in case_updates if u.id == case_id]
        for u in filtered_updates:
            case.update_from_case_update(u, form)

    case.xform_ids = [f._id for f in sorted_forms]
    if not case.xform_ids:
        if not found:
            return None
        # there were no more forms. 'delete' the case
        case.doc_type = 'CommCareCase-Deleted'

    # add a "rebuild" action
    case.actions.append(_rebuild_action())
    case.save()
    return case
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:61,代码来源:cleanup.py

示例2: rebuild_case

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import xform_ids [as 别名]
def rebuild_case(case_id):
    """
    Given a case ID, rebuild the entire case state based on all existing forms
    referencing it. Useful when things go wrong or when you need to manually
    rebuild a case after archiving / deleting it
    """

    try:
        case = CommCareCase.get(case_id)
        found = True
    except ResourceNotFound:
        case = CommCareCase()
        case._id = case_id
        found = False

    reset_state(case)
    # in addition to resetting the state, also manually clear xform_ids and actions
    # since we're going to rebuild these from the forms
    case.xform_ids = []
    case.actions = []

    forms = get_case_forms(case_id)
    filtered_forms = [f for f in forms if f.doc_type == "XFormInstance"]
    sorted_forms = sorted(filtered_forms, key=lambda f: f.received_on)
    for form in sorted_forms:
        if not found and case.domain is None:
            case.domain = form.domain
        assert form.domain == case.domain

        case_updates = get_case_updates(form)
        filtered_updates = [u for u in case_updates if u.id == case_id]
        for u in filtered_updates:
            case.actions.extend(u.get_case_actions(form))

    # call "rebuild" on the case, which should populate xform_ids
    # and re-sort actions if necessary
    case.rebuild(strict=False, xforms={f._id: f for f in sorted_forms})
    case.xform_ids = case.xform_ids + [f._id for f in sorted_forms if f._id not in case.xform_ids]

    # todo: should this move to case.rebuild?
    if not case.xform_ids:
        if not found:
            return None
        # there were no more forms. 'delete' the case
        case.doc_type = 'CommCareCase-Deleted'

    # add a "rebuild" action
    case.actions.append(_rebuild_action())
    case.save()
    return case
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:52,代码来源:cleanup.py

示例3: testConflictingIdsFail

# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import xform_ids [as 别名]
    def testConflictingIdsFail(self):
        original = CommCareCase()
        original.xform_ids = ['f1', 'f2']
        original.save()
        conflict = CommCareCase.get(original._id)
        original.xform_ids.append('f3')
        original.save()
        for xform_ids in [
            [],
            ['f1'],
            ['f1', 'f2'],
            ['f1', 'f2', 'f4']
        ]:
            conflict.xform_ids = xform_ids 
            try:
                conflict.force_save()
                self.fail('conflicting force save should fail if new forms found!')
            except ResourceConflict:
                pass

        # adding should be ok
        conflict.xform_ids = ['f1', 'f2', 'f3', 'f4']
        conflict.force_save()
开发者ID:dimagi,项目名称:casexml,代码行数:25,代码来源:test_force_save.py


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