Пример #1
0
def view_newsletter_tracking_link(request, slug, uidb36, token, link_id):
    """Track the opening of a link on the website"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    link = get_object_or_404(Link, pk=link_id)
    ContactMailingStatus.objects.create(
        newsletter=newsletter, contact=contact, status=ContactMailingStatus.LINK_OPENED, link=link
    )
    if not USE_UTM_TAGS:
        return HttpResponseRedirect(link.url)

    url_parts = urlparse(link.url)
    query_dict = dict(parse_qsl(url_parts.query))
    query_dict.update(
        {
            "utm_source": "newsletter_%s" % newsletter.pk,
            "utm_medium": "mail",
            "utm_campaign": smart_str(newsletter.title),
        }
    )
    url = urlunparse(
        (
            url_parts.scheme,
            url_parts.netloc,
            url_parts.path,
            url_parts.params,
            urlencode(query_dict),
            url_parts.fragment,
        )
    )
    return HttpResponseRedirect(url)
def view_mailinglist_unsubscribe(request, slug, uidb36, token):
    """Unsubscribe a contact to a mailing list"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    
    unsubscribers = Contact.objects.none()
    for mailing_list in newsletter.mailing_lists.all():
        unsubscribers |= mailing_list.unsubscribers.all()
    
    already_unsubscribed = contact in unsubscribers

    if request.POST.get('email') and not already_unsubscribed:
        for mailing_list in newsletter.mailing_lists.all():
            if contact in mailing_list.subscribers.all():
                mailing_list.unsubscribers.add(contact)
                mailing_list.save()

        already_unsubscribed = True
        log = ContactMailingStatus.objects.create(newsletter=newsletter, contact=contact,
                                                  status=ContactMailingStatus.UNSUBSCRIPTION)

    return render_to_response('newsletter/mailing_list_unsubscribe.html',
                              {'email': contact.email,
                               'already_unsubscribed': already_unsubscribed},
                              context_instance=RequestContext(request))
Пример #3
0
def view_mailinglist_unsubscribe(request, slug, uidb36, token):
    """Unsubscribe a contact to one or all mailing lists"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    if emencia_settings.UNSUBSCRIBE_ALL:
        mailing_lists = MailingList.objects.all()
        contact.subscriber = False
        contact.save()
    else:
        mailing_lists = [newsletter.mailing_list]

    unsubscribed = 0
    already_unsubscribed = False

    if request.POST.get('email'):
        for mailing_list in mailing_lists:
            already_unsubscribed = contact in mailing_list.unsubscribers.all()

            if not already_unsubscribed:
                mailing_list.unsubscribers.add(contact)
                mailing_list.save()
            unsubscribed += 1

    if unsubscribed > 0:
        already_unsubscribed = True
        ContactMailingStatus.objects.create(newsletter=newsletter, contact=contact,
                                            status=ContactMailingStatus.UNSUBSCRIPTION)

    return render_to_response('newsletter/mailing_list_unsubscribe.html',
                              {'email': contact.email,'unsubscribed_count':unsubscribed,
                               'already_unsubscribed': already_unsubscribed},
                              context_instance=RequestContext(request))
Пример #4
0
def view_newsletter_tracking(request, slug, uidb36, token):
    """Track the opening of the newsletter by requesting a blank img"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    ContactMailingStatus.objects.create(newsletter=newsletter,
                                        contact=contact,
                                        status=ContactMailingStatus.OPENED)
    return HttpResponse(base64.b64decode(TRACKING_IMAGE), mimetype='image/png')
def view_newsletter_tracking(request, slug, uidb36, token):
    """Track the opening of the newsletter by requesting a blank img"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    log = ContactMailingStatus.objects.create(
        newsletter=newsletter, contact=contact, status=ContactMailingStatus.OPENED
    )
    return HttpResponse(base64.b64decode(TRACKING_IMAGE), mimetype="image/png")
def view_newsletter_tracking_link(request, slug, uidb36, token, link_id):
    """Track the opening of a link on the website"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    link = get_object_or_404(Link, pk=link_id)
    log = ContactMailingStatus.objects.create(
        newsletter=newsletter, contact=contact, status=ContactMailingStatus.LINK_OPENED, link=link
    )
    return HttpResponseRedirect(link.url)
def view_newsletter_contact(request, slug, uidb36, token):
    """Visualization of a newsletter by an user"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    ContactMailingStatus.objects.create(
        newsletter=newsletter, contact=contact, status=ContactMailingStatus.OPENED_ON_SITE
    )
    context = {"contact": contact, "uidb36": uidb36, "token": token, "SITE_VERSION": True}

    return render_newsletter(request, slug, context)
def view_newsletter_contact(request, slug, uidb36, token):
    """Visualization of a newsletter by an user"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    log = ContactMailingStatus.objects.create(newsletter=newsletter,
                                              contact=contact,
                                              status=ContactMailingStatus.OPENED_ON_SITE)
    context = {'contact': contact,
               'uidb36': uidb36, 'token': token}
    
    return render_newsletter(request, slug, context)
