move plan choice into form
This commit is contained in:
parent
928bd0818e
commit
aa4ec33c93
4 changed files with 56 additions and 7 deletions
|
@ -54,6 +54,17 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if choices %}
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="id_choice" class="form-label">{{ choice_label|default:"Please Select" }}</label>
|
||||||
|
<select name="selected_choice" id="id_choice" class="form-control">
|
||||||
|
{% for choice_id, choice_name in choices %}
|
||||||
|
<option value="{{ choice_id }}|{{ choice_name }}">{{ choice_name }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="id_message" class="form-label">Your Message (Optional)</label>
|
<label for="id_message" class="form-label">Your Message (Optional)</label>
|
||||||
{{ form.message|addclass:"form-control" }}
|
{{ form.message|addclass:"form-control" }}
|
||||||
|
|
|
@ -149,11 +149,6 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<h4 class="mb-3">Order This Plan</h4>
|
|
||||||
{% load contact_tags %}
|
|
||||||
{% embedded_contact_form source="Plan Order" service=offering.service offering_id=offering.id plan_id=plan.id %}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
|
@ -167,6 +162,18 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if offering.plans.exists %}
|
||||||
|
<div class="pt-40">
|
||||||
|
<h4 class="fs-22 fw-semibold lh-1 mb-12">I'm interested in a plan</h4>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
{% load contact_tags %}
|
||||||
|
{% embedded_contact_form source="Plan Order" service=offering.service offering_id=offering.id choices=offering.plans.all choice_label="Select a Plan" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,7 +8,14 @@ register = template.Library()
|
||||||
|
|
||||||
@register.inclusion_tag("services/embedded_contact_form.html", takes_context=True)
|
@register.inclusion_tag("services/embedded_contact_form.html", takes_context=True)
|
||||||
def embedded_contact_form(
|
def embedded_contact_form(
|
||||||
context, source=None, details=None, service=None, offering_id=None, plan_id=None
|
context,
|
||||||
|
source=None,
|
||||||
|
details=None,
|
||||||
|
service=None,
|
||||||
|
offering_id=None,
|
||||||
|
plan_id=None,
|
||||||
|
choices=None,
|
||||||
|
choice_label=None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Renders an embedded contact form with optional service context information.
|
Renders an embedded contact form with optional service context information.
|
||||||
|
@ -17,6 +24,7 @@ def embedded_contact_form(
|
||||||
{% load contact_tags %}
|
{% load contact_tags %}
|
||||||
{% embedded_contact_form source="Partner Page" details="ACME Corp" %}
|
{% embedded_contact_form source="Partner Page" details="ACME Corp" %}
|
||||||
{% embedded_contact_form service=service offering_id=offering.id plan_id=plan.id %}
|
{% embedded_contact_form service=service offering_id=offering.id plan_id=plan.id %}
|
||||||
|
{% embedded_contact_form service=service offering_id=offering.id choices=offering.plans.all choice_label="Select a Plan" %}
|
||||||
"""
|
"""
|
||||||
request = context["request"]
|
request = context["request"]
|
||||||
form = LeadForm()
|
form = LeadForm()
|
||||||
|
@ -25,6 +33,11 @@ def embedded_contact_form(
|
||||||
offering_obj = None
|
offering_obj = None
|
||||||
plan_obj = None
|
plan_obj = None
|
||||||
|
|
||||||
|
# Process choices if they're QuerySet objects (like plans)
|
||||||
|
processed_choices = None
|
||||||
|
if choices:
|
||||||
|
processed_choices = [(str(choice.id), choice.name) for choice in choices]
|
||||||
|
|
||||||
# Resolve service/offering/plan objects if IDs provided
|
# Resolve service/offering/plan objects if IDs provided
|
||||||
if service and isinstance(service, str):
|
if service and isinstance(service, str):
|
||||||
try:
|
try:
|
||||||
|
@ -56,4 +69,6 @@ def embedded_contact_form(
|
||||||
"offering": offering_obj,
|
"offering": offering_obj,
|
||||||
"plan": plan_obj,
|
"plan": plan_obj,
|
||||||
"request": request,
|
"request": request,
|
||||||
|
"choices": processed_choices,
|
||||||
|
"choice_label": choice_label,
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ def contact_form(request):
|
||||||
lead = Lead(
|
lead = Lead(
|
||||||
name=form.cleaned_data["name"],
|
name=form.cleaned_data["name"],
|
||||||
email=form.cleaned_data["email"],
|
email=form.cleaned_data["email"],
|
||||||
message=form.cleaned_data["message"],
|
message=form.cleaned_data["message"] or "",
|
||||||
company=form.cleaned_data["company"],
|
company=form.cleaned_data["company"],
|
||||||
phone=form.cleaned_data["phone"],
|
phone=form.cleaned_data["phone"],
|
||||||
)
|
)
|
||||||
|
@ -87,6 +87,22 @@ def contact_form(request):
|
||||||
if plan_name:
|
if plan_name:
|
||||||
service_info.append(f"Plan: {plan_name}")
|
service_info.append(f"Plan: {plan_name}")
|
||||||
|
|
||||||
|
# Handle selected choice if present
|
||||||
|
selected_choice = request.POST.get("selected_choice", "")
|
||||||
|
if selected_choice:
|
||||||
|
try:
|
||||||
|
choice_id, choice_name = selected_choice.split("|", 1)
|
||||||
|
# Add selected choice to message
|
||||||
|
service_info.append(f"Selected Plan: {choice_name}")
|
||||||
|
|
||||||
|
# Try to set the plan based on the choice_id
|
||||||
|
try:
|
||||||
|
lead.plan = Plan.objects.get(id=choice_id)
|
||||||
|
except Plan.DoesNotExist:
|
||||||
|
pass
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
if service_info:
|
if service_info:
|
||||||
context_info.append("Service Information: " + ", ".join(service_info))
|
context_info.append("Service Information: " + ", ".join(service_info))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue