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


Python RestoreConfig.get_response方法代码示例

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


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

示例1: get_restore_response

# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_response [as 别名]
def get_restore_response(domain, couch_user, app_id=None, since=None, version='1.0',
                         state=None, items=False, force_cache=False,
                         cache_timeout=None, overwrite_cache=False,
                         force_restore_mode=None):
    # not a view just a view util
    if not couch_user.is_commcare_user():
        return HttpResponse("No linked chw found for %s" % couch_user.username,
                            status=401)  # Authentication Failure
    elif domain != couch_user.domain:
        return HttpResponse("%s was not in the domain %s" % (couch_user.username, domain),
                            status=401)

    project = Domain.get_by_name(domain)
    app = get_app(domain, app_id) if app_id else None
    restore_config = RestoreConfig(
        project=project,
        user=couch_user.to_casexml_user(),
        params=RestoreParams(
            sync_log_id=since,
            version=version,
            state_hash=state,
            include_item_count=items,
            force_restore_mode=force_restore_mode,
            app=app,
        ),
        cache_settings=RestoreCacheSettings(
            force_cache=force_cache,
            cache_timeout=cache_timeout,
            overwrite_cache=overwrite_cache
        ),
    )
    return restore_config.get_response()
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:34,代码来源:views.py

示例2: generate_restore_response

# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_response [as 别名]
def generate_restore_response(project, user, restore_id="", version=V1, state_hash="", items=False):
    config = RestoreConfig(
        project=project,
        user=user,
        params=RestoreParams(
            sync_log_id=restore_id,
            version=version,
            state_hash=state_hash,
            include_item_count=items
        )
    )
    return config.get_response()
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:14,代码来源:utils.py

示例3: get_restore_response

# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_response [as 别名]
def get_restore_response(domain, couch_user, since=None, version='1.0', state=None):
    # not a view just a view util
    if not couch_user.is_commcare_user():
        return HttpResponse("No linked chw found for %s" % couch_user.username,
                            status=401)  # Authentication Failure
    elif domain != couch_user.domain:
        return HttpResponse("%s was not in the domain %s" % (couch_user.username, domain),
                            status=401)

    project = Domain.get_by_name(domain)
    restore_config = RestoreConfig(
        couch_user.to_casexml_user(), since, version, state,
        caching_enabled=project.ota_restore_caching,
    )
    return restore_config.get_response()
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:17,代码来源:views.py

示例4: get_restore_response

# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_response [as 别名]
def get_restore_response(domain, couch_user, since=None, version='1.0',
                         state=None, items=False):
    # not a view just a view util
    if not couch_user.is_commcare_user():
        return HttpResponse("No linked chw found for %s" % couch_user.username,
                            status=401)  # Authentication Failure
    elif domain != couch_user.domain:
        return HttpResponse("%s was not in the domain %s" % (couch_user.username, domain),
                            status=401)

    project = Domain.get_by_name(domain)
    commtrack_settings = project.commtrack_settings
    stock_settings = commtrack_settings.get_ota_restore_settings() if commtrack_settings else None
    restore_config = RestoreConfig(
        couch_user.to_casexml_user(), since, version, state,
        items=items,
        stock_settings=stock_settings,
        domain=project
    )
    return restore_config.get_response()
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:22,代码来源:views.py

示例5: get_restore_response

# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_response [as 别名]
def get_restore_response(domain, couch_user, since=None, version='1.0',
                         state=None, items=False, force_cache=False,
                         cache_timeout=None, overwrite_cache=False):
    # not a view just a view util
    if not couch_user.is_commcare_user():
        return HttpResponse("No linked chw found for %s" % couch_user.username,
                            status=401)  # Authentication Failure
    elif domain != couch_user.domain:
        return HttpResponse("%s was not in the domain %s" % (couch_user.username, domain),
                            status=401)

    project = Domain.get_by_name(domain)
    restore_config = RestoreConfig(
        couch_user.to_casexml_user(), since, version, state,
        items=items,
        domain=project,
        force_cache=force_cache,
        cache_timeout=cache_timeout,
        overwrite_cache=overwrite_cache
    )
    return restore_config.get_response()
