本文整理汇总了Python中soil.util.get_download_context函数的典型用法代码示例。如果您正苦于以下问题:Python get_download_context函数的具体用法?Python get_download_context怎么用?Python get_download_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_download_context函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: importer_job_poll
def importer_job_poll(request, domain, download_id, template="importer/partials/import_status.html"):
try:
download_context = get_download_context(download_id, check_state=True)
except TaskFailedError as e:
error = e.errors
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")
else:
context = RequestContext(request)
context.update(download_context)
context['url'] = base.ImportCases.get_url(domain=domain)
return render_to_response(template, context_instance=context)
开发者ID:nnestle,项目名称:commcare-hq,代码行数:17,代码来源:views.py
示例17: add_export_email_request
def add_export_email_request(request, domain):
download_id = request.POST.get('download_id')
user_id = request.couch_user.user_id
if download_id is None or user_id is None:
return HttpResponseBadRequest(ugettext_lazy('Download ID or User ID blank/not provided'))
try:
download_context = get_download_context(download_id)
except TaskFailedError:
return HttpResponseServerError(ugettext_lazy('Export failed'))
if download_context.get('is_ready', False):
try:
couch_user = CouchUser.get_by_user_id(user_id, domain=domain)
except CouchUser.AccountTypeError:
return HttpResponseBadRequest(ugettext_lazy('Invalid user'))
if couch_user is not None:
process_email_request(domain, download_id, couch_user.get_email())
else:
EmailExportWhenDoneRequest.objects.create(domain=domain, download_id=download_id, user_id=user_id)
return HttpResponse(ugettext_lazy('Export e-mail request sent.'))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:19,代码来源:download.py
示例18: poll_custom_export_download
def poll_custom_export_download(request, domain):
"""Polls celery to see how the export download task is going.
:return: final response: {
'success': True,
'dropbox_url': '<url>',
'download_url: '<url>',
<task info>
}
"""
form_or_case = request.GET.get('form_or_case')
permissions = ExportsPermissionsManager(form_or_case, domain, request.couch_user)
permissions.access_download_export_or_404()
download_id = request.GET.get('download_id')
try:
context = get_download_context(download_id)
except TaskFailedError as e:
if e.exception_name == 'XlsLengthException':
return JsonResponse({
'error': _(
'This file has more than 256 columns, which is not supported by xls. '
'Please change the output type to csv or xlsx to export this file.')
})
else:
notify_exception(
request, "Export download failed",
details={'download_id': download_id, 'errors': e.errors,
'exception_name': e.exception_name})
return JsonResponse({
'error': _("Download task failed to start."),
})
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 json_response(context)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:41,代码来源:download.py
示例19: importer_job_poll
def importer_job_poll(request, domain, download_id, template="importer/partials/import_status.html"):
try:
download_context = get_download_context(download_id, check_state=True)
except TaskFailedError as e:
# todo: this is async, so it's totally inappropriate to be using messages.error
# todo: and HttpResponseRedirect
error = e.errors
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.'))
else:
messages.error(request, _('Sorry something went wrong with that import. Please try again. '
'Report an issue if you continue to have problems.'))
return HttpResponseRedirect(base.ImportCases.get_url(domain=domain) + "?error=cache")
else:
context = RequestContext(request)
context.update(download_context)
context['url'] = base.ImportCases.get_url(domain=domain)
return render_to_response(template, context_instance=context)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:22,代码来源:views.py
注:本文中的soil.util.get_download_context函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论