예제 #1
0
def view_mailinglist_unsubscribe_notrack(request):
    """Unsubscribe a contact to a mailing list"""
    user_email = request.POST.get("email")
    message = ""
    if user_email:
        try:
            contact = Contact.objects.get(email=user_email)
            contactsave = Contact(
                pk=contact.pk,
                email=contact.email,
                first_name=contact.first_name,
                last_name=contact.last_name,
                subscriber=False,
                content_type=contact.content_type,
                object_id=contact.object_id,
                content_object=contact.content_object,
                creation_date=contact.creation_date,
                modification_date=contact.modification_date,
            )
            contactsave.save()
            finished = True
            return render_to_response(
                "newsletter/mailing_list_unsubscribe_notrack.html",
                {"finished": finished},
                context_instance=RequestContext(request),
            )
        except:
            message = "A user with that email does not exist."
    else:
        message = "No email have been entered."
    return render_to_response(
        "newsletter/mailing_list_unsubscribe_notrack.html",
        {"message": message},
        context_instance=RequestContext(request),
    )
예제 #2
0
def newsletter_subscribe(request):
    if request.POST:
        news_form = NewsletterForm(request.POST)
        if news_form.is_valid():
            data = news_form.cleaned_data
            contact = Contact(email=data['email'],content_object=data['city'])
            contact.save()
            mailing, created = MailingList.objects.get_or_create(name=data['city'].slug)
            mailing.subscribers.add(contact)
            mailing.save()
            return HttpResponseRedirect(reverse('newsletter_subscribe_success'))
    else:
        city = request.session.get('CURRENT_CITY')
        news_form = NewsletterForm(initial={'city':city and city.id or None})
    return render_to_response('newsletter/cadastro.html',locals(),context_instance=RequestContext(request))