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


Python SMSSendForm.is_valid方法代码示例

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


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

示例1: sms_send

# 需要导入模块: from bedrock.firefox.forms import SMSSendForm [as 别名]
# 或者: from bedrock.firefox.forms.SMSSendForm import is_valid [as 别名]
def sms_send(request):
    form = SMSSendForm(request.POST or None)
    if request.method == "POST":
        error_msg = _("An error occurred in our system. Please try again later.")
        error = None
        if form.is_valid():
            try:
                basket.send_sms(form.cleaned_data["number"], SMS_MESSAGES["android"], form.cleaned_data["optin"])
            except basket.BasketException:
                error = error_msg

        else:
            number_errors = form.errors.get("number")
            if number_errors:
                # form error messages may contain unsanitized user input
                error = escape(number_errors[0])
            else:
                error = error_msg

        if request.is_ajax():
            # return JSON
            if error:
                resp = {"success": False, "error": error}
            else:
                resp = {"success": True}

            return HttpResponseJSON(resp)
        else:
            if error:
                form.errors["__all__"] = form.error_class([error])
            else:
                return HttpResponseRedirect(reverse("firefox.android.sms-thankyou"))

    return l10n_utils.render(request, "firefox/android/sms-send.html", {"sms_form": form})
开发者ID:MichaelKohler,项目名称:bedrock,代码行数:36,代码来源:views.py

示例2: sms_send

# 需要导入模块: from bedrock.firefox.forms import SMSSendForm [as 别名]
# 或者: from bedrock.firefox.forms.SMSSendForm import is_valid [as 别名]
def sms_send(request):
    form = SMSSendForm(request.POST or None)
    if request.method == "POST" and form.is_valid():
        try:
            basket.send_sms(form.cleaned_data["number"], "SMS_Android", form.cleaned_data["optin"])
        except basket.BasketException:
            msg = form.error_class([_("An error occurred in our system. " "Please try again later.")])
            form.errors["__all__"] = msg
        else:
            return HttpResponseRedirect(reverse("firefox.mobile.sms-thankyou"))
    return l10n_utils.render(request, "firefox/mobile/sms-send.html", {"sms_form": form})
开发者ID:josiah2595,项目名称:bedrock,代码行数:13,代码来源:views.py

示例3: sms_send

# 需要导入模块: from bedrock.firefox.forms import SMSSendForm [as 别名]
# 或者: from bedrock.firefox.forms.SMSSendForm import is_valid [as 别名]
def sms_send(request):
    form = SMSSendForm(request.POST or None)
    if request.method == 'POST' and form.is_valid():
        try:
            basket.send_sms(form.cleaned_data['number'],
                            'SMS_Android',
                            form.cleaned_data['optin'])
        except basket.BasketException:
            msg = form.error_class(
                [_('An error occurred in our system. '
                   'Please try again later.')]
            )
            form.errors['__all__'] = msg
        else:
            return HttpResponseRedirect(
                reverse('firefox.android.sms-thankyou'))
    return l10n_utils.render(request, 'firefox/android/sms-send.html',
                             {'sms_form': form})
开发者ID:NIRVIT,项目名称:bedrock,代码行数:20,代码来源:views.py

示例4: sms_send

# 需要导入模块: from bedrock.firefox.forms import SMSSendForm [as 别名]
# 或者: from bedrock.firefox.forms.SMSSendForm import is_valid [as 别名]
def sms_send(request):
    form = SMSSendForm(request.POST or None)
    if request.method == 'POST':
        error_msg = _('An error occurred in our system. Please try again later.')
        error = None
        if form.is_valid():
            try:
                basket.send_sms(form.cleaned_data['number'],
                                'SMS_Android',
                                form.cleaned_data['optin'])
            except basket.BasketException:
                error = error_msg

        else:
            number_errors = form.errors.get('number')
            if number_errors:
                # form error messages may contain unsanitized user input
                error = escape(number_errors[0])
            else:
                error = error_msg

        if request.is_ajax():
            # return JSON
            if error:
                resp = {
                    'success': False,
                    'error': error,
                }
            else:
                resp = {'success': True}

            return HttpResponseJSON(resp)
        else:
            if error:
                form.errors['__all__'] = form.error_class([error])
            else:
                return HttpResponseRedirect(reverse('firefox.android.sms-thankyou'))

    return l10n_utils.render(request, 'firefox/android/sms-send.html',
                             {'sms_form': form})
开发者ID:LinuzLuzas,项目名称:bedrock,代码行数:42,代码来源:views.py


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