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


Python DownloadBase.get方法代码示例

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


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

示例1: location_importer_job_poll

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [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: bulk_import_async

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def bulk_import_async(import_id, config, domain, excel_id):
    excel_ref = DownloadBase.get(excel_id)
    spreadsheet = importer_util.get_spreadsheet(excel_ref, config.named_columns)
    result = do_import(spreadsheet, config, domain, task=bulk_import_async)

    # return compatible with soil
    return {"messages": result}
开发者ID:nnestle,项目名称:commcare-hq,代码行数:9,代码来源:tasks.py

示例3: get_download_context

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def get_download_context(download_id, message=None, require_result=False):
    """
    :param require_result: If set to True, is_ready will not be set to True unless result is
    also available. If check_state=False, this is ignored.
    """
    download_data = DownloadBase.get(download_id)
    if download_data is None:
        download_data = DownloadBase(download_id=download_id)

    task = download_data.task

    task_status = get_task_status(
        task, is_multiple_download_task=isinstance(download_data, MultipleTaskDownload))
    if task_status.failed():
        raise TaskFailedError(task_status.error)
    if require_result:
        is_ready = task_status.success() and task_status.result is not None
    else:
        is_ready = task_status.success()

    return {
        'result': task_status.result,
        'error': task_status.error,
        'is_ready': is_ready,
        'is_alive': is_alive() if heartbeat_enabled() else True,
        'progress': task_status.progress._asdict(),
        'download_id': download_id,
        'allow_dropbox_sync': isinstance(download_data, FileDownload) and download_data.use_transfer,
        'has_file': download_data is not None and download_data.has_file,
        'custom_message': message,
    }
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:33,代码来源:util.py

示例4: get_download_context

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def get_download_context(download_id, message=None, require_result=False):
    """
    :param require_result: If set to True, is_ready will not be set to True unless result is
    also available. If check_state=False, this is ignored.
    """
    download_data = DownloadBase.get(download_id)
    if download_data is None:
        download_data = DownloadBase(download_id=download_id)

    task = download_data.task

    task_status = get_task_status(
        task, is_multiple_download_task=isinstance(download_data, MultipleTaskDownload))
    if task_status.failed():
        # Celery replaces exceptions with a wrapped one that we can't directly import
        # so I think our best choice is to match off the name, even though that's hacky
        exception_name = (task.result.__class__.__name__
                          if isinstance(task.result, Exception) else None)
        raise TaskFailedError(task_status.error, exception_name=exception_name)
    if require_result:
        is_ready = task_status.success() and task_status.result is not None
    else:
        is_ready = task_status.success()

    return {
        'result': task_status.result,
        'error': task_status.error,
        'is_ready': is_ready,
        'is_alive': is_alive() if heartbeat_enabled() else True,
        'progress': task_status.progress._asdict(),
        'download_id': download_id,
        'allow_dropbox_sync': isinstance(download_data, FileDownload) and download_data.use_transfer,
        'has_file': download_data is not None and download_data.has_file,
        'custom_message': message,
    }
开发者ID:dimagi,项目名称:commcare-hq,代码行数:37,代码来源:util.py

示例5: fixture_upload_async

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def fixture_upload_async(domain, download_id, replace):
    task = fixture_upload_async
    DownloadBase.set_progress(task, 0, 100)
    download_ref = DownloadBase.get(download_id)
    result = upload_fixture_file(domain, download_ref.get_filename(), replace, task)
    DownloadBase.set_progress(task, 100, 100)
    return {"messages": result}
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:tasks.py

示例6: import_products_async

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def import_products_async(domain, file_ref_id):
    task = import_products_async
    DownloadBase.set_progress(task, 0, 100)
    download_ref = DownloadBase.get(file_ref_id)
    results = import_products(domain, download_ref, task)
    DownloadBase.set_progress(task, 100, 100)
    return {
        'messages': results
    }
开发者ID:NoahCarnahan,项目名称:commcare-hq,代码行数:11,代码来源:tasks.py

示例7: fixture_upload_async

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def fixture_upload_async(domain, download_id, replace):
    task = fixture_upload_async
    DownloadBase.set_progress(task, 0, 100)
    download_ref = DownloadBase.get(download_id)
    result = safe_fixture_upload(domain, download_ref, replace, task)
    DownloadBase.set_progress(task, 100, 100)
    return {
        'messages': result,
    }
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:11,代码来源:tasks.py

示例8: __init__

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
    def __init__(self, task, file_ref_id):
        self.task = task
        self.progress = 0

        if self.task:
            DownloadBase.set_progress(self.task, 0, 100)

        download_ref = DownloadBase.get(file_ref_id)
        self.workbook = WorkbookJSONReader(download_ref.get_filename())
开发者ID:inmagik,项目名称:dimagi-utils,代码行数:11,代码来源:excel_importer.py

示例9: import_stock_reports_async

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def import_stock_reports_async(download_id, domain, file_ref_id):
    """
    Same idea but for stock reports
    """
    download_ref = DownloadBase.get(file_ref_id)
    with open(download_ref.get_filename(), 'rb') as f:
        try:
            results = import_stock_reports(domain, f)
        except Exception, e:
            results = "ERROR: %s" % e
开发者ID:comm-scriptek,项目名称:commcare-hq,代码行数:12,代码来源:tasks.py

示例10: __init__

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
    def __init__(self, task, file_ref_id):
        self.task = task
        self.progress = 0

        if self.task:
            DownloadBase.set_progress(self.task, 0, 100)

        download_ref = DownloadBase.get(file_ref_id)
        if download_ref is None:
            raise UnknownFileRefException("Could not find file wih ref %s. It may have expired" % file_ref_id)
        self.workbook = WorkbookJSONReader(download_ref.get_filename())
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:13,代码来源:excel_importer.py

示例11: import_locations_async

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def import_locations_async(download_id, domain, file_ref_id, update_existing=False):
    """
    Asynchronously import locations. download_id is for showing
    the results to the user through soil. file_ref_id is also a
    download_id, but should be a pointer to the import file.
    """
    download_ref = DownloadBase.get(file_ref_id)
    with open(download_ref.get_filename(), 'rb') as f:
        results_msg = '\n'.join(import_locations(domain, f, update_existing))
    ref = expose_download(results_msg, 60*60*3)
    cache.set(download_id, ref)
开发者ID:comm-scriptek,项目名称:commcare-hq,代码行数:13,代码来源:tasks.py

示例12: bulk_import_async

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def bulk_import_async(import_id, config, domain, excel_id):
    excel_ref = DownloadBase.get(excel_id)
    try:
        spreadsheet_or_error = importer_util.get_spreadsheet(excel_ref, config.named_columns)
    except ImporterError as spreadsheet_or_error:
        pass

    result = do_import(spreadsheet_or_error, config, domain, task=bulk_import_async)

    # return compatible with soil
    return {"messages": result}
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:13,代码来源:tasks.py

示例13: excel_commit

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def excel_commit(request, domain):
    """
    Step three of three.

    This page is submitted with the list of column to
    case property mappings for this upload.

    The config variable is an ImporterConfig object that
    has everything gathered from previous steps, with the
    addition of all the field data. See that class for
    more information.
    """
    config = importer_util.ImporterConfig.from_request(request)

    excel_id = request.session.get(EXCEL_SESSION_ID)

    excel_ref = DownloadBase.get(excel_id)
    spreadsheet = importer_util.get_spreadsheet(excel_ref, config.named_columns)

    if not spreadsheet:
        return _spreadsheet_expired(request, domain)

    if spreadsheet.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")

    download = DownloadBase()
    download.set_task(bulk_import_async.delay(
        download.download_id,
        config,
        domain,
        excel_id,
    ))

    try:
        del request.session[EXCEL_SESSION_ID]
    except KeyError:
        pass

    return render(
        request,
        "importer/excel_commit.html", {
            'download_id': download.download_id,
            'template': 'importer/partials/import_status.html',
            'domain': domain,
            'report': {
                'name': 'Import: Completed'
            },
            'slug': base.ImportCases.slug
        }
    )
开发者ID:johan--,项目名称:commcare-hq,代码行数:55,代码来源:views.py

示例14: import_locations_async

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [as 别名]
def import_locations_async(domain, file_ref_id):
    task = import_locations_async

    DownloadBase.set_progress(task, 0, 100)
    download_ref = DownloadBase.get(file_ref_id)
    workbook = WorkbookJSONReader(download_ref.get_filename())
    worksheets = workbook.worksheets

    results = list(import_locations(domain, worksheets, task))

    DownloadBase.set_progress(task, 100, 100)

    return {
        'messages': results
    }
开发者ID:NoahCarnahan,项目名称:commcare-hq,代码行数:17,代码来源:tasks.py

示例15: get_download_context

# 需要导入模块: from soil import DownloadBase [as 别名]
# 或者: from soil.DownloadBase import get [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


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