This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 695113 apps newsletter to apps landing page
- Loading branch information
1 parent
d9eac99
commit ac797fd
Showing
10 changed files
with
219 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django import forms | ||
|
||
from tower import ugettext as _, ugettext_lazy as _lazy | ||
|
||
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.') | ||
EMAIL_LONG = _lazy(u'Email address is too long (%(show_value)s characters). ' | ||
'It must be %(limit_value)s characters or less.') | ||
PRIVACY_REQUIRED = _lazy(u'You must agree to the privacy policy.') | ||
|
||
class SubscriptionForm(forms.Form): | ||
""" | ||
Form to capture and validate email subscriptions | ||
""" | ||
email = forms.EmailField(label=_lazy(u'Your e-mail address'), | ||
error_messages={'required': EMAIL_REQUIRED, | ||
'min_length': EMAIL_SHORT, | ||
'max_length': EMAIL_LONG}) | ||
format = forms.ChoiceField( | ||
label=_lazy(u'Your preferred format'), | ||
choices=[('html', 'HTML'), ('text', 'Plain text')], | ||
widget=forms.RadioSelect() | ||
) | ||
agree = forms.BooleanField( | ||
label=_lazy(u'I agree'), | ||
error_messages={'required': PRIVACY_REQUIRED} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from datetime import date | ||
|
||
import pycurl | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
from django.conf import settings | ||
from django.utils.http import urlencode | ||
|
||
|
||
def make_source_url(request): | ||
return request.get_host() + request.get_full_path() | ||
|
||
|
||
def subscribe(campaign, address, format='html', source_url='', lang='', country=''): | ||
""" | ||
Subscribe a user to a list in responsys. There should be two | ||
fields within the Responsys system named by the "campaign" | ||
parameter: <campaign>_FLG and <campaign>_DATE | ||
""" | ||
data = { | ||
'LANG_LOCALE': lang, | ||
'COUNTRY_': country, | ||
'SOURCE_URL': source_url, | ||
'EMAIL_ADDRESS_': address, | ||
'EMAIL_FORMAT_': 'H' if format == 'html' else 'T', | ||
} | ||
|
||
data['%s_FLG' % campaign] = 'Y' | ||
data['%s_DATE' % campaign] = date.today().strftime('%Y-%m-%d') | ||
|
||
# views.py asserts setting is available | ||
data['_ri_'] = settings.RESPONSYS | ||
This comment has been minimized.
Sorry, something went wrong.
lmorchard
Contributor
|
||
|
||
if not settings.RESPONSYS_API_URL.lower().startswith('https://'): | ||
raise Exception('Responsys API URL must start with HTTPS.') | ||
|
||
curl = pycurl.Curl() | ||
# Ensure SSL cert validates before sending user data over the wire | ||
curl.setopt(pycurl.SSL_VERIFYPEER, 1) | ||
curl.setopt(pycurl.SSL_VERIFYHOST, 2) | ||
curl.setopt(pycurl.URL, settings.RESPONSYS_API_URL) | ||
# Add POST data | ||
curl.setopt(pycurl.POST, 1) | ||
curl.setopt(pycurl.POSTFIELDS, urlencode(data)) | ||
try: | ||
curl.perform() | ||
except Exception, ce: | ||
raise Exception('Newsletter subscription failed: %s' % ce) | ||
else: | ||
return curl.getinfo(pycurl.RESPONSE_CODE) == 200 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ lxml==2.2.6 | |
coverage==3.2b4 | ||
pylibmc==0.9 | ||
django-pylibmc | ||
pycurl==7.19.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule vendor
updated
7 files
+6 −0 | .gitmodules | |
+2 −0 | kuma.pth | |
+1 −1 | src/bleach | |
+1 −1 | src/django-mozilla-product-details | |
+1 −0 | src/nuggets | |
+1 −1 | src/py-wikimarkup | |
+1 −0 | src/requests |
Can we do this with the httplib or requests module? We already have one or both of those, and they don't have compiled and binary dependencies.