本文整理汇总了Python中bedrock.firefox.forms.SMSSendForm类的典型用法代码示例。如果您正苦于以下问题:Python SMSSendForm类的具体用法?Python SMSSendForm怎么用?Python SMSSendForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SMSSendForm类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sms_send
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})
示例2: sms_send
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})
示例3: sms_send
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})
示例4: sms_send
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})