2020-11-15 02:22:03 -03:00
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from gestionPedidos.models import Articulos
|
2020-11-15 03:46:07 -03:00
|
|
|
from django.core.mail import send_mail
|
|
|
|
from django.conf import settings
|
2020-11-15 15:53:34 -03:00
|
|
|
from gestionPedidos.forms import FormContacto
|
2020-11-15 02:22:03 -03:00
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
def busqueda_productos(request):
|
|
|
|
return render(request, "busqueda_prods.html")
|
|
|
|
|
|
|
|
def buscar(request):
|
|
|
|
# Validación campo vacio
|
|
|
|
if request.GET["prod"]:
|
|
|
|
prod_buscar = request.GET["prod"]
|
|
|
|
if len(prod_buscar) > 20:
|
|
|
|
msj = "Termino de búsqueda demasiado largo"
|
|
|
|
else:
|
|
|
|
articulos = Articulos.objects.filter(nombre__icontains=prod_buscar)
|
|
|
|
return render(request, "resultado_busqueda.html", {"articulos":articulos, "query":prod_buscar})
|
|
|
|
else:
|
|
|
|
msj = "Debes introducir un termino de búsqueda"
|
|
|
|
return HttpResponse(msj)
|
|
|
|
|
|
|
|
|
2020-11-15 15:53:34 -03:00
|
|
|
# def contacto(request):
|
|
|
|
# if request.method == "POST":
|
|
|
|
# subject = request.POST['asunto']
|
|
|
|
# message = request.POST['mensaje']+' '+request.POST['mail']
|
|
|
|
# email_from = settings.EMAIL_HOST_USER
|
|
|
|
# recipient_list = ['ratablastard@gmail.com']
|
|
|
|
# send_mail(subject, message, email_from, recipient_list)
|
|
|
|
# return render(request, "gracias.html")
|
|
|
|
# return render(request, "contacto.html")
|
|
|
|
|
2020-11-15 02:22:03 -03:00
|
|
|
def contacto(request):
|
|
|
|
if request.method == "POST":
|
2020-11-15 15:53:34 -03:00
|
|
|
miForm = FormContacto(request.POST)
|
|
|
|
if miForm.is_valid():
|
|
|
|
contenido = miForm.cleaned_data
|
|
|
|
|
|
|
|
send_mail(contenido['asunto'], contenido['msj'],
|
|
|
|
contenido.get('email',''),['ratablastard@gmail.com'],)
|
|
|
|
|
|
|
|
return render(request, 'gracias.html')
|
|
|
|
else:
|
|
|
|
miForm = FormContacto()
|
|
|
|
|
|
|
|
return render(request, 'form_contacto.html', {"form":miForm})
|