Skip to content

Commit

Permalink
Allow the passing of arbitrary get params in mail chimp
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlifshin committed Jul 30, 2014
1 parent 98c73eb commit 9d7fc55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 8 additions & 4 deletions backend/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ def Charge(self, customer_id, amount_cents):
class MailchimpSubscriber(handlers.MailingListSubscriber):
def Subscribe(self, email, first_name, last_name, amount_cents, ip_addr, time,
source, phone=None, zipcode=None, volunteer=None, skills=None, rootstrikers=None,
nonce=None, pledgePageSlug=None):
nonce=None, pledgePageSlug=None, otherVars = None):
deferred.defer(_subscribe_to_mailchimp,
email, first_name, last_name,
amount_cents, ip_addr, source, phone, zipcode,
volunteer, skills, rootstrikers, nonce, pledgePageSlug)
volunteer, skills, rootstrikers,
nonce, pledgePageSlug, otherVars)


class FakeSubscriber(handlers.MailingListSubscriber):
Expand Down Expand Up @@ -155,7 +156,7 @@ def _send_mail(to, subject, text_body, html_body, reply_to=None):
def _subscribe_to_mailchimp(email_to_subscribe, first_name, last_name,
amount, request_ip, source, phone=None, zipcode=None,
volunteer=None, skills=None, rootstrikers=None,
nonce=None, pledgePageSlug=None):
nonce=None, pledgePageSlug=None, otherVars=None):
mailchimp_api_key = model.Config.get().mailchimp_api_key
mailchimp_list_id = model.Config.get().mailchimp_list_id
mc = mailchimp.Mailchimp(mailchimp_api_key)
Expand Down Expand Up @@ -194,9 +195,12 @@ def _subscribe_to_mailchimp(email_to_subscribe, first_name, last_name,

if pledgePageSlug is not None:
merge_vars['PPURL'] = pledgePageSlug

if otherVars is not None:
merge_vars.update(otherVars)

# list ID and email struct
logging.info('Subscribing: %s. ZIP: %s', email_to_subscribe, zipcode)
logging.info('Subscribing: %s. Merge_vars: %s', email_to_subscribe, str(merge_vars))
mc.lists.subscribe(id=mailchimp_list_id,
email=dict(email=email_to_subscribe),
merge_vars=merge_vars,
Expand Down
12 changes: 10 additions & 2 deletions backend/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,14 @@ def post(self):
pledgePageSlug_input = cgi.escape(self.request.get('pledgePageSlug'))
if len(pledgePageSlug_input) == 0:
pledgePageSlug_input = ''


otherVars = {}
# get any parameter that looks like MERGE something
for argName in self.request.arguments():
if argName.startswith('MERGE'):
arg = self.request.get(argName)
otherVars[argName] = arg

env.mailing_list_subscriber.Subscribe(
email=email_input,
first_name=first_name, last_name=last_name,
Expand All @@ -383,7 +390,8 @@ def post(self):
volunteer=volunteer_input,
skills=skills_input,
rootstrikers=rootstrikers_input,
pledgePageSlug=pledgePageSlug_input
pledgePageSlug=pledgePageSlug_input,
otherVars=otherVars
)

util.EnableCors(self)
Expand Down

0 comments on commit 9d7fc55

Please sign in to comment.