Permalink
Browse files

Merge pull request #988 from lmorchard/849434-newsletter-country

fix bug 849434: Add country selector to App Developer newsletter signup
  • Loading branch information...
2 parents 8517bbb + 1fbb8c4 commit cfe1c051c2ecb04f3baf7b2c6f3c2794448913d1 @groovecoder groovecoder committed Apr 4, 2013
View
@@ -2,6 +2,8 @@
from tower import ugettext as _, ugettext_lazy as _lazy
+from product_details import product_details
+
EMAIL_REQUIRED = _lazy(u'Email address is required.')
EMAIL_SHORT = _lazy(u'Email address is too short (%(show_value)s characters). '
'It must be at least %(limit_value)s characters.')
@@ -26,3 +28,20 @@ class SubscriptionForm(forms.Form):
label=_lazy(u'I agree'),
error_messages={'required': PRIVACY_REQUIRED}
)
+
+ def __init__(self, locale, *args, **kwargs):
+ regions = product_details.get_regions(locale)
+ regions = sorted(regions.iteritems(), key=lambda x: x[1])
+
+ lang = country = locale.lower()
+ if '-' in lang:
+ lang, country = lang.split('-', 1)
+
+ super(SubscriptionForm, self).__init__(*args, **kwargs)
+
+ self.fields['country'] = forms.ChoiceField(
+ label=_lazy(u'Your country'),
+ choices=regions,
+ initial=country,
+ required=False
+ )
@@ -17,6 +17,7 @@
<h3 class="mod-title">{{ _('Firefox Apps & Hacks Newsletter') }}</h3>
{% if form %}
<form id="newsletter-sub" class="fm-subscribe" action="{{ url('apps_newsletter') }}" method="POST">
+ {{ csrf() }}
<p class="mod-intro">{% trans %}
Sign up now for news about Firefox OS, Firefox Marketplace and the Open Web apps ecosystem. <strong>Join us!</strong>
{% endtrans %}</p>
@@ -36,6 +37,11 @@ <h3 class="mod-title">{{ _('Firefox Apps & Hacks Newsletter') }}</h3>
<label for="email">{{ form.email.label }}</label>
{{ form.email }}
</li>
+ <li>
+ {{ form.country.errors }}
+ <label for="country">{{ form.country.label }}</label>
+ {{ form.country }}
+ </li>
<li class="check">
{{ form.format.errors }}
<span class="label">{{ form.format.label }}</span>
@@ -67,4 +73,4 @@ <h3 class="mod-title">{{ _('Firefox Apps & Hacks Newsletter') }}</h3>
</div>
</section>
-{% endblock %}
+{% endblock %}
@@ -106,6 +106,7 @@ def _good_newsletter_post(self):
r = self.client.post(url,
{'format': 'html',
+ 'country': 'pt',
'email': 'testuser@test.com',
'agree': 'checked'},
follow=True)
View
@@ -77,7 +77,7 @@ def apps(request):
def apps_newsletter(request):
if request.method == 'POST':
- form = SubscriptionForm(data=request.POST)
+ form = SubscriptionForm(request.locale, data=request.POST)
context = {'form': form}
if form.is_valid():
optin = 'N'
@@ -87,6 +87,7 @@ def apps_newsletter(request):
try:
result = basket.subscribe(email=form.cleaned_data['email'],
newsletters=settings.BASKET_APPS_NEWSLETTER,
+ country=form.cleaned_data['country'],
format=form.cleaned_data['format'],
lang=request.locale,
optin=optin)
@@ -100,7 +101,7 @@ def apps_newsletter(request):
del context['form']
else:
- context = {'form': SubscriptionForm()}
+ context = {'form': SubscriptionForm(request.locale)}
return jingo.render(request, 'landing/apps_newsletter.html', context)
View
@@ -1007,6 +1007,7 @@ li.tag-expert label:hover { border-color: #bbb; }
.fm-subscribe li { margin-bottom: 1em; font-size: .857em; }
.fm-subscribe label, .fm-subscribe .label { display: block; margin: 0 0 .25em; font: 200 1.25em/1.2 "Bebas Neue", "League Gothic", Haettenschweiler, "Arial Narrow", sans-serif; text-transform: uppercase; letter-spacing: .5px; }
.fm-subscribe input { border: 1px solid #bfbbad; background: #fff; padding: 4px 8px; width: 182px; font-size: .857em; }
+.fm-subscribe select { width: 200px; }
.fm-subscribe input:hover, .fm-subscribe input:focus { border-color: #8d846f; }
.fm-subscribe .fm-submit { text-align: right; font-size: 1.143em; }
.fm-subscribe .inline label, .fm-subscribe .inline .label { width: auto; display: inline; font-family: inherit; font-size: 1em; text-transform: none; }
@@ -1115,4 +1116,4 @@ li.tag-expert label:hover { border-color: #bbb; }
.html-rtl #welcome-close { right: auto; left: 15px; }
.html-rtl #welcome-open { right: auto; left: 10px; }
-.html-rtl.hasJS #nav-main #nav-sub-docs, .html-rtl #nav-main .menu:hover #nav-sub-docs { right: -50px; }
+.html-rtl.hasJS #nav-main #nav-sub-docs, .html-rtl #nav-main .menu:hover #nav-sub-docs { right: -50px; }

0 comments on commit cfe1c05

Please sign in to comment.