Beispiel #1
0
def newsletter_edit(request, newsletter_id):
    #from django.forms.models import inlineformset_factory
    
    newsletter = Newsletter.objects.get(id=newsletter_id)
    if request.method == "POST":
        form = NewsletterForm(request.POST, instance=newsletter)
        #form = NewsletterForm(request.POST, instance=newsletter, prefix="newsletter")
        #formset = LinkFormset(request.POST, request.FILES, instance=newsletter, prefix="links")
        if form.is_valid():
        #and formset.is_valid():
            #f = form.save(commit=False)
            #f.save(True)
            #form.save_m2m()
            #formset.save()
            form.save()
            
            return HttpResponseRedirect('/newsletter/edit/%s'%(newsletter_id))
    else:
        form = NewsletterForm(instance=newsletter)
        #form = NewsletterForm(instance=newsletter, prefix="newsletter")
        #formset = LinkFormset(instance=newsletter, prefix="links")
        
    return render_to_response("newsletter/newsletter_edit.html",
                              {"form": form,"newsletter":newsletter,
                               #"formset": formset,
                               },
                              context_instance=RequestContext(request))
Beispiel #2
0
def try_to_subscribe(request):
    if request.method == 'POST':
        form = NewsletterForm(request.POST)
        if form.is_valid():
            try:
                newsletter_subscription = NewsletterSubscription.objects.get(email=request.POST['email'])
            except NewsletterSubscription.DoesNotExist:
                newsletter_subscription = NewsletterSubscription(email=request.POST['email'], subscribed=False)
                newsletter_subscription.save()
                newsletter_subscription.set_token()

            subscribe_url = settings.SUBSCRIBE_URL % (settings.SITE_URL, newsletter_subscription.token)

            file = open(settings.TEMPLATE_DIRS[0] + "/newsletter/subscribe_send_token_" + translation.get_language() + ".txt", "r")
            message_txt = file.read()
            file.close()
            message_txt = message_txt.decode("utf-8")
            message_txt = message_txt % (subscribe_url)

            file = open(settings.TEMPLATE_DIRS[0] + "/newsletter/subscribe_send_token_" + translation.get_language() + ".html", "r")
            message_html = file.read()
            file.close()
            message_html = message_html.decode("utf-8")
            message_html = message_html % (subscribe_url, subscribe_url)
            
            print subscribe_url

            subject = "%s %s" % (settings.EMAIL_SUBJECT_PREFIX, unicode(_(u"newsletter subscription")))

            send_mass_email(settings.EMAIL_FROM, [request.POST['email']], None, subject, message_txt, message_html)

            return render_to_response('newsletter/subscription_token_sent_' + translation.get_language() + '.html', { 'SITE_URL': settings.SITE_URL }, context_instance=RequestContext(request))
    else:
        form = NewsletterForm()

    user = request.user

    if user and user.is_authenticated():
        try:
            newsletter_subscription = NewsletterSubscription.objects.get(email=user.email)
            if newsletter_subscription.subscribed == False:
                newsletter_subscription.subscribed = True
                newsletter_subscription.save()
                return render_to_response('newsletter/successfully_subscribed_' + translation.get_language() + '.html', { 'token': newsletter_subscription.token }, context_instance=RequestContext(request))
            else:
                return render_to_response('newsletter/already_subscribed_' + translation.get_language() + '.html', { 'subscription': newsletter_subscription, 'SITE_URL': settings.SITE_URL }, context_instance=RequestContext(request))

        except NewsletterSubscription.DoesNotExist:
            newsletter_subscription = NewsletterSubscription(email=request.POST['email'], subscribed=True)
            newsletter_subscription.save()
            newsletter_subscription.set_token()

    return render_to_response('newsletter/subscribe_' + translation.get_language() + '.html', { 'form': form, 'SITE_URL': settings.SITE_URL }, context_instance=RequestContext(request))
Beispiel #3
0
def cadastrar_newsletter(request):
    if request.method != 'POST':
        response = HttpResponse("Method not allowed.")
        response.status_code = 405
        return response

    form = NewsletterForm(request.POST)
    if form.is_valid():
        form.save()
        out = { 'status' : u'Ok', 'mensagem' : u'E-mail gravado com sucesso!' }
    else:
        out = { 'status' : u'Erro', 'mensagem' : form.errors['email'][0] }

    json_content = json.dumps(out)
    return HttpResponse(json_content, mimetype='application/json')