def view_newsletter_contact(request, slug, uidb36, token):
    """Visualization of a newsletter by an user"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    ContactMailingStatus.objects.create(
        newsletter=newsletter,
        contact=contact,
        status=ContactMailingStatus.OPENED_ON_SITE)
    context = {'contact': contact, 'uidb36': uidb36, 'token': token}

    return render_newsletter(request, slug, context)
Пример #10
0
def view_newsletter_tracking_link(request, slug, uidb36, token, link_id):
    """Track the opening of a link on the website"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    link = get_object_or_404(Link, pk=link_id)
    ContactMailingStatus.objects.create(
        newsletter=newsletter,
        contact=contact,
        status=ContactMailingStatus.LINK_OPENED,
        link=link)
    return HttpResponseRedirect(link.url)
Пример #11
0
def view_mailinglist_unsubscribe(request, slug, uidb36, token):
    """Unsubscribe a contact to a mailing list"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)

    already_unsubscribed = contact in newsletter.mailing_list.unsubscribers.all()

    if request.POST.get("email") and not already_unsubscribed:
        newsletter.mailing_list.unsubscribers.add(contact)
        newsletter.mailing_list.save()
        already_unsubscribed = True
        ContactMailingStatus.objects.create(
            newsletter=newsletter, contact=contact, status=ContactMailingStatus.UNSUBSCRIPTION
        )

    return render_to_response(
        "newsletter/mailing_list_unsubscribe.html",
        {"email": contact.email, "already_unsubscribed": already_unsubscribed},
        context_instance=RequestContext(request),
    )
Пример #12
0
def view_mailinglist_unsubscribe(request, slug, uidb36, token):
    """Unsubscribe a contact to a mailing list"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)

    already_unsubscribed = contact in newsletter.mailing_list.unsubscribers.all(
    )

    if request.POST.get('email') and not already_unsubscribed:
        newsletter.mailing_list.unsubscribers.add(contact)
        newsletter.mailing_list.save()
        already_unsubscribed = True
        log = ContactMailingStatus.objects.create(
            newsletter=newsletter,
            contact=contact,
            status=ContactMailingStatus.UNSUBSCRIPTION)

    return render(request, 'newsletter/mailing_list_unsubscribe.html', {
        'email': contact.email,
        'already_unsubscribed': already_unsubscribed
    })
Пример #13
0
def view_newsletter_tracking_link(request, slug, uidb36, token, link_id):
    """Track the opening of a link on the website"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    link = get_object_or_404(Link, pk=link_id)
    ContactMailingStatus.objects.create(
        newsletter=newsletter,
        contact=contact,
        status=ContactMailingStatus.LINK_OPENED,
        link=link)
    if not USE_UTM_TAGS:
        return HttpResponseRedirect(link.url)

    url_parts = urlparse(link.url)
    query_dict = parse_qs(url_parts.query)
    query_dict.update({
        'utm_source': 'newsletter_%s' % newsletter.pk,
        'utm_medium': 'mail',
        'utm_campaign': smart_str(newsletter.title)
    })
    url = urlunparse(
        (url_parts.scheme, url_parts.netloc, url_parts.path, url_parts.params,
         urlencode(query_dict), url_parts.fragment))
    return HttpResponseRedirect(url)
Пример #14
0
def view_mailinglist_unsubscribe(request, slug, uidb36, token):
    """Unsubscribe a contact to one or all mailing lists"""
    newsletter = get_object_or_404(Newsletter, slug=slug)
    contact = untokenize(uidb36, token)
    if emencia_settings.UNSUBSCRIBE_ALL:
        mailing_lists = MailingList.objects.all()
        contact.subscriber = False
        contact.save()
    else:
        mailing_lists = [newsletter.mailing_list]

    unsubscribed = 0
    already_unsubscribed = False

    if request.POST.get('email'):
        for mailing_list in mailing_lists:
            already_unsubscribed = contact in mailing_list.unsubscribers.all()

            if not already_unsubscribed:
                mailing_list.unsubscribers.add(contact)
                mailing_list.save()
            unsubscribed += 1

    if unsubscribed > 0:
        already_unsubscribed = True
        ContactMailingStatus.objects.create(
            newsletter=newsletter,
            contact=contact,
            status=ContactMailingStatus.UNSUBSCRIPTION)

    return render_to_response('newsletter/mailing_list_unsubscribe.html', {
        'email': contact.email,
        'unsubscribed_count': unsubscribed,
        'already_unsubscribed': already_unsubscribed
    },
                              context_instance=RequestContext(request))
Пример #15
0
 def test_tokenize_untokenize(self):
     uidb36, token = tokenize(self.contact)
     self.assertEquals(untokenize(uidb36, token), self.contact)
     self.assertRaises(Http404, untokenize, 'toto', token)
     self.assertRaises(Http404, untokenize, uidb36, 'toto')
Пример #16
0
 def test_tokenize_untokenize(self):
     uidb36, token = tokenize(self.contact)
     self.assertEquals(untokenize(uidb36, token), self.contact)
     self.assertRaises(Http404, untokenize, 'toto', token)
     self.assertRaises(Http404, untokenize, uidb36, 'toto')