Beispiel #1
0
def mobile_stable_feedback(request):
    form = ResponseForm()
    happy = None

    if request.method == 'POST':
        response, form = _handle_feedback_post(request)
        if response:
            return response
        happy = smart_bool(request.POST.get('happy', None), None)

    return render(request, 'feedback/mobile/feedback.html', {
        'form': form,
        'happy': happy,
    })
Beispiel #2
0
def mobile_stable_feedback(request):
    form = ResponseForm()
    happy = None

    if request.method == 'POST':
        response, form = _handle_feedback_post(request)
        if response:
            return response
        happy = smart_bool(request.POST.get('happy', None), None)

    return render(request, 'feedback/mobile/feedback.html', {
        'form': form,
        'happy': happy,
    })
Beispiel #3
0
def mobile_stable_feedback(request, locale=None, product=None,
                           version=None, channel=None):
    form = ResponseForm()
    happy = None

    if request.method == 'POST':
        response, form = _handle_feedback_post(
            request, locale, product, version, channel)
        if response:
            return response
        happy = smart_bool(request.POST.get('happy', None), None)

    return render(request, 'feedback/mobile/feedback.html', {
        'form': form,
        'happy': happy,
    })
Beispiel #4
0
def desktop_stable_feedback(request, template=None):
    # Use two instances of the same form because the template changes the text
    # based on the value of ``happy``.
    forms = {"happy": SimpleForm(initial={"happy": 1}), "sad": SimpleForm(initial={"happy": 0})}

    if request.method == "POST":
        form = SimpleForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            # Most platforms aren't different enough between versions to care.
            # Windows is.
            platform = request.BROWSER.platform
            if platform == "Windows":
                platform += " " + request.BROWSER.platform_version

            opinion = models.Simple(
                # Data coming from the user
                happy=data["happy"],
                url=data["url"],
                description=data["description"],
                # Inferred data
                prodchan="firefox.desktop.stable",
                user_agent=request.META.get("HTTP_USER_AGENT", ""),
                browser=request.BROWSER.browser,
                browser_version=request.BROWSER.browser_version,
                platform=platform,
                locale=request.locale,
            )
            opinion.save()

            if data["email_ok"] and data["email"]:
                e = models.SimpleEmail(email=data["email"], opinion=opinion)
                e.save()

            return HttpResponseRedirect(reverse("thanks"))
        else:
            # The user did something wrong. Update the appropriate form, so
            # the errors show correctly.
            happy = smart_bool(request.POST.get("happy", None))
            if happy:
                forms["happy"] = form
            else:
                forms["sad"] = form

    return render(request, "feedback/feedback.html", {"forms": forms})
Beispiel #5
0
def desktop_stable_feedback(request):
    # Use two instances of the same form because the template changes the text
    # based on the value of ``happy``.
    forms = {
        'happy': ResponseForm(initial={'happy': 1}),
        'sad': ResponseForm(initial={'happy': 0}),
    }

    if request.method == 'POST':
        response, form = _handle_feedback_post(request)
        if response:
            return response

        happy = smart_bool(request.POST.get('happy', None))
        if happy:
            forms['happy'] = form
        else:
            forms['sad'] = form

    return render(request, 'feedback/feedback.html', {'forms': forms})
Beispiel #6
0
def desktop_stable_feedback(request):
    # Use two instances of the same form because the template changes the text
    # based on the value of ``happy``.
    forms = {
        'happy': ResponseForm(initial={'happy': 1}),
        'sad': ResponseForm(initial={'happy': 0}),
    }

    if request.method == 'POST':
        response, form = _handle_feedback_post(request)
        if response:
            return response

        happy = smart_bool(request.POST.get('happy', None))
        if happy:
            forms['happy'] = form
        else:
            forms['sad'] = form

    return render(request, 'feedback/feedback.html', {'forms': forms})
Beispiel #7
0
 def test_falsey(self):
     falses = ['No', 'n', u'FALSE', '0', u'0']
     for x in falses:
         b = smart_bool(x, 'fallback')
         assert b is False, self.msg_template % (x, False, b)
Beispiel #8
0
 def test_truthy(self):
     truths = ['Yes', 'y', u'TRUE', '1', u'1']
     for x in truths:
         b = smart_bool(x, 'fallback')
         assert b is True, self.msg_template % (x, True, b)
Beispiel #9
0
 def test_fallback(self):
     garbages = [None, 'apple', u'']
     for x in garbages:
         b = smart_bool(x, 'fallback')
         assert b == 'fallback', self.msg_template % (x, 'fallback', b)
Beispiel #10
0
 def test_fallback(self):
     garbages = [None, 'apple', u'']
     for x in garbages:
         b = smart_bool(x, 'fallback')
         assert b == 'fallback', self.msg_template % (x, 'fallback', b)
Beispiel #11
0
 def test_falsey(self):
     falses = ['No', 'n', u'FALSE', '0', u'0']
     for x in falses:
         b = smart_bool(x, 'fallback')
         assert b == False, self.msg_template % (x, False, b)
Beispiel #12
0
 def test_truthy(self):
     truths = ['Yes', 'y', u'TRUE', '1', u'1']
     for x in truths:
         b = smart_bool(x, 'fallback')
         assert b == True, self.msg_template % (x, True, b)