def post(self): email = cgi.escape(self.request.get('email')) mailchimp = PyChimp(settings.MAILCHIMP_KEY) try: mailchimp.listSubscribe(settings.MAILCHIMP_LIST, email, {'FIRST': '', 'LAST': ''}) self.redirect('/?subscribe=success') except: self.redirect('/?subscribe=failed')
def post(self): email = cgi.escape(self.request.get('email')) mailchimp = PyChimp(settings.MAILCHIMP_KEY) try: mailchimp.listSubscribe(settings.MAILCHIMP_LIST, email, { 'FIRST': '', 'LAST': '' }) self.redirect('/?subscribe=success') except: self.redirect('/?subscribe=failed')
def __init__(self, request, *args, **kwargs): super(ManageMailchimpSubscriptionForm, self).__init__(*args, **kwargs) # connect to mailchimp to set up form using their info about our lists mailchimp_api = PyChimp("3cb8530ce9770dc992d48f579b6bb09a-us1") mchimp_lists = mailchimp_api.lists() announce_subscribed_status = False news_subscribed_status = False for mchimp_list in mchimp_lists: if request.user.get_profile().is_rhizomemember() and mchimp_list["name"] == "Rhizome Members Announcements": announce_form_label = mchimp_list["name"] user_info = mailchimp_api.listMemberInfo(mchimp_list["id"], request.user.email) if user_info.get("status"): if user_info.get("status") == "subscribed": announce_subscribed_status = True if ( not request.user.get_profile().is_rhizomemember() and mchimp_list["name"] == "Rhizome Users Announcements" ): announce_form_label = mchimp_list["name"] user_info = mailchimp_api.listMemberInfo(mchimp_list["id"], request.user.email) if user_info.get("status"): if user_info.get("status") == "subscribed": announce_subscribed_status = True if mchimp_list["name"] == "Rhizome News": news_form_label = mchimp_list["name"] user_info = mailchimp_api.listMemberInfo(mchimp_list["id"], request.user.email) if user_info.get("status"): if user_info.get("status") == "subscribed": news_subscribed_status = True self.fields["announce_subscribe_checkbox"].label = announce_form_label self.fields["announce_subscribe_checkbox"].initial = announce_subscribed_status self.fields["announce_mailchimp_list"].initial = announce_form_label self.fields["announce_subscribed_status"].initial = announce_subscribed_status self.fields["news_subscribe_checkbox"].label = news_form_label self.fields["news_subscribe_checkbox"].initial = news_subscribed_status self.fields["news_mailchimp_list"].initial = news_form_label self.fields["news_subscribed_status"].initial = news_subscribed_status
def __init__(self, request, *args, **kwargs): super(ManageMailchimpSubscriptionForm, self).__init__(*args, **kwargs) #connect to mailchimp to set up form using their info about our lists mailchimp_api = PyChimp('3cb8530ce9770dc992d48f579b6bb09a-us1') mchimp_lists = mailchimp_api.lists() announce_subscribed_status = False news_subscribed_status = False announce_form_label = '' for mchimp_list in mchimp_lists: if request.user.get_profile().is_rhizomemember( ) and mchimp_list["name"] == "Rhizome Members Announcements": announce_form_label = mchimp_list["name"] user_info = mailchimp_api.listMemberInfo( mchimp_list["id"], request.user.email) if user_info.get("status"): if user_info.get("status") == "subscribed": announce_subscribed_status = True if not request.user.get_profile().is_rhizomemember( ) and mchimp_list["name"] == "Rhizome Users Announcements": announce_form_label = mchimp_list["name"] user_info = mailchimp_api.listMemberInfo( mchimp_list["id"], request.user.email) if user_info.get("status"): if user_info.get("status") == "subscribed": announce_subscribed_status = True if mchimp_list["name"] == "Rhizome News": news_form_label = mchimp_list["name"] user_info = mailchimp_api.listMemberInfo( mchimp_list["id"], request.user.email) if user_info.get("status"): if user_info.get("status") == "subscribed": news_subscribed_status = True self.fields['announce_subscribe_checkbox'].label = announce_form_label self.fields[ 'announce_subscribe_checkbox'].initial = announce_subscribed_status self.fields['announce_mailchimp_list'].initial = announce_form_label self.fields[ 'announce_subscribed_status'].initial = announce_subscribed_status self.fields['news_subscribe_checkbox'].label = news_form_label self.fields['news_subscribe_checkbox'].initial = news_subscribed_status self.fields['news_mailchimp_list'].initial = news_form_label self.fields['news_subscribed_status'].initial = news_subscribed_status
def send_news(self, request): mailchimp_api = PyChimp('3cb8530ce9770dc992d48f579b6bb09a-us1') mailchimp_return_error_notice = '' mailchimp_return_success_notice = '' site = Site.objects.get(id=1) context_instance = RequestContext(request) newsletter = Newsletter.objects.order_by('-created')[0] today = datetime.date.today() news_url = 'https://%s/editorial/news/' % site.domain article = newsletter.article() from_name = "RHIZOME NEWS" from_email = "*****@*****.**" to_email = "*****@*****.**" formatted_date = today.strftime('%m.%d.%y') #get news and test lists for mailchimp_list in mailchimp_api.lists(): if mailchimp_list["name"] == "Rhizome News": rhiz_news_list = mailchimp_list if mailchimp_list["name"] == "Test List": test_list = mailchimp_list if request.method == 'POST': mailchimp_opts = { "list_id": rhiz_news_list["id"], "subject": request.POST["subject"], "from_name": request.POST["from_name"], "from_email": request.POST["from_email"], "to_email": request.POST["to_email"], "tracking": {'opens':True, 'html_clicks':True,'text_clicks':True}, "authenticate":True, "title": "RHIZOME NEWS: %s" % formatted_date, "generate_text": True } #get the news html page content mailchimp_content = {"url": news_url} #create campaign rhizome_news_campaign = mailchimp_api.campaignCreate("regular", mailchimp_opts, mailchimp_content) #check to see if campaign created successfully try: mailchimp_return_error_notice = "CAMPAIGN CREATION ERROR: %s..<br />." % (rhizome_news_campaign["error"]) except: mailchimp_return_success_notice = "New Campaign Created. ID = %s <br />" % rhizome_news_campaign #send the campaign or a test depending on "to" field if request.POST["to_email"] == "*****@*****.**": #send the newsletter send_campaign = mailchimp_api.campaignSendNow(rhizome_news_campaign) #check for sending errors try: mailchimp_return_error_notice += "SENDING ERROR: %s..<br />." % (send_campaign["error"]) except: mailchimp_return_success_notice += "Rhizome News Successfully Sent! Sent = %s<br />" % send_campaign else: #send a test address in "to" field test_email_addys = ["%s" % request.POST["to_email"]] send_test_campaign = mailchimp_api.campaignSendTest(rhizome_news_campaign, test_email_addys); #check for sending errors try: mailchimp_return_error_notice += "TEST SENDING ERROR: %s...<br />" % (send_test_campaign["error"]) except: mailchimp_return_success_notice += " Test email sent! Success = %s<br />" % send_test_campaign context = { 'app_label': self.model._meta.app_label, 'admin_site': self.admin_site.name, 'title': "Send the News", 'opts': "Newsletters", 'from_name' : from_name, 'from_email': from_email, 'to_email':to_email, 'subject': article, 'news_url' : news_url, 'mailchimp_return_error_notice':mailchimp_return_error_notice, 'mailchimp_return_success_notice':mailchimp_return_success_notice } return render_to_response("admin/mailinglists/send_news.html", context, context_instance)
def send_member_newsletter(self, request): mailchimp_api = PyChimp('3cb8530ce9770dc992d48f579b6bb09a-us1') mailchimp_return_error_notice = '' mailchimp_return_success_notice = '' site = Site.objects.get(id=1) context_instance = RequestContext(request) try: newsletter = MemberNewsletter.objects.order_by('-created')[0] except: newsletter = None if not newsletter: context = { 'app_label': self.model._meta.app_label, 'admin_site': self.admin_site.name, 'title': "Send A Member Newsletter", 'opts': "Member Newsletters", 'from_name' :'', 'from_email': '', 'to_email': '', 'subject': '', 'newsletter_url' : '', 'mailchimp_return_error_notice': 'NO NEWSLETTERS FOUND! GO CREATE ONE!', 'mailchimp_return_success_notice': '', 'site': site, } return render_to_response("admin/mailinglists/send_member_newsletter.html", context, context_instance) today = datetime.date.today() newsletter_url = 'https://%s/member-newsletter/' % site.domain from_name = "RHIZOME" from_email = "*****@*****.**" to_email = "*****@*****.**" formatted_date = today.strftime('%m.%d.%y') newsletter_title = "RHIZOME MEMBER NEWSLETTER: %s" % formatted_date for mailchimp_list in mailchimp_api.lists(): if mailchimp_list["name"] == "Rhizome Members Announcements": members_list = mailchimp_list if mailchimp_list["name"] == "Test List": test_list = mailchimp_list if request.method == 'POST': mailchimp_opts = { "list_id": members_list["id"], "subject": request.POST["subject"], "from_name": request.POST["from_name"], "from_email": request.POST["from_email"], "to_email": request.POST["to_email"], "tracking": {'opens':True, 'html_clicks':True, 'text_clicks':True}, "authenticate": True, "title": newsletter_title, "generate_text": True } #get the news html page content mailchimp_content = {"url":newsletter_url} #create campaign member_newsletter_campaign = mailchimp_api.campaignCreate("regular", mailchimp_opts, mailchimp_content) #check to see if campaign created successfully try: mailchimp_return_error_notice = "CAMPAIGN CREATION ERROR: %s...<br />" % (member_newsletter_campaign["error"]) except: mailchimp_return_success_notice = "New Campaign Created. ID = %s <br />" % member_newsletter_campaign #send the campaign or a test depending on "to" field if request.POST["to_email"] == "*****@*****.**": #send the newsletter send_campaign = mailchimp_api.campaignSendNow(member_newsletter_campaign) #check for sending errors try: mailchimp_return_error_notice += "SENDING ERROR: %s...<br />" % (send_campaign["error"]) except: mailchimp_return_success_notice += "Member Newsletter Successfully Sent! Sent = %s<br />" % send_campaign else: #send a test address in "to" field test_email_addys = ["%s" % request.POST["to_email"]] send_test_campaign = mailchimp_api.campaignSendTest(member_newsletter_campaign, test_email_addys); #check for sending errors try: mailchimp_return_error_notice += "TEST SENDING ERROR: %s...<br />" % (send_test_campaign["error"]) except: mailchimp_return_success_notice += " Test email sent! Success = %s<br />" % send_test_campaign context = { 'app_label': self.model._meta.app_label, 'admin_site': self.admin_site.name, 'title': "Send A Member Newsletter", 'opts': "Member Newsletters", 'from_name' : from_name, 'from_email': from_email, 'to_email':to_email, 'subject': newsletter_title, 'newsletter_url' : newsletter_url, 'mailchimp_return_error_notice':mailchimp_return_error_notice, 'mailchimp_return_success_notice':mailchimp_return_success_notice, 'site': site, } return render_to_response("admin/mailinglists/send_member_newsletter.html", context, context_instance)
def manage_mailchimp_subscriptions(request): ''' - creates a simple form allowing people to un/subscribe to/from mailchimp lists - this is an ssi in the template in case mailchimp delays or problems, don't want their stuff slowing or crashing our stuff ''' context = RequestContext(request) manange_mailchimp_form = ManageMailchimpSubscriptionForm(request) notification = None errors = None redirect_path = request.GET.get('parent') if request.POST: manange_mailchimp_form = ManageMailchimpSubscriptionForm(request, request.POST) if manange_mailchimp_form.is_valid(): mailchimp_api = PyChimp('3cb8530ce9770dc992d48f579b6bb09a-us1') announce_new_status = manange_mailchimp_form.cleaned_data["announce_subscribe_checkbox"] announce_old_status = manange_mailchimp_form.cleaned_data["announce_subscribed_status"] announce_form_mchimp_list = manange_mailchimp_form.cleaned_data["announce_mailchimp_list"] news_new_status = manange_mailchimp_form.cleaned_data["news_subscribe_checkbox"] news_old_status = manange_mailchimp_form.cleaned_data["news_subscribed_status"] news_form_mchimp_list = manange_mailchimp_form.cleaned_data["news_mailchimp_list"] if announce_old_status != announce_new_status or news_new_status != news_old_status: mailchimp_api = PyChimp('3cb8530ce9770dc992d48f579b6bb09a-us1') mchimp_lists = mailchimp_api.lists() for mchimp_list in mchimp_lists: if mchimp_list["name"] == announce_form_mchimp_list: #user_info = mailchimp_api.listMemberInfo(mchimp_list["id"], request.user.email) if request.user.first_name: merge_vars = {"FNAME": request.user.first_name, "LNAME": request.user.last_name} else: if announce_form_mchimp_list == "Rhizome Users Announcements": merge_vars = {"FNAME": "Rhizome", "LNAME": "Member"} if announce_form_mchimp_list == "Rhizome Members Announcements": merge_vars = {"FNAME": "Rhizome", "LNAME": "Friend"} if announce_new_status == True: # subscribe request mailchimp_api.listSubscribe(mchimp_list["id"], request.user.email, merge_vars, email_type='html', double_optin=False, update_existing=False, replace_interests=True, send_welcome=True) if announce_new_status == False: # unsubscribe request mailchimp_api.listUnsubscribe(mchimp_list["id"], request.user.email, delete_member=False, send_goodbye=True, send_notify=True) if mchimp_list["name"] == news_form_mchimp_list: #user_info = mailchimp_api.listMemberInfo(mchimp_list["id"], request.user.email) if request.user.get_full_name(): merge_vars = {"FNAME": request.user.first_name, "LNAME": request.user.last_name} elif request.user.first_name: merge_vars = {"FNAME": request.user.first_name, "LNAME": None} else: merge_vars = {"FNAME": request.user.username, "LNAME": None} if news_new_status == True: # subscribe request mailchimp_api.listSubscribe(mchimp_list["id"], request.user.email, merge_vars, email_type='html', double_optin=False, update_existing=False, replace_interests=True, send_welcome=True) if news_new_status == False: # unsubscribe request mailchimp_api.listUnsubscribe(mchimp_list["id"], request.user.email, delete_member=False, send_goodbye=True, send_notify=True) else: errors = manange_mailchimp_form.errors return HttpResponseRedirect("/profiles/edit?updated=True&errors=%s" % errors) d= {"form":manange_mailchimp_form} return render_to_response("accounts/forms/manage_mailchimp_subscriptions.html", d, context)
def send_news(self, request): mailchimp_api = PyChimp('3cb8530ce9770dc992d48f579b6bb09a-us1') mailchimp_return_error_notice = '' mailchimp_return_success_notice = '' site = Site.objects.get(id=1) context_instance = RequestContext(request) newsletter = Newsletter.objects.order_by('-created')[0] today = datetime.date.today() news_url = 'https://%s/editorial/news/' % site.domain article = newsletter.article() from_name = "RHIZOME NEWS" from_email = "*****@*****.**" to_email = "*****@*****.**" formatted_date = today.strftime('%m.%d.%y') #get news and test lists for mailchimp_list in mailchimp_api.lists(): if mailchimp_list["name"] == "Rhizome News": rhiz_news_list = mailchimp_list if mailchimp_list["name"] == "Test List": test_list = mailchimp_list if request.method == 'POST': mailchimp_opts = { "list_id": rhiz_news_list["id"], "subject": request.POST["subject"], "from_name": request.POST["from_name"], "from_email": request.POST["from_email"], "to_email": request.POST["to_email"], "tracking": { 'opens': True, 'html_clicks': True, 'text_clicks': True }, "authenticate": True, "title": "RHIZOME NEWS: %s" % formatted_date, "generate_text": True } #get the news html page content mailchimp_content = {"url": news_url} #create campaign rhizome_news_campaign = mailchimp_api.campaignCreate( "regular", mailchimp_opts, mailchimp_content) #check to see if campaign created successfully try: mailchimp_return_error_notice = "CAMPAIGN CREATION ERROR: %s..<br />." % ( rhizome_news_campaign["error"]) except: mailchimp_return_success_notice = "New Campaign Created. ID = %s <br />" % rhizome_news_campaign #send the campaign or a test depending on "to" field if request.POST["to_email"] == "*****@*****.**": #send the newsletter send_campaign = mailchimp_api.campaignSendNow( rhizome_news_campaign) #check for sending errors try: mailchimp_return_error_notice += "SENDING ERROR: %s..<br />." % ( send_campaign["error"]) except: mailchimp_return_success_notice += "Rhizome News Successfully Sent! Sent = %s<br />" % send_campaign else: #send a test address in "to" field test_email_addys = ["%s" % request.POST["to_email"]] send_test_campaign = mailchimp_api.campaignSendTest( rhizome_news_campaign, test_email_addys) #check for sending errors try: mailchimp_return_error_notice += "TEST SENDING ERROR: %s...<br />" % ( send_test_campaign["error"]) except: mailchimp_return_success_notice += " Test email sent! Success = %s<br />" % send_test_campaign context = { 'app_label': self.model._meta.app_label, 'admin_site': self.admin_site.name, 'title': "Send the News", 'opts': "Newsletters", 'from_name': from_name, 'from_email': from_email, 'to_email': to_email, 'subject': article, 'news_url': news_url, 'mailchimp_return_error_notice': mailchimp_return_error_notice, 'mailchimp_return_success_notice': mailchimp_return_success_notice } return render_to_response("admin/mailinglists/send_news.html", context, context_instance)
def send_member_newsletter(self, request): mailchimp_api = PyChimp('3cb8530ce9770dc992d48f579b6bb09a-us1') mailchimp_return_error_notice = '' mailchimp_return_success_notice = '' site = Site.objects.get(id=1) context_instance = RequestContext(request) try: newsletter = MemberNewsletter.objects.order_by('-created')[0] except: newsletter = None if not newsletter: context = { 'app_label': self.model._meta.app_label, 'admin_site': self.admin_site.name, 'title': "Send A Member Newsletter", 'opts': "Member Newsletters", 'from_name': '', 'from_email': '', 'to_email': '', 'subject': '', 'newsletter_url': '', 'mailchimp_return_error_notice': 'NO NEWSLETTERS FOUND! GO CREATE ONE!', 'mailchimp_return_success_notice': '', 'site': site, } return render_to_response( "admin/mailinglists/send_member_newsletter.html", context, context_instance) today = datetime.date.today() newsletter_url = 'https://%s/member-newsletter/' % site.domain from_name = "RHIZOME" from_email = "*****@*****.**" to_email = "*****@*****.**" formatted_date = today.strftime('%m.%d.%y') newsletter_title = "RHIZOME MEMBER NEWSLETTER: %s" % formatted_date for mailchimp_list in mailchimp_api.lists(): if mailchimp_list["name"] == "Rhizome Members Announcements": members_list = mailchimp_list if mailchimp_list["name"] == "Test List": test_list = mailchimp_list if request.method == 'POST': mailchimp_opts = { "list_id": members_list["id"], "subject": request.POST["subject"], "from_name": request.POST["from_name"], "from_email": request.POST["from_email"], "to_email": request.POST["to_email"], "tracking": { 'opens': True, 'html_clicks': True, 'text_clicks': True }, "authenticate": True, "title": newsletter_title, "generate_text": True } #get the news html page content mailchimp_content = {"url": newsletter_url} #create campaign member_newsletter_campaign = mailchimp_api.campaignCreate( "regular", mailchimp_opts, mailchimp_content) #check to see if campaign created successfully try: mailchimp_return_error_notice = "CAMPAIGN CREATION ERROR: %s...<br />" % ( member_newsletter_campaign["error"]) except: mailchimp_return_success_notice = "New Campaign Created. ID = %s <br />" % member_newsletter_campaign #send the campaign or a test depending on "to" field if request.POST["to_email"] == "*****@*****.**": #send the newsletter send_campaign = mailchimp_api.campaignSendNow( member_newsletter_campaign) #check for sending errors try: mailchimp_return_error_notice += "SENDING ERROR: %s...<br />" % ( send_campaign["error"]) except: mailchimp_return_success_notice += "Member Newsletter Successfully Sent! Sent = %s<br />" % send_campaign else: #send a test address in "to" field test_email_addys = ["%s" % request.POST["to_email"]] send_test_campaign = mailchimp_api.campaignSendTest( member_newsletter_campaign, test_email_addys) #check for sending errors try: mailchimp_return_error_notice += "TEST SENDING ERROR: %s...<br />" % ( send_test_campaign["error"]) except: mailchimp_return_success_notice += " Test email sent! Success = %s<br />" % send_test_campaign context = { 'app_label': self.model._meta.app_label, 'admin_site': self.admin_site.name, 'title': "Send A Member Newsletter", 'opts': "Member Newsletters", 'from_name': from_name, 'from_email': from_email, 'to_email': to_email, 'subject': newsletter_title, 'newsletter_url': newsletter_url, 'mailchimp_return_error_notice': mailchimp_return_error_notice, 'mailchimp_return_success_notice': mailchimp_return_success_notice, 'site': site, } return render_to_response( "admin/mailinglists/send_member_newsletter.html", context, context_instance)