Skip to content

Commit

Permalink
Merge pull request #2852 from mozilla/bug-1134414-ff37-whatsnew-page
Browse files Browse the repository at this point in the history
Bug 1134414 ff37 whatsnew page
  • Loading branch information
jgmize committed Mar 25, 2015
2 parents 4eba99b + b0d80ea commit 638397c
Show file tree
Hide file tree
Showing 18 changed files with 1,039 additions and 21 deletions.
2 changes: 2 additions & 0 deletions bedrock/firefox/forms.py
Expand Up @@ -8,6 +8,8 @@

from lib.l10n_utils.dotlang import _

LANG_FILES = ['firefox/whatsnew-fx37']


class SMSSendForm(forms.Form):
number = forms.CharField(max_length=14)
Expand Down
126 changes: 126 additions & 0 deletions bedrock/firefox/templates/firefox/whatsnew-fx37.html
@@ -0,0 +1,126 @@
{# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. -#}

{% extends "firefox/base-resp.html" %}

{% block extra_meta %}<meta name="robots" content="noindex">{% endblock %}

{#- This will appear as <meta property="og:title"> which can be used for social share -#}
{% block page_og_title %}
{{_('Choose the independent browser')}}
{% endblock %}

{#- This will appear as <meta property="og:description"> which can be used for social share -#}
{% block page_og_desc %}
{{_('Firefox is non-profit, non-corporate, non-compromised. Choosing Firefox isn’t just choosing a browser. It’s a vote for personal freedom.')}}
{% endblock %}

{#- Override <meta property="og:url"> for social share -#}
{% block page_og_url %}{{ url('firefox') }}{% endblock %}

{% block page_title_prefix %}{% endblock %}

{# L10n: This string is used in the <title> tag #}
{% block page_title %}{{ _('Now add Firefox to your Android devices') }}{% endblock %}
{% block page_title_suffix %}{% endblock %}
{% block body_id %}firefox-whatsnew-37{% endblock %}
{% block body_class %}{% endblock %}

{% block site_header_nav %}{% endblock %}
{% block site_header_logo %}
<h2><a href="{{ url('firefox') }}">
{{ high_res_img('img/firefox/whatsnew-fx37/firefox-wordmark.png', {'alt': 'Mozilla Firefox', 'width': '220', 'height': '90'}) }}
</a></h2>
{% endblock %}

{% block site_css %}
{% stylesheet 'firefox_whatsnew_37' %}
{% endblock %}

{% macro thank_you_message() %}
{# L10n: Thank you message after sending the SMS/email #}
{{_('Check your device to start downloading.') }}
<p><a role="button" href="#send-another" class="send-another more">
{# L10n: Thank you message after sending the SMS/email #}
{{ _('Send to another device') }}
</a></p>
{%- endmacro %}

{% block content %}
<main role="main" data-active="email-only">
<header>
<p class="up-to-date">{{ _('Your Firefox is up to date.') }}</p>
<h1>{{ _('Now add Firefox to your Android devices') }}</h1>
<p class="tagline">{{ _('Get the features you love and the privacy you trust in our most customizable Android browser yet. Simply send a download link straight to your phone or tablet — or both.') }}</p>
</header>
<nav class="toggle">
<ul role="tablist">
<li role="presentation" class="sms-tab">
<a id="tab-sms" role="tab" aria-controls="send-sms" href="#send-sms">{{ _('Send by text message') }}</a>
</li>
<li role="presentation" class="email-tab">
<a id="tab-email" role="tab" aria-controls="send-email" href="#send-email">{{ _('Send by email') }}</a>
</li>
</ul>
</nav>
<div class="tab-container">
<div class="inner-wrapper">
<section id="send-email" class="tab-content">
{% set newsletter_id = 'download-firefox-android' %}
{% set newsletter_title = _('Send Firefox to your Android phone or tablet') %}
{% set newsletter_submit = _('Send') %}
{% set newsletter_thankyou_head = _('Your link has been sent!') %}
{% set newsletter_thankyou_content = thank_you_message() %}

{{ email_newsletter_form(newsletter_id, title=newsletter_title, submit_text=newsletter_submit, thankyou_head=newsletter_thankyou_head,thankyou_content=newsletter_thankyou_content) }}
<footer>
{% trans url=settings.GOOGLE_PLAY_FIREFOX_LINK %}
Also available from <a href="{{ url }}">Google Play</a>.
{% endtrans %}
<br>{{ _('The intended recipient of the email must have consented.') }} <a href="{{ url('privacy.notices.websites') }}#campaigns">{{ _('Learn more') }}</a>
</footer>
</section>
<section id="send-sms" class="tab-content">
<div class="inner-wrapper">
<div class="sms-form-wrapper">
<h3>{{ _('Send Firefox to your Android phone') }}</h3>
<form id="sms-form" method="post" action="{{ secure_url('firefox.sms') }}">
<div class="input">
<label for="number">{{ _('Enter your 10-digit phone number') }}</label>
<input type="tel"
maxlength="14"
id="number"
name="number"
placeholder="{{ _('Enter your 10-digit phone number') }}"
value=""
required>
<p class="error hidden">{{ _('An error occurred in our system. Please try again later.') }}</p>
</div>
<button type="submit">{{ _('Send') }}</button>
</form>
<div id="sms-form-thank-you">
<h3>{{ _('Your link has been sent!') }}</h3>
<p>{{ thank_you_message() }}</p>
</div>
<div id="sms-spinner" class="hidden"></div>
</div>
<footer>
{% trans url=settings.GOOGLE_PLAY_FIREFOX_LINK %}
Also available from <a href="{{ url }}">Google Play</a>.
{% endtrans %}
<br>
{{ _('SMS service available in the U.S. only.') }} {{ _('SMS & data rates may apply. The intended recipient of the SMS must have consented.') }} <a href="{{ url('privacy.notices.websites') }}#campaigns">{{ _('Learn more') }}</a>
</footer>
</div>
</section>
</div>
</div>
</main>
{% endblock %}

{% block email_form %}{% endblock%}

{% block js %}
{% javascript 'firefox_whatsnew_fx37' %}
{% endblock %}
8 changes: 8 additions & 0 deletions bedrock/firefox/tests/test_base.py
Expand Up @@ -738,6 +738,14 @@ def test_fx_36_0_with_wrong_oldversion(self, render_mock):

# end 36.0 hello tour tests

@override_settings(DEV=True)
def test_fx_37_0_whatsnew(self, render_mock):
"""Should show Android SMS template for 37.0"""
req = self.rf.get('/en-US/firefox/whatsnew/?oldversion=36.0')
self.view(req, version='37.0')
template = render_mock.call_args[0][1]
eq_(template, ['firefox/whatsnew-fx37.html'])

# ESR31 whatsnew tests

@override_settings(DEV=True)
Expand Down
69 changes: 69 additions & 0 deletions bedrock/firefox/tests/test_views.py
@@ -1,9 +1,13 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json
from django.test.client import RequestFactory
from funfactory.urlresolvers import reverse
from mock import patch
from nose.tools import ok_

from bedrock.firefox import views
from bedrock.mozorg.tests import TestCase


Expand All @@ -18,3 +22,68 @@ def test_frames_allow(self):
resp = self.client.get(reverse('firefox.new'))

ok_('x-frame-options' not in resp)


@patch('bedrock.firefox.views.basket.send_sms')
class TestSMSView(TestCase):
def setUp(self):
self.rf = RequestFactory()

def test_normal_post_success(self, sms_mock):
"""Should send sms and return a redirect."""
req = self.rf.post('/', {'number': '5558675309'})
resp = views.sms_send(req)
sms_mock.assert_called_with('15558675309', 'SMS_Android', False)
self.assertEqual(resp.status_code, 302)

def test_ajax_post_success(self, sms_mock):
"""Should send sms and return a JSON response."""
req = self.rf.post('/', {'number': '5558675309'},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
resp = views.sms_send(req)
sms_mock.assert_called_with('15558675309', 'SMS_Android', False)
self.assertEqual(resp.status_code, 200)
resp_data = json.loads(resp.content)
self.assertEqual(resp_data, {'success': True})

def test_normal_post_error(self, sms_mock):
"""Should not send sms and should return the form with error message."""
req = self.rf.post('/', {'number': '8675309'})
resp = views.sms_send(req)
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, u'Sorry. This number isn\'t valid.')
self.assertFalse(sms_mock.called)

def test_ajax_post_error(self, sms_mock):
"""Should not send sms and should return a JSON response."""
req = self.rf.post('/', {'number': '8675309'},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
resp = views.sms_send(req)
self.assertFalse(sms_mock.called)
self.assertEqual(resp.status_code, 200)
resp_data = json.loads(resp.content)
self.assertFalse(resp_data['success'])
self.assertIn(u'Sorry. This number isn\'t valid.', resp_data['error'])

def test_normal_basket_error(self, sms_mock):
"""Should not send sms and should return the form with error message."""
sms_mock.side_effect = views.basket.BasketException
req = self.rf.post('/', {'number': '5558675309'})
resp = views.sms_send(req)
sms_mock.assert_called_with('15558675309', 'SMS_Android', False)
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, u'An error occurred in our system. Please try again later.')

def test_ajax_basket_error(self, sms_mock):
"""Should not send sms and should return a JSON response."""
sms_mock.side_effect = views.basket.BasketException
req = self.rf.post('/', {'number': '5558675309'},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
resp = views.sms_send(req)
sms_mock.assert_called_with('15558675309', 'SMS_Android', False)
self.assertEqual(resp.status_code, 200)
resp_data = json.loads(resp.content)
self.assertEqual(resp_data, {
'success': False,
'error': u'An error occurred in our system. Please try again later.',
})
54 changes: 40 additions & 14 deletions bedrock/firefox/views.py
Expand Up @@ -6,6 +6,7 @@

import json
import re
from cgi import escape

from django.conf import settings
from django.http import HttpResponsePermanentRedirect, HttpResponseRedirect
Expand All @@ -25,6 +26,7 @@
from bedrock.firefox.forms import SMSSendForm
from bedrock.mozorg.context_processors import funnelcake_param
from bedrock.mozorg.views import process_partnership_form
from bedrock.mozorg.util import HttpResponseJSON
from bedrock.firefox.firefox_details import firefox_details, mobile_details
from lib.l10n_utils.dotlang import _
from product_details.version_compare import Version
Expand Down Expand Up @@ -148,20 +150,42 @@ def installer_help(request):
@csrf_exempt
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
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:
return HttpResponseRedirect(
reverse('firefox.android.sms-thankyou'))
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})

Expand Down Expand Up @@ -469,7 +493,9 @@ def get_template_names(self):
oldversion = oldversion[3:]
versions = ('29.', '30.', '32.')

if version.startswith('36.'):
if version.startswith('37.'):
template = 'firefox/whatsnew-fx37.html'
elif version.startswith('36.'):
if show_36_whatsnew_tour(oldversion):
template = 'firefox/australis/fx36/whatsnew-tour.html'
else:
Expand Down
3 changes: 2 additions & 1 deletion bedrock/newsletter/helpers.py
Expand Up @@ -20,7 +20,7 @@ def email_newsletter_form(ctx, newsletters='mozilla-and-you', title=None,
include_country=True, include_language=True,
details=None, use_thankyou=True, thankyou_head=None,
thankyou_content=None, footer=True, process_form=True,
include_title=None,):
include_title=None, submit_text=None):
request = ctx['request']
context = ctx.get_all()

Expand All @@ -44,6 +44,7 @@ def email_newsletter_form(ctx, newsletters='mozilla-and-you', title=None,
footer=footer,
include_title=include_title if include_title is not None else footer,
form=form,
submit_text=submit_text,
success=success,
))

Expand Down
2 changes: 1 addition & 1 deletion bedrock/newsletter/templates/newsletter/includes/form.html
Expand Up @@ -65,7 +65,7 @@ <h3>{{ title|d(_('Get Firefox news'), true) }}</h3>

<div class="form-submit">
<input type="submit" id="footer_email_submit"
value="{{ _('Sign me up') }} »" class="button">
value="{% if submit_text %}{{ submit_text }}{% else %}{{ _('Sign me up') }} »{% endif %}" class="button">

{% if details %}
<p class="form-details">
Expand Down
14 changes: 14 additions & 0 deletions bedrock/settings/base.py
Expand Up @@ -652,6 +652,14 @@ def JINJA_CONFIG():
),
'output_filename': 'css/firefox_whatsnew-bundle.css',
},
'firefox_whatsnew_37': {
'source_filenames': (
'css/sandstone/sandstone-resp.less',
'css/firefox/template-resp.less',
'css/firefox/whatsnew-fx37.less',
),
'output_filename': 'css/firefox_whatsnew_37-bundle.css',
},
'firefox_whatsnew_fxos': {
'source_filenames': (
'css/sandstone/sandstone.less',
Expand Down Expand Up @@ -1503,6 +1511,12 @@ def JINJA_CONFIG():
),
'output_filename': 'js/firefox_sms-bundle.js',
},
'firefox_whatsnew_fx37': {
'source_filenames': (
'js/firefox/whatsnew-fx37.js',
),
'output_filename': 'js/firefox_whatsnew_fx37-bundle.js',
},
'firefox_whatsnew_fxos': {
'source_filenames': (
'js/firefox/whatsnew-fxos.js',
Expand Down

0 comments on commit 638397c

Please sign in to comment.