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


Python DownloadBase.get_progress方法代码示例

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


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

示例1: location_importer_job_poll

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get_progress [as 别名]
def location_importer_job_poll(request, domain, download_id, template="locations/manage/partials/status.html"):
    download_data = DownloadBase.get(download_id)
    is_ready = False

    if download_data is None:
        download_data = DownloadBase(download_id=download_id)
        try:
            if download_data.task.failed():
                return HttpResponseServerError()
        except (TypeError, NotImplementedError):
            # no result backend / improperly configured
            pass

    alive = True
    if heartbeat_enabled():
        alive = is_alive()

    context = RequestContext(request)

    if download_data.task.state == 'SUCCESS':
        is_ready = True
        context['result'] = download_data.task.result.get('messages')

    context['is_ready'] = is_ready
    context['is_alive'] = alive
    context['progress'] = download_data.get_progress()
    context['download_id'] = download_id
    return render_to_response(template, context_instance=context)
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:30,代码来源:views.py

示例2: get_download_context

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get_progress [as 别名]
def get_download_context(download_id, check_state=False, message=None):
    is_ready = False
    context = {}
    download_data = DownloadBase.get(download_id)
    context['has_file'] = download_data is not None and download_data.has_file
    if download_data is None:
        download_data = DownloadBase(download_id=download_id)

    if isinstance(download_data, MultipleTaskDownload):
        if download_data.task.ready():
            context['result'], context['error'] = _get_download_context_multiple_tasks(download_data)
    else:
        try:
            if download_data.task.failed():
                raise TaskFailedError()
        except (TypeError, NotImplementedError):
            # no result backend / improperly configured
            pass
        else:
            if not check_state:
                is_ready = True
            elif download_data.task.successful():
                is_ready = True
                result = download_data.task.result
                context['result'] = result and result.get('messages')
                if result and result.get('errors'):
                    raise TaskFailedError(result.get('errors'))

    alive = True
    if heartbeat_enabled():
        alive = is_alive()

    progress = download_data.get_progress()

    def progress_complete():
        return (
            getattr(settings, 'CELERY_ALWAYS_EAGER', False) or
            progress.get('percent', 0) == 100 and
            not progress.get('error', False)
        )

    context['is_ready'] = is_ready or progress_complete()
    context['is_alive'] = alive
    context['progress'] = progress
    context['download_id'] = download_id
    context['allow_dropbox_sync'] = isinstance(download_data, FileDownload) and download_data.use_transfer
    context['custom_message'] = message
    return context
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:50,代码来源:util.py

示例3: get_download_context

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get_progress [as 别名]
def get_download_context(download_id, check_state=False):
    is_ready = False
    context = {}
    download_data = DownloadBase.get(download_id)
    context['has_file'] = bool(download_data)
    if download_data is None:
        download_data = DownloadBase(download_id=download_id)

    try:
        if download_data.task.failed():
            raise TaskFailedError()
    except (TypeError, NotImplementedError):
        # no result backend / improperly configured
        pass
    else:
        if not check_state:
            is_ready = True
        elif download_data.task.state == 'SUCCESS':
            is_ready = True
            result = download_data.task.result
            context['result'] = result and result.get('messages')
            if result and result.get('errors'):
                raise TaskFailedError(result.get('errors'))

    alive = True
    if heartbeat_enabled():
        alive = is_alive()

    progress = download_data.get_progress()

    def progress_complete():
        return (
            getattr(settings, 'CELERY_ALWAYS_EAGER', False) and
            progress.get('percent', 0) == 100 and
            not progress.get('error', False)
        )

    context['is_ready'] = is_ready or progress_complete()
    context['is_alive'] = alive
    context['progress'] = progress
    context['download_id'] = download_id
    return context
开发者ID:dimagi,项目名称:django-soil,代码行数:44,代码来源:util.py

示例4: importer_job_poll

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get_progress [as 别名]
def importer_job_poll(request, domain, download_id, template="importer/partials/import_status.html"):
    download_data = DownloadBase.get(download_id)
    is_ready = False

    if download_data is None:
        download_data = DownloadBase(download_id=download_id)
        try:
            if download_data.task.failed():
                return HttpResponseServerError()
        except (TypeError, NotImplementedError):
            # no result backend / improperly configured
            pass

    alive = True
    if heartbeat_enabled():
        alive = is_alive()

    context = RequestContext(request)

    if download_data.task.result and 'error' in download_data.task.result:
        error = download_data.task.result['error']
        if error == 'EXPIRED':
            return _spreadsheet_expired(request, domain)
        elif error == 'HAS_ERRORS':
            messages.error(request, _('The session containing the file you '
                                      'uploaded has expired - please upload '
                                      'a new one.'))
            return HttpResponseRedirect(base.ImportCases.get_url(domain=domain) + "?error=cache")

    if download_data.task.state == 'SUCCESS':
        is_ready = True
        context['result'] = download_data.task.result

    context['is_ready'] = is_ready
    context['is_alive'] = alive
    context['progress'] = download_data.get_progress()
    context['download_id'] = download_id
    context['url'] = base.ImportCases.get_url(domain=domain)
    return render_to_response(template, context_instance=context)
开发者ID:johan--,项目名称:commcare-hq,代码行数:41,代码来源:views.py


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