开发者ID:aristide,项目名称:commcare-hq,代码行数:23,代码来源:views.py

示例6: get_restore_response

# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_response [as 别名]
def get_restore_response(domain, couch_user, app_id=None, since=None, version='1.0',
                         state=None, items=False, force_cache=False,
                         cache_timeout=None, overwrite_cache=False,
                         as_user=None, device_id=None, user_id=None,
                         openrosa_version=None,
                         case_sync=None):
    """
    :param domain: Domain being restored from
    :param couch_user: User performing restore
    :param app_id: App ID of the app making the request
    :param since: ID of current sync log used to generate incremental sync
    :param version: Version of the sync response required
    :param state: Hash value of the current database of cases on the device for consistency checking
    :param items: Include item count if True
    :param force_cache: Force response to be cached
    :param cache_timeout: Override the default cache timeout of 1 hour.
    :param overwrite_cache: Ignore cached response if True
    :param as_user: Username of user to generate restore for (if different from current user)
    :param device_id: ID of device performing restore
    :param user_id: ID of user performing restore (used in case of deleted user with same username)
    :param openrosa_version:
    :param case_sync: Override default case sync algorithm
    :return: Tuple of (http response, timing context or None)
    """

    if user_id and user_id != couch_user.user_id:
        # sync with a user that has been deleted but a new
        # user was created with the same username and password
        from couchforms.openrosa_response import get_simple_response_xml
        from couchforms.openrosa_response import ResponseNature
        response = get_simple_response_xml(
            'Attempt to sync with invalid user.',
            ResponseNature.OTA_RESTORE_ERROR
        )
        return HttpResponse(response, content_type="text/xml; charset=utf-8", status=412), None

    is_demo_restore = couch_user.is_commcare_user() and couch_user.is_demo_user
    if is_demo_restore:
        # if user is in demo-mode, return demo restore
        return demo_user_restore_response(couch_user), None

    uses_login_as = bool(as_user)
    as_user_obj = CouchUser.get_by_username(as_user) if uses_login_as else None
    if uses_login_as and not as_user_obj:
        msg = _('Invalid restore as user {}').format(as_user)
        return HttpResponse(msg, status=401), None
    is_permitted, message = is_permitted_to_restore(
        domain,
        couch_user,
        as_user_obj,
    )
    if not is_permitted:
        return HttpResponse(message, status=401), None

    restore_user = get_restore_user(domain, couch_user, as_user_obj)
    if not restore_user:
        return HttpResponse('Could not find user', status=404), None

    project = Domain.get_by_name(domain)
    async_restore_enabled = (
        toggles.ASYNC_RESTORE.enabled(domain)
        and openrosa_version
        and LooseVersion(openrosa_version) >= LooseVersion(OPENROSA_VERSION_MAP['ASYNC_RESTORE'])
    )

    app = get_app_cached(domain, app_id) if app_id else None
    restore_config = RestoreConfig(
        project=project,
        restore_user=restore_user,
        params=RestoreParams(
            sync_log_id=since,
            version=version,
            state_hash=state,
            include_item_count=items,
            app=app,
            device_id=device_id,
            openrosa_version=openrosa_version,
        ),
        cache_settings=RestoreCacheSettings(
            force_cache=force_cache or async_restore_enabled,
            cache_timeout=cache_timeout,
            overwrite_cache=overwrite_cache
        ),
        is_async=async_restore_enabled,
        case_sync=case_sync,
    )
    return restore_config.get_response(), restore_config.timing_context
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:89,代码来源:views.py

示例7: generate_restore_response

# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_response [as 别名]
def generate_restore_response(user, restore_id="", version=V1, state_hash="",
                              items=False):
    config = RestoreConfig(user, restore_id, version, state_hash, items=items)
    return config.get_response()
开发者ID:aristide,项目名称:commcare-hq,代码行数:6,代码来源:utils.py


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