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


Python util.get_download_context函数代码示例

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


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

示例1: user_upload_job_poll

def user_upload_job_poll(request, domain, download_id, template="users/mobile/partials/user_upload_status.html"):
    try:
        context = get_download_context(download_id, check_state=True)
    except TaskFailedError:
        return HttpResponseServerError()

    context.update(
        {"on_complete_short": _("Bulk upload complete."), "on_complete_long": _("Mobile Worker upload has finished")}
    )

    class _BulkUploadResponseWrapper(object):
        def __init__(self, context):
            results = context.get("result", defaultdict(lambda: []))
            self.response_rows = results["rows"]
            self.response_errors = results["errors"]
            self.problem_rows = [r for r in self.response_rows if r["flag"] not in ("updated", "created")]

        def success_count(self):
            return len(self.response_rows) - len(self.problem_rows)

        def has_errors(self):
            return bool(self.response_errors or self.problem_rows)

        def errors(self):
            errors = []
            for row in self.problem_rows:
                if row["flag"] == "missing-data":
                    errors.append(_("A row with no username was skipped"))
                else:
                    errors.append(u"{username}: {flag}".format(**row))
            errors.extend(self.response_errors)
            return errors

    context["result"] = _BulkUploadResponseWrapper(context)
    return render(request, template, context)
开发者ID:idiene,项目名称:commcare-hq,代码行数:35,代码来源:users.py

示例2: poll_custom_export_download

 def poll_custom_export_download(self, in_data):
     """Polls celery to see how the export download task is going.
     :param in_data: dict passed by the  angular js controller.
     :return: final response: {
         'success': True,
         'dropbox_url': '<url>',
         'download_url: '<url>',
         <task info>
     }
     """
     try:
         download_id = in_data["download_id"]
     except KeyError:
         return format_angular_error(_("Requires a download id"))
     try:
         context = get_download_context(download_id, check_state=True)
     except TaskFailedError:
         return format_angular_error(
             _("Download Task Failed to Start. It seems that the server " "might be under maintenance.")
         )
     if context.get("is_ready", False):
         context.update(
             {
                 "dropbox_url": reverse("dropbox_upload", args=(download_id,)),
                 "download_url": "{}?get_file".format(reverse("retrieve_download", args=(download_id,))),
             }
         )
     context["is_poll_successful"] = True
     return context
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:29,代码来源:views.py

示例3: ajax_job_poll

def ajax_job_poll(request, download_id, template="soil/partials/dl_status.html"):
    try:
        context = get_download_context(download_id, check_state=True)
    except TaskFailedError as e:
        context = {'error': list(e)}
        return HttpResponseServerError(render(request, template, context))
    return render(request, template, context)
开发者ID:dimagi,项目名称:django-soil,代码行数:7,代码来源:views.py

示例4: user_upload_job_poll

def user_upload_job_poll(request, domain, download_id, template="users/mobile/partials/user_upload_status.html"):
    context = get_download_context(download_id, check_state=True)
    context.update({
        'on_complete_short': _('Bulk upload complete.'),
        'on_complete_long': _('Mobile Worker upload has finished'),

    })
    class _BulkUploadResponseWrapper(object):
        def __init__(self, context):
            results = context.get('result', defaultdict(lambda: []))
            self.response_rows = results['rows']
            self.response_errors = results['errors']
            self.problem_rows = [r for r in self.response_rows if r['flag'] not in ('updated', 'created')]

        def success_count(self):
            return len(self.response_rows) - len(self.problem_rows)

        def has_errors(self):
            return bool(self.response_errors or self.problem_rows)

        def errors(self):
            errors = []
            for row in self.problem_rows:
                if row['flag'] == 'missing-data':
                    errors.append(_('A row with no username was skipped'))
                else:
                    errors.append('{username}: {flag}'.format(**row))
            errors.extend(self.response_errors)
            return errors

    context['result'] = _BulkUploadResponseWrapper(context)
    return render(request, template, context)
开发者ID:kkaczmarczyk,项目名称:commcare-hq,代码行数:32,代码来源:users.py

示例5: user_download_job_poll

def user_download_job_poll(request, domain, download_id, template="hqwebapp/partials/shared_download_status.html"):
    try:
        context = get_download_context(download_id, 'Preparing download')
        context.update({'link_text': _('Download Users')})
    except TaskFailedError as e:
        return HttpResponseServerError(e.errors)
    return render(request, template, context)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:7,代码来源:users.py

示例6: fixture_upload_job_poll

def fixture_upload_job_poll(request, domain, download_id, template="fixtures/partials/fixture_upload_status.html"):
    context = get_download_context(download_id, check_state=True)
    context.update({
        'on_complete_short': _('Upload complete.'),
        'on_complete_long': _('Lookup table upload has finished'),

    })
    return render(request, template, context)
开发者ID:dslowikowski,项目名称:commcare-hq,代码行数:8,代码来源:views.py

