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))
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))
def index(request): projects = project.objects.all() servicio = Servicio.objects.all() contact_form = ContactoForm(data=request.POST) cotizacion = CotizacionForm(data=request.POST) if cotizacion.is_valid(): nombre_f = request.POST.get('nombre_c', '') apellido_f = request.POST.get('apellido', '') rut_f = request.POST.get('rut', '') empresa_f = request.POST.get('empresa', '') email_f = request.POST.get('email_c', '') servicio_f = request.POST.get('servicio', '') telefono_f = request.POST.get('telefono', '') try: b = Cliente(rut=rut_f, nombre=nombre_f, apellido=apellido_f, correo=email_f, telefono=telefono_f, empresa=empresa_f) c = Cotizacion(cliente=b, servicio=servicio_f, estado=False) b.save() c.save() return redirect(reverse('home')) except: return redirect(reverse('home')) if contact_form.is_valid(): nombre = request.POST.get('nombre', '') email = request.POST.get('email', '') asunto = request.POST.get('asunto', '') mensaje = request.POST.get('mensaje', '') #Enviar Correo email = EmailMessage("Consulta: " + asunto, "De {} <{}\n\nEscribio:\n\n{}".format( nombre, email, mensaje), "no-contestar", ["*****@*****.**"], reply_to=[email]) try: email.send() return redirect(reverse('home')) except: #Algo no ha ido bien return redirect(reverse('home')) return render( request, "base/index.html", { 'projects': projects, 'form': contact_form, 'servicios': servicio, 'form_c': cotizacion })
def contacto(request): if request.method == 'POST': form = ContactoForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( cd['asunto'], cd['mensaje'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('general/contacto/thanks/') else: form = ContactoForm( initial={'asunto': 'Me encanta este sitio.'} ) return render_to_response('general/contacto.html', {'form': form})
def contacto(request): if request.method == 'POST': form = ContactoForm(request.POST) if form.is_valid(): meta = request.META g = GeoIP() x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') if x_forwarded_for: ip = x_forwarded_for.split(',')[0] else: ip = request.META.get('REMOTE_ADDR') print ip info = g.city(ip) coordenadas = g.lat_lon(ip) datos = form.cleaned_data coordenadas = '''\nCodigo de Continente : %s\n \nCodigo Pais : %s\n \nPais : %s\n \nRegion : %s\n \nCiudad : %s\n \nCodigo Postal : %s\n \ncoordenadas : %s'''%( info['continent_code'] , info['country_code'] , info['country_name'] , info['region'] , info['city'] , info['postal_code'] , coordenadas ) metadata = str('\n\n\n Favor de no responder al servidor , responder al email del cliente \n\nEmail del cliente : %s\nEmpresa : %s \n\nMETADATA\n\nNavegador : %s\nDireccion : %s\n' % (datos['email'],datos['empresa'] , meta['HTTP_USER_AGENT'] , meta['REMOTE_ADDR'] ,) ) #print metadata send_mail(str('MENSAJE DE SERVIDOR |'+datos['asunto']) , str(datos['mensaje']+metadata+coordenadas), '*****@*****.**', ['*****@*****.**','*****@*****.**','*****@*****.**']) return HttpResponseRedirect('/contacto/gracias/') else: form = ContactoForm() #return render(request , 'formulario_contacto.html' ,{'form':form}) return render(request , 'contacto_formulario.html' , {'subtitulo' : 'Formulario de contacto' , 'login': request.user.is_authenticated(), 'form': form ,'title' : 'Contacto | Borbolla Metrology' , 'texto': 'Porfavor llena el siguiente formulario , es importante que incluyas un correo real , ya que por este medio nos comunicaremos con tigo', })
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)
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)
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