コード例 #1
0
def agregar(request):
	if request.method == 'POST':
		frm = ContactoForm(request.POST)
		if frm.is_valid():
			frm.save()
			return HttpResponseRedirect("/contacto")
	else:
		frm = ContactoForm()
	return render_to_response("contacto/agregar.html", { "frm": frm }, context_instance=RequestContext(request))
コード例 #2
0
def editar(request, id):
	contacto = Contacto.objects.get(pk=id)
	if request.method == 'POST':
		frm = ContactoForm(request.POST, instance=contacto)
		if frm.is_valid():
			frm.save()
			return HttpResponseRedirect("/contacto")
	else:
		frm = ContactoForm(instance=contacto)
	return render_to_response("contacto/editar.html", { "frm": frm }, context_instance=RequestContext(request))
コード例 #3
0
def contacto(request):
    if request.method == "POST":
        contact = ContactoForm(request.POST)
        mensaje_enviado = 'enviando/'
        if contact.is_valid():
            c = contact.save(commit=False)
            c.save()
            to_mail = c.email
            subject, from_email, to = 'Copia Mensaje [email protected]', '*****@*****.**', to_mail,
            text_content = 'Gracias por inscribirte'
            html_content = '<h1>Copia del mensaje en [email protected]:</h1><br><p><strong>Mensaje: </strong><br>' + c.mensaje + '</p><br><p><strong>De: </strong>' + c.nombre + '(' + c.email + ')</p>'
            msg = EmailMultiAlternatives(subject, text_content, from_email,
                                         [to])
            msg.attach_alternative(html_content, "text/html")
            msg.send()
            to_mail = '*****@*****.**'
            subject, from_email, to = 'Copia Mensaje [email protected]', '*****@*****.**', to_mail,
            text_content = 'Gracias por inscribirte'
            html_content = '<h1>Copia del mensaje en [email protected]:</h1><br><p><strong>Mensaje: </strong><br>' + c.mensaje + '</p><br><p><strong>De: </strong>' + c.nombre + '(' + c.email + ')</p>'
            msg = EmailMultiAlternatives(subject, text_content, from_email,
                                         [to])
            msg.attach_alternative(html_content, "text/html")
            msg.send()
            print('Enviado :v')
            return redirect(mensaje_enviado)
    else:
        contact = ContactoForm()
    context = {
        'form': contact,
    }
    return render(request, 'form_contacto.html', context)
コード例 #4
0
ファイル: views.py プロジェクト: paulpopaul/skeletonweb
def index(request):
    form = ContactoForm()
    if request.method == 'POST':
        form = ContactoForm(request.POST or NONE)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.save()
            to_mail = ['*****@*****.**']
            subject = "Web Mail x"
            from_email = settings.DEFAULT_FROM_EMAIL
            context = {
                'nombre': instance.nombre,
                'email': instance.email,
                'asunto': instance.asunto,
                'mensaje': instance.mensaje
            }
            with open(settings.BASE_DIR + "/skeletonweb/templates/mail/contacto.txt") as f:
                signup_message = f.read()
            html_template = get_template("mail/contacto.html").render(context)
            message = EmailMultiAlternatives(subject=subject, body=signup_message, from_email=from_email, to=to_mail)
            message.attach_alternative(html_template, "text/html")
            message.send()
            messages.success(request, "Tu mensaje ha sido recibido")
            return redirect("/")

    context = {'form':form}
    return render(request,'index.html',context)  
コード例 #5
0
def contacto(request):
    if request.method == "POST":
        contact = ContactoForm(request.POST or None)
        enviando = '/enviando/'

        if contact.is_valid():
            instance = contact.save(commit=False)
            instance.save()
            to_mail = [instance.email]
            subject = "Copia: Nuevo Mensaje | Murtao Web Mail"
            from_email = settings.DEFAULT_FROM_EMAIL
            context = {
                'nombre': instance.nombre,
                'apellido': instance.apellido,
                'celular': instance.celular,
                'email': instance.email,
                'mensaje': instance.mensaje,
                'fecha': instance.fecha,
            }
            with open(settings.BASE_DIR +
                      "/templates/contactoapp/contacto_template_detail.txt"
                      ) as f:
                signup_message = f.read()
            html_template = get_template(
                "contactoapp/contacto_template_detail.html").render(context)
            message = EmailMultiAlternatives(subject=subject,
                                             body=signup_message,
                                             from_email=from_email,
                                             to=to_mail)
            message.attach_alternative(html_template, "text/html")
            message.send()

            subject = "Copia: Nuevo Mensaje | Murtao Web Mail"
            from_email = settings.DEFAULT_FROM_EMAIL
            to_mail = ['*****@*****.**']
            with open(settings.BASE_DIR +
                      "/templates/contactoapp/contacto_template_detail.txt"
                      ) as f:
                signup_message = f.read()
            html_template = get_template(
                "contactoapp/contacto_template_detail.html").render(context)
            message = EmailMultiAlternatives(subject=subject,
                                             body=signup_message,
                                             from_email=from_email,
                                             to=to_mail)
            message.attach_alternative(html_template, "text/html")
            message.send()

            return redirect(enviando)
    else:
        contact = ContactoForm()
    return contact