Exemplo n.º 1
0
def contact(request):
    send_error = None
    recipient_email = settings.EMAIL_TO
    if request.method == 'POST':
        send_to = []
        for manager in settings.MANAGERS:
            name, email = manager
            send_to.append(email)

        form = ContactForm(request.POST)
        if form.is_valid():
            data = {'name':form.cleaned_data['name'], 'email': form.cleaned_data['email'], 'message': form.cleaned_data['message']}
            try:
                email_message = settings.EMAIL_TEMPLATE.format(**data)
                bcc = [settings.ADMIN_EMAIL_TO]
                msg = EmailMessage(settings.EMAIL_SUBJECT, email_message, recipient_email, send_to, bcc, 
                        headers = {'Reply-To': data['email']})
                msg.send()
                return HttpResponseRedirect(reverse('contact_success'))
            except:
                send_error = "You contact submission cannot be sent at this time. Send an email to %s and let them know of this error" % (recipient_email)

            form = ContactForm({'name': data['name'], 'email': data['email'], 'message': data['message']})
    else:
        form = ContactForm()

    return render_to_response('contact.html', {'form': form, 'send_status': send_error, 'email': recipient_email}, context_instance=RequestContext(request))
Exemplo n.º 2
0
def contact(request, lang=0, email_response=''):
    '''
		function to show contact view
		lang = 0:Esp, 1:Eng
	'''
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            send_contact_message(request)
            return HttpResponseRedirect('/contacto/gracias')
    else:
        form = ContactForm()

    page = get_lang_labels(
        'esp', 'contacto') if lang == 0 else get_lang_labels('eng', 'contact')
    data = Data.objects.filter(
        section=4).order_by('id') if lang == 0 else Data.objects.filter(
            section=9).order_by('id')
    gral_data = Data.objects.filter(
        section=13) if lang == 0 else Data.objects.filter(section=14)
    year = date.today().year
    main_menu = Section.objects.filter(in_menu=True,
                                       lang=lang).order_by('weight_menu')
    footer_menu = Section.objects.filter(in_footer=True,
                                         lang=lang).order_by('weight_footer')
    question = Question.objects.filter(active=True).order_by('-reg_date')[0]
    answer = question.answer_set.filter(active=True)
    return render_to_response('section/contact.html',
                              locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data

            if cd['subject'] and cd['message'] and cd['email']:
                try:
                    send_mail(
                        cd['subject'],
            cd['email'] + '\n' + cd['message'],
            cd['email'],
            [EMAIL_HOST_USER],
            fail_silently=False,
                        )
                    url = reverse('contact_thank_you')
                    return HttpResponseRedirect(url)
                except BadHeaderError:
                    return HttpResponse('Invalid header found.')
            else:
                return HttpResponse('Make sure all fields are entered.')
    else:
        form = ContactForm()

    return render_to_response('pages/contact.html', {'form':form}, RequestContext(request))
Exemplo n.º 4
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            print "===="
            print form.cleaned_data['message']
            return HttpResponseRedirect('/file_uploads/thanks/')
    else:
        form = ContactForm()

    print "contact.html"

    return render_to_response('file_uploads/contact.html', {'form': form,})
Exemplo n.º 5
0
def contact_form(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            form.send()
            return HttpResponseRedirect('%s?msg=60' % reverse('contact'))
    else:  
        form = ContactForm()
    
    num_msg = int(request.GET.get('msg', 0))
    
    return render_to_response('contact.html', {'form': form, 'num_msg': num_msg}, \
        context_instance=RequestContext(request))  
Exemplo n.º 6
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            send_mail(
                cd['subject'],
                cd['message'],
                cd.get('email', '*****@*****.**'),
                ['*****@*****.**'],
            )
            return HttpResponseRedirect('/contact/thanks/')
    else:
        form = ContactForm(initial={'subject': 'I love your site!'})
    return render(request, 'contact_form.html', {'form': form},context_instance=RequestContext(request))
Exemplo n.º 7
0
def send_message(request):
    context = RequestContext(request)          

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['subject']
            message = form.cleaned_data['message']
            sender = form.cleaned_data['sender']
            
            send_mail(subject, message + " Gonderen: " + sender, sender, ['*****@*****.**'])
            return render_to_response('booksite/index.html', {}, context)
        else:
            print form.errors
    else:
        form = ContactForm()

    return render_to_response('booksite/send_message.html', {'form': form}, context)
Exemplo n.º 8
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            subject = 'Auto-generated email from ChoosingViz'
            message = form.cleaned_data['message']
            sender = form.cleaned_data['sent_from']
            cc_myself = form.cleaned_data['cc_myself']
            recipients = ['*****@*****.**']
            if cc_myself:
                recipients.append(sender)
            # send an email with the information
            send_mail(subject, message, sender, recipients)
            return HttpResponseRedirect('/thanks/')

    else:
        form = ContactForm()
    response_dict = {'form': form,}
    return render(request, 'contact/contact.html',response_dict)
Exemplo n.º 9
0
def contact(request) :
	if request.method == 'POST' :
		form = ContactForm(request.POST)
		if form.is_valid():
			subject = form.cleaned_data['subject']
			message = form.cleaned_data['message']
			sender = form.cleaned_data['sender']
			cc_myself = form.cleaned_data['cc_myself']

			recipients = ['*****@*****.**', '*****@*****.**']
			if cc_myself :
				recipients.append(sender)
			from django.core.mail import send_mail
			send_mail("COGGENE :: "+subject, message, sender, recipients)
			return HttpResponseRedirect('/thanks/')
	else :
		form = ContactForm()
	c = { 'form' : form }
	return render_to_response('templates/contact.html', c, context_instance=RequestContext(request) )
Exemplo n.º 10
0
def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data

            try:
                send_mail(
                    cd['subject'],
                    cd['email'] + '\n' + cd['message'],
                    EMAIL_HOST_USER,
                    [EMAIL_HOST_USER]
                    )
                url = reverse('contact_thank_you')
                return HttpResponseRedirect(url)
            except BadHeaderError:
                return HttpResponse('Invalid header found.')
    else:
        form = ContactForm()

    return render(request, 'pages/contact.html', {'form':form})
Exemplo n.º 11
0
def contact(request):
    if request.method == 'POST': # If the form has been submitted...

        form = ContactForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            email = form.cleaned_data['email']
            subject = 'A message from your site'
            message = form.cleaned_data['message']
            recipients = ['*****@*****.**']

            from django.core.mail import send_mail
            send_mail(subject, message, email, recipients)
            return HttpResponseRedirect('/thanks/') # Redirect after POST

    else:
        form = ContactForm() # An unbound form

    return render(request, 'contact/contact.html', {
        'form': form,
    })
Exemplo n.º 12
0
def contact(request, lang=0, email_response=''):
	'''
		function to show contact view
		lang = 0:Esp, 1:Eng
	'''
	if request.method == 'POST':
		form = ContactForm(request.POST)
		if form.is_valid():
			send_contact_message(request)
			return HttpResponseRedirect('/contacto/gracias')
	else:
		form = ContactForm()

	page = get_lang_labels('esp','contacto') if lang == 0 else get_lang_labels('eng','contact')
	data = Data.objects.filter(section=4).order_by('id') if lang == 0 else Data.objects.filter(section=9).order_by('id')
	gral_data = Data.objects.filter(section=13) if lang == 0 else Data.objects.filter(section=14)
	year = date.today().year
	main_menu = Section.objects.filter(in_menu=True, lang=lang).order_by('weight_menu')
	footer_menu = Section.objects.filter(in_footer=True, lang=lang).order_by('weight_footer')
	question = Question.objects.filter(active=True).order_by('-reg_date')[0]
	answer = question.answer_set.filter(active=True)
	return render_to_response('section/contact.html', locals(), context_instance=RequestContext(request))
Exemplo n.º 13
0
def index():
    if request.method == 'POST':
        name = urllib.parse.quote(request.form['name'])
        email = request.form['email']
        message = urllib.parse.quote(request.form['message'])
        msg = MIMEText(message, 'plain', _charset='utf-8')
        msg['Subject'] = Header('МК', 'utf-8')
        msg['From'] = XXX
        msg['To'] = email
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.starttls()
        server.login(XXX, XXX)
        server.sendmail(msg['From'], email, msg.as_string())
        server.quit()
        return redirect('/')
    e_form = ContactForm()
    return render_template('index.html', e_form=e_form)
Exemplo n.º 14
0
def index(request): # наша вьюшка
    all_is_right = ''

    if request.method == 'POST': # пару проверок формы
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save() # сохраняем нашу форму в базу
            all_is_right = u"Ваше сообщение успешно отправлено."
            form = ContactForm() # очищаем форму
    else:
        form = ContactForm()
    return render(request, 'contacts.html', {
        'form': form,
        'all_is_right': all_is_right,
        })