Example #1
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})
Example #2
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})
Example #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})
Example #4
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.android.sms-thankyou'))
    return l10n_utils.render(request, 'firefox/android/sms-send.html',
                             {'sms_form': form})
Example #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})
Example #6
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_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})