本文整理汇总了Python中mkt.developers.forms.trap_duplicate函数的典型用法代码示例。如果您正苦于以下问题:Python trap_duplicate函数的具体用法?Python trap_duplicate怎么用?Python trap_duplicate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了trap_duplicate函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _upload_manifest
def _upload_manifest(request, is_standalone=False):
form = forms.NewManifestForm(request.POST, is_standalone=is_standalone)
if (not is_standalone and
waffle.switch_is_active('webapps-unique-by-domain')):
# Helpful error if user already submitted the same manifest.
dup_msg = trap_duplicate(request, request.POST.get('manifest'))
if dup_msg:
return {'validation': {'errors': 1, 'success': False,
'messages': [{'type': 'error', 'message': dup_msg,
'tier': 1}]}}
if form.is_valid():
upload = FileUpload.objects.create()
tasks.fetch_manifest.delay(form.cleaned_data['manifest'], upload.pk)
if is_standalone:
return redirect('mkt.developers.standalone_upload_detail',
'hosted', upload.pk)
else:
return redirect('mkt.developers.upload_detail', upload.pk, 'json')
else:
error_text = _('There was an error with the submission.')
if 'manifest' in form.errors:
error_text = ' '.join(form.errors['manifest'])
error_message = {'type': 'error', 'message': error_text, 'tier': 1}
v = {'errors': 1, 'success': False, 'messages': [error_message]}
return make_validation_result(dict(validation=v, error=error_text))
示例2: _upload_manifest
def _upload_manifest(request, is_standalone=False):
form = forms.NewManifestForm(request.POST, is_standalone=is_standalone)
if not is_standalone and waffle.switch_is_active("webapps-unique-by-domain"):
# Helpful error if user already submitted the same manifest.
dup_msg = trap_duplicate(request, request.POST.get("manifest"))
if dup_msg:
return {
"validation": {
"errors": 1,
"success": False,
"messages": [{"type": "error", "message": dup_msg, "tier": 1}],
}
}
if form.is_valid():
upload = FileUpload.objects.create(user=request.user)
fetch_manifest.delay(form.cleaned_data["manifest"], upload.pk)
if is_standalone:
return redirect("mkt.developers.standalone_upload_detail", "hosted", upload.pk)
else:
return redirect("mkt.developers.upload_detail", upload.pk, "json")
else:
error_text = _("There was an error with the submission.")
if "manifest" in form.errors:
error_text = " ".join(form.errors["manifest"])
error_message = {"type": "error", "message": error_text, "tier": 1}
v = {"errors": 1, "success": False, "messages": [error_message]}
return make_validation_result(dict(validation=v, error=error_text))