Example #1
0
def create_and_send_campaign(request):
    try:
        if request.method == 'POST':
            api = pychimp.PyChimp(request.POST['apikey'])
            campaign = api.campaignCreate(
                'regular', {
                    'list_id': request.POST['listid'],
                    'subject': request.POST['subject'],
                    'from_email': request.POST['from_email'],
                    'from_name': request.POST['from_name']
                }, {
                    'url':
                    request.POST['url'],
                    'text':
                    "check out this weeks events at %s" % request.POST['url']
                })
            taskqueue.add(url='/subscriptions/send_campaign/',
                          params={
                              'apikey': request.POST['apikey'],
                              'campaign': campaign,
                          },
                          countdown=20,
                          name="campaign-%s" % campaign)

            return HttpResponse("Created campaign %s" % campaign)

        else:
            site = get_site()
            chimp = site.chimp
            return HttpResponse("""
            <form method="POST">
            url: <input type="text" value="" name="url"/><br/>
            subject: <input type="text" value="" name="subject"/><br/>
            from name: <input type="text" value="" name="from_name"/><br/>
            from email: <input type="text" value="" name="from_email"/>
            <input type="hidden" name="apikey" value="%s"/>
            <input type="hidden" name="listid" value="%s"/>
            <input type="submit" value="Send"/>
            </form>
        
        
        
            """ % (chimp.apikey, chimp.listid))

    except Exception, e:
        logging.error("%s in \n%s" %
                      (traceback.format_exc(), str(request.POST)))
        HttpResponse("OK")
Example #2
0
def configure_mailchimp(request):
    site = get_site()
    mc = models.SitesMailchimp.all().ancestor(site).get()
    if not mc:
        if request.method == 'POST':
            form = MailChimpApiKey(request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('configure-mailchimp'))
        else:
            form = MailChimpApiKey()

        return render_to_response('admin/mailchimp_apikey.html',
                                  locals(),
                                  context_instance=RequestContext(request))

    else:
        chimp = pychimp.PyChimp(mc.apikey)
        lists = chimp.lists()
        list_choices = [(l['id'] + '!@!' + l['name'], l['name'])
                        for l in lists]

        class MailChimpListForm(forms.Form):
            mailchimp_list = forms.ChoiceField(choices=list_choices)

            def save(self):
                mc.listid, mc.listname = self.cleaned_data[
                    'mailchimp_list'].split('!@!')
                mc.put()

        if request.method == 'POST':
            form = MailChimpListForm(request.POST)
            if form.is_valid():
                form.save()
                messages.add_message(request, messages.INFO,
                                     "Mailing list configured!")
                return HttpResponseRedirect(reverse('admin-home'))

        form = MailChimpListForm()
        return render_to_response('admin/mailchimp_apikey.html',
                                  locals(),
                                  context_instance=RequestContext(request))
        return HttpResponse(lists)
Example #3
0
def send_campaign(request):
    api = pychimp.PyChimp(request.POST['apikey'])
    api.campaignSendNow(request.POST['campaign'])
    return HttpResponse("sent campaign")
Example #4
0
def subscribe_email(request):
    api = pychimp.PyChimp(request.POST['apikey'])
    api.listSubscribe(request.POST['list_id'], request.POST['email'], '')
    return HttpResponse("OK")
Example #5
0
 def api(self):
     return pychimp.PyChimp(self.apikey)