示例7: product_importer_job_poll

def product_importer_job_poll(request, domain, download_id, template="hqwebapp/partials/download_status.html"):
    context = get_download_context(download_id, check_state=True)
    context.update({
        'on_complete_short': _('Import complete.'),
        'on_complete_long': _('Product importing has finished'),

    })
    return render(request, template, context)
开发者ID:thedevelopermw,项目名称:commcare-hq,代码行数:8,代码来源:views.py

示例8: ajax_job_poll

def ajax_job_poll(request, download_id, template="soil/partials/bootstrap2/dl_status.html"):
    message = request.GET['message'] if 'message' in request.GET else None
    is_bootstrap3 = request.GET.get('is_bootstrap3', 'false') == 'true'
    template = 'soil/partials/bootstrap3/dl_status.html' if is_bootstrap3 else template
    try:
        context = get_download_context(download_id, check_state=True, message=message)
    except TaskFailedError as e:
        context = {'error': list(e.errors) if e.errors else [_("An error occurred during the download.")]}
        return HttpResponseServerError(render(request, template, context))
    return render(request, template, context)
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:10,代码来源:views.py

示例9: fixture_upload_job_poll

def fixture_upload_job_poll(request, domain, download_id, template="fixtures/partials/fixture_upload_status.html"):
    try:
        context = get_download_context(download_id, check_state=True)
    except TaskFailedError:
        return HttpResponseServerError()

    context.update({
        'on_complete_short': _('Upload complete.'),
        'on_complete_long': _('Lookup table upload has finished'),

    })
    return render(request, template, context)
开发者ID:aristide,项目名称:commcare-hq,代码行数:12,代码来源:views.py

示例10: location_importer_job_poll

def location_importer_job_poll(request, domain, download_id, template="hqwebapp/partials/download_status.html"):
    try:
        context = get_download_context(download_id, check_state=True)
    except TaskFailedError:
        return HttpResponseServerError()

    context.update({
        'on_complete_short': _('Import complete.'),
        'on_complete_long': _('Location importing has finished'),

    })
    return render(request, template, context)
开发者ID:puttarajubr,项目名称:commcare-hq,代码行数:12,代码来源:views.py

示例11: product_importer_job_poll

def product_importer_job_poll(
    request, domain, download_id, template="products/manage/partials/product_upload_status.html"
):
    try:
        context = get_download_context(download_id, check_state=True)
    except TaskFailedError:
        return HttpResponseServerError()

    context.update(
        {"on_complete_short": _("Import complete."), "on_complete_long": _("Product importing has finished")}
    )
    return render(request, template, context)
开发者ID:sheelio,项目名称:commcare-hq,代码行数:12,代码来源:views.py

示例12: location_importer_job_poll

def location_importer_job_poll(request, domain, download_id):
    template = "locations/manage/partials/locations_upload_status.html"
    try:
        context = get_download_context(download_id)
    except TaskFailedError:
        return HttpResponseServerError()

    context.update({
        'on_complete_short': _('Import complete.'),
        'on_complete_long': _('Organization Structure importing has finished'),

    })
    return render(request, template, context)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:13,代码来源:views.py

示例13: ucr_download_job_poll

def ucr_download_job_poll(request, domain,
                          download_id,
                          template="hqwebapp/partials/shared_download_status.html"):
    config_id = request.GET.get('config_id')
    if config_id and _has_permission(domain, request.couch_user, config_id):
        try:
            context = get_download_context(download_id, 'Preparing download')
            context.update({'link_text': _('Download Report')})
        except TaskFailedError as e:
            return HttpResponseServerError(e.errors)
        return render(request, template, context)
    else:
        raise Http403()
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:13,代码来源:view.py

示例14: xform_management_job_poll

def xform_management_job_poll(request, domain, download_id,
                              template="data_interfaces/partials/xform_management_status.html"):
    mode = FormManagementMode(request.GET.get('mode'), validate=True)
    try:
        context = get_download_context(download_id, check_state=True)
    except TaskFailedError:
        return HttpResponseServerError()

    context.update({
        'on_complete_short': mode.complete_short,
        'mode': mode,
        'form_management_url': reverse(EditDataInterfaceDispatcher.name(),
                                       args=[domain, BulkFormManagementInterface.slug])
    })
    return render(request, template, context)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:15,代码来源:views.py

示例15: pending_location_import_download_id

def pending_location_import_download_id(domain):
    # Check if there is an unfinished import_locations_async
    # If the task is pending returns download_id of the task else returns False
    key = import_locations_task_key(domain)
    download_id = cache.get(key)
    if download_id:
        try:
            context = get_download_context(download_id)
        except TaskFailedError:
            return False
        if context['is_ready']:
            return False
        else:
            # task hasn't finished
            return download_id
    else:
        return False
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:17,代码来源:views.py


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