Beispiel #4
0
def newsletter_add(request):
    if request.method == 'POST':
        form = NewsletterForm(request.POST)

        if form.is_valid():
            #newsl = 
            form.save()

            #return HttpResponseRedirect('/newsletter/edit/%s'%(newsl.id))
            return HttpResponseRedirect('/newsletter/list')
        else:
            return render_to_response('newsletter/newsletter_add.html',
                                    {'form' : form},
                                    context_instance=RequestContext(request))
    else:
        return render_to_response('newsletter/newsletter_add.html',
                                {'form': NewsletterForm()},
                                context_instance=RequestContext(request))
Beispiel #5
0
 def save(self, commit=True):
     super(RegistrationForm, self).save(commit=commit)
     NewsletterForm.save(self)
Beispiel #6
0
def renderLandingPage(request):

    contextDomain = 'kit'
    languageCode = 'en-us'

    data = None
    try:
        data = Context.getProcessedContextDataWithDependencies(
            contextDomain, languageCode)
    except Exception as error:
        raise Http404

    contactForm = None
    newsletterForm = None

    formContext = {
        'request': request,
        'contextDomain': contextDomain,
        'languageCode': languageCode
    }

    context = {
        'contextDomain': contextDomain,
        'contactForm': contactForm,
        'newsletterForm': newsletterForm,
        'data': data,
        'anchor': ''
    }

    if request.method == 'POST':

        if 'company' in request.POST and 'subject' in request.POST:
            # This is contact form
            contactForm = ContactForm(request.POST, **formContext)
            if contactForm.is_valid():
                contactInstance = contactForm.addContact()

                emailDict = buildEmailAsStr(
                    email.CONTACT_EMAIL_TEMPLATE, {
                        'body': {
                            'NAME':
                            contactInstance.name
                            if contactInstance.name else contactInstance.email,
                            'EMAIL':
                            contactInstance.email,
                            'SUBJECT':
                            contactInstance.subject,
                            'MESSAGE':
                            contactInstance.message
                        }
                    })

                sendSimpleEmail(emailDict['fromEmail'], contactInstance.email,
                                emailDict['subject'], emailDict['body'],
                                emailDict['backend'], emailDict['bcc'])

                context = {
                    'contactInstance': contactInstance,
                    'context': data['context']
                }

                return render(
                    request,
                    template_name=
                    'landing-page/landing-page-contact-success-rnd.html',
                    context=context)

            else:
                context['contactForm'] = ContactForm(request.POST,
                                                     **formContext)
                context['newsletterForm'] = NewsletterForm(**formContext)
                context['anchor'] = 'Contact'

        else:
            # This is newsletter form
            newsletterForm = NewsletterForm(request.POST, **formContext)
            if newsletterForm.is_valid():
                newsletterInstance = newsletterForm.addSubscriber()

                emailDict = buildEmailAsStr(
                    email.NEWSLETTER_EMAIL_TEMPLATE, {
                        'body': {
                            'NAME':
                            newsletterInstance.name if newsletterInstance.name
                            else newsletterInstance.email
                        }
                    })

                sendSimpleEmail(emailDict['fromEmail'],
                                newsletterInstance.email, emailDict['subject'],
                                emailDict['body'], emailDict['backend'],
                                emailDict['bcc'])

                context = {
                    'newsletterInstance': newsletterInstance,
                    'context': data['context']
                }

                return render(
                    request,
                    template_name=
                    'landing-page/landing-page-newsletter-success-rnd.html',
                    context=context)

            else:
                context['contactForm'] = ContactForm(**formContext)
                context['newsletterForm'] = NewsletterForm(
                    request.POST, **formContext)
                context['anchor'] = 'Newsletter'

    else:
        rotate_token(request)

        context['contactForm'] = ContactForm(**formContext)
        context['newsletterForm'] = NewsletterForm(**formContext)

    context.update(csrf(request))

    return render(request,
                  template_name='landing-page/landing-page-rnd.html',
                  context=context)
Beispiel #7
0
 def save(self, commit=True):
     super(RegistrationForm, self).save(commit=commit)
     NewsletterForm.save(self)