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


Python forms.trap_duplicate函数代码示例

本文整理汇总了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))
开发者ID:bearstech,项目名称:zamboni,代码行数:26,代码来源:views.py

示例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))
开发者ID:ngokevin,项目名称:zamboni,代码行数:28,代码来源:views.py


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