コード例 #1
0
ファイル: views.py プロジェクト: MichaelKohler/bedrock
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
0
ファイル: views.py プロジェクト: josiah2595/bedrock
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
0
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})
コード例 #4
0
ファイル: views.py プロジェクト: NIRVIT/bedrock
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})
コード例 #5
0
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})
コード例 #6
0
ファイル: views.py プロジェクト: LinuzLuzas/bedrock
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})