generic contact form
This commit is contained in:
parent
eece05af74
commit
2cbcc4ba98
9 changed files with 280 additions and 48 deletions
|
@ -91,3 +91,54 @@ def create_lead(request, slug):
|
|||
def thank_you(request, slug):
|
||||
service = get_object_or_404(Service, slug=slug)
|
||||
return render(request, "services/thank_you.html", {"service": service})
|
||||
|
||||
|
||||
def contact(request):
|
||||
if request.method == "POST":
|
||||
form = LeadForm(request.POST)
|
||||
if form.is_valid():
|
||||
# Create a minimal Lead object
|
||||
from hub.services.models import Lead
|
||||
|
||||
lead = Lead(
|
||||
name=form.cleaned_data["name"],
|
||||
email=form.cleaned_data["email"],
|
||||
message=form.cleaned_data["message"],
|
||||
company=form.cleaned_data["company"],
|
||||
phone=form.cleaned_data["phone"],
|
||||
)
|
||||
|
||||
try:
|
||||
logger.info(f"Attempting to create contact lead from {lead.name}")
|
||||
odoo = OdooAPI()
|
||||
odoo_lead_id = odoo.create_lead(lead, source="contact_form")
|
||||
lead.odoo_lead_id = odoo_lead_id
|
||||
lead.save()
|
||||
|
||||
logger.info(
|
||||
f"Successfully created contact lead with Odoo ID: {odoo_lead_id}"
|
||||
)
|
||||
messages.success(
|
||||
request, "Thank you for your message. We'll get back to you soon!"
|
||||
)
|
||||
return redirect("services:contact_thank_you")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create contact lead: {str(e)}", exc_info=True)
|
||||
error_message = "Sorry, there was an error processing your request. Please try again later."
|
||||
|
||||
if settings.DEBUG:
|
||||
error_message += f" Error: {str(e)}"
|
||||
|
||||
messages.error(request, error_message)
|
||||
else:
|
||||
form = LeadForm()
|
||||
|
||||
context = {
|
||||
"form": form,
|
||||
}
|
||||
return render(request, "services/contact_form.html", context)
|
||||
|
||||
|
||||
def contact_thank_you(request):
|
||||
return render(request, "services/contact_thank_you.html")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue