Template
Add shopper accounts, reviews, tracking, and seed_demo (#9)
Closes #9. Shop-gated buyer accounts, purchase reviews, Stripe customer ids, shipment tracking, slim public contact form, and a template-neutral seed_demo command.
This commit is contained in:
@@ -10,88 +10,9 @@ class ContactForm(forms.Form):
|
||||
("other", "Something else"),
|
||||
]
|
||||
|
||||
first_name = forms.CharField(
|
||||
max_length=100,
|
||||
widget=forms.TextInput(attrs={"class": "form-input", "id": "contact-first-name"}),
|
||||
)
|
||||
last_name = forms.CharField(
|
||||
max_length=100,
|
||||
required=False,
|
||||
widget=forms.TextInput(attrs={"class": "form-input", "id": "contact-last-name"}),
|
||||
)
|
||||
email = forms.EmailField(
|
||||
widget=forms.EmailInput(attrs={"class": "form-input", "id": "contact-email"}),
|
||||
)
|
||||
phone = forms.CharField(
|
||||
max_length=32,
|
||||
required=False,
|
||||
widget=forms.TextInput(attrs={"class": "form-input", "id": "contact-phone"}),
|
||||
)
|
||||
address_line1 = forms.CharField(
|
||||
max_length=200,
|
||||
required=False,
|
||||
label="Street address",
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"class": "form-input",
|
||||
"id": "contact-address-line1",
|
||||
"autocomplete": "off",
|
||||
"data-ac": "line1",
|
||||
}
|
||||
),
|
||||
)
|
||||
address_line2 = forms.CharField(
|
||||
max_length=200,
|
||||
required=False,
|
||||
label="Apt / suite",
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"class": "form-input",
|
||||
"id": "contact-address-line2",
|
||||
"autocomplete": "address-line2",
|
||||
"data-ac": "line2",
|
||||
}
|
||||
),
|
||||
)
|
||||
address_city = forms.CharField(
|
||||
max_length=100,
|
||||
required=False,
|
||||
label="City",
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"class": "form-input",
|
||||
"id": "contact-address-city",
|
||||
"autocomplete": "address-level2",
|
||||
"data-ac": "city",
|
||||
}
|
||||
),
|
||||
)
|
||||
address_state = forms.CharField(
|
||||
max_length=32,
|
||||
required=False,
|
||||
label="State",
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"class": "form-input",
|
||||
"id": "contact-address-state",
|
||||
"autocomplete": "address-level1",
|
||||
"data-ac": "state",
|
||||
}
|
||||
),
|
||||
)
|
||||
address_zip = forms.CharField(
|
||||
max_length=20,
|
||||
required=False,
|
||||
label="ZIP",
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"class": "form-input",
|
||||
"id": "contact-address-zip",
|
||||
"autocomplete": "postal-code",
|
||||
"data-ac": "zip",
|
||||
}
|
||||
),
|
||||
)
|
||||
interest = forms.ChoiceField(
|
||||
choices=INTEREST_CHOICES,
|
||||
widget=forms.Select(attrs={"class": "form-input", "id": "contact-interest"}),
|
||||
|
||||
@@ -17,6 +17,10 @@ class UnderConstructionMiddleware:
|
||||
"/admin/",
|
||||
"/accounts/login",
|
||||
"/accounts/logout",
|
||||
"/account/login",
|
||||
"/account/logout",
|
||||
"/account/register",
|
||||
"/account/password-reset",
|
||||
"/under-construction",
|
||||
"/portal/messaging/webhooks/",
|
||||
"/unsubscribe/",
|
||||
|
||||
@@ -26,8 +26,6 @@ def notify_admins_of_contact_form(lead: Lead) -> bool:
|
||||
return False
|
||||
|
||||
contact = lead.contact
|
||||
name = contact.full_name or "(no name)"
|
||||
phone = contact.phone or "(none)"
|
||||
email = contact.email or "(none)"
|
||||
message = (lead.message or "").strip() or "(no message)"
|
||||
|
||||
@@ -35,27 +33,8 @@ def notify_admins_of_contact_form(lead: Lead) -> bool:
|
||||
portal_path = reverse("leads:detail", kwargs={"pk": lead.pk})
|
||||
portal_url = f"{site}{portal_path}" if site else portal_path
|
||||
|
||||
postal = contact.postal_address or {}
|
||||
address_bits = [
|
||||
postal.get("line1") or "",
|
||||
postal.get("line2") or "",
|
||||
", ".join(
|
||||
part
|
||||
for part in [
|
||||
postal.get("city") or "",
|
||||
postal.get("state") or "",
|
||||
postal.get("zip") or "",
|
||||
]
|
||||
if part
|
||||
),
|
||||
]
|
||||
address = "\n".join(bit for bit in address_bits if bit) or "(none)"
|
||||
|
||||
ctx = email_brand_context(
|
||||
name=name,
|
||||
email=email,
|
||||
phone=phone,
|
||||
address=address,
|
||||
message=message,
|
||||
portal_url=portal_url,
|
||||
)
|
||||
@@ -63,7 +42,7 @@ def notify_admins_of_contact_form(lead: Lead) -> bool:
|
||||
html_content = get_template("emails/contact_email.html").render(ctx)
|
||||
|
||||
mail = EmailMultiAlternatives(
|
||||
subject=f"New contact form inquiry from {name}",
|
||||
subject=f"New contact form inquiry from {email}",
|
||||
body=text_content,
|
||||
from_email=settings.DEFAULT_FROM_EMAIL,
|
||||
to=[to_email],
|
||||
|
||||
@@ -6,20 +6,11 @@
|
||||
<p style="margin:0 0 16px;color:#212121;">Hello,</p>
|
||||
<p style="margin:0 0 24px;color:#212121;">A new contact request was submitted on the site.</p>
|
||||
|
||||
<p class="field-label" style="color:#6b7280;font-size:12px;text-transform:uppercase;letter-spacing:0.6px;margin:0 0 4px;">Name</p>
|
||||
<p class="field-value" style="color:#212121;font-size:15px;margin:0 0 16px;"><strong>{{ name }}</strong></p>
|
||||
|
||||
<p class="field-label" style="color:#6b7280;font-size:12px;text-transform:uppercase;letter-spacing:0.6px;margin:0 0 4px;">Email</p>
|
||||
<p class="field-value" style="color:#212121;font-size:15px;margin:0 0 16px;">
|
||||
<a href="mailto:{{ email }}" style="color:#00626c;text-decoration:none;">{{ email }}</a>
|
||||
</p>
|
||||
|
||||
<p class="field-label" style="color:#6b7280;font-size:12px;text-transform:uppercase;letter-spacing:0.6px;margin:0 0 4px;">Phone</p>
|
||||
<p class="field-value" style="color:#212121;font-size:15px;margin:0 0 16px;">{{ phone }}</p>
|
||||
|
||||
<p class="field-label" style="color:#6b7280;font-size:12px;text-transform:uppercase;letter-spacing:0.6px;margin:0 0 4px;">Address</p>
|
||||
<p class="field-value" style="color:#212121;font-size:15px;margin:0 0 16px;white-space:pre-wrap;">{{ address }}</p>
|
||||
|
||||
<p class="field-label" style="color:#6b7280;font-size:12px;text-transform:uppercase;letter-spacing:0.6px;margin:0 0 4px;">Message</p>
|
||||
<p class="field-value" style="color:#212121;font-size:15px;margin:0 0 16px;white-space:pre-wrap;">{{ message }}</p>
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
New contact form inquiry — {{ brand_name|default:"Monica Dhillon" }}
|
||||
New contact form inquiry — {{ brand_name|default:"Your Company" }}
|
||||
|
||||
Name: {{ name }}
|
||||
Email: {{ email }}
|
||||
Phone: {{ phone }}
|
||||
Address:
|
||||
{{ address }}
|
||||
|
||||
Message:
|
||||
{{ message }}
|
||||
@@ -12,6 +8,6 @@ Message:
|
||||
{% if portal_url %}View in portal: {{ portal_url }}
|
||||
{% endif %}
|
||||
—
|
||||
{{ brand_name|default:"Monica Dhillon" }}
|
||||
{{ site_url|default:"https://mkdrealtor.com" }}
|
||||
{{ brand_name|default:"Your Company" }}
|
||||
{{ site_url|default:"" }}
|
||||
{% if brand_tagline %}{{ brand_tagline }}{% endif %}
|
||||
|
||||
@@ -87,74 +87,13 @@
|
||||
<form class="rd-form contact-message-form" method="post" action="{% url 'public:contact' %}">
|
||||
{% csrf_token %}
|
||||
<div class="row row-10">
|
||||
<div class="col-md-6">
|
||||
<div class="form-wrap">
|
||||
<label class="form-label-outside" for="{{ form.first_name.id_for_label }}">First name</label>
|
||||
{{ form.first_name }}
|
||||
{{ form.first_name.errors }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-wrap">
|
||||
<label class="form-label-outside" for="{{ form.last_name.id_for_label }}">Last name</label>
|
||||
{{ form.last_name }}
|
||||
{{ form.last_name.errors }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-12">
|
||||
<div class="form-wrap">
|
||||
<label class="form-label-outside" for="{{ form.email.id_for_label }}">Email</label>
|
||||
{{ form.email }}
|
||||
{{ form.email.errors }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-wrap">
|
||||
<label class="form-label-outside" for="{{ form.phone.id_for_label }}">Phone</label>
|
||||
{{ form.phone }}
|
||||
{{ form.phone.errors }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<p class="form-label-outside" style="margin:8px 0 4px">Mailing address <span style="font-weight:400;color:#6b7280">(optional — for postcards)</span></p>
|
||||
</div>
|
||||
<div class="col-12" data-address-autocomplete data-suggest-url="{% url 'address_suggest' %}">
|
||||
<div class="form-wrap address-ac-wrap">
|
||||
<label class="form-label-outside" for="{{ form.address_line1.id_for_label }}">Street address</label>
|
||||
{{ form.address_line1 }}
|
||||
{{ form.address_line1.errors }}
|
||||
</div>
|
||||
<div class="row row-10">
|
||||
<div class="col-md-6">
|
||||
<div class="form-wrap">
|
||||
<label class="form-label-outside" for="{{ form.address_line2.id_for_label }}">Apt / suite</label>
|
||||
{{ form.address_line2 }}
|
||||
{{ form.address_line2.errors }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-wrap">
|
||||
<label class="form-label-outside" for="{{ form.address_city.id_for_label }}">City</label>
|
||||
{{ form.address_city }}
|
||||
{{ form.address_city.errors }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-wrap">
|
||||
<label class="form-label-outside" for="{{ form.address_state.id_for_label }}">State</label>
|
||||
{{ form.address_state }}
|
||||
{{ form.address_state.errors }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-wrap">
|
||||
<label class="form-label-outside" for="{{ form.address_zip.id_for_label }}">ZIP</label>
|
||||
{{ form.address_zip }}
|
||||
{{ form.address_zip.errors }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div class="form-wrap">
|
||||
<label class="form-label-outside" for="{{ form.interest.id_for_label }}">I am interested in</label>
|
||||
@@ -173,7 +112,7 @@
|
||||
<div class="col-12">{{ form.captcha }}{{ form.captcha.errors }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<p style="font-size:13px;color:#6b7280;margin:12px 0 20px;">By submitting, you agree I may contact you about your inquiry by email and SMS (if you provide a phone number). You can change preferences or unsubscribe anytime from links in messages, or reply STOP to SMS.{% if form.captcha %} Protected by reCAPTCHA.{% endif %}</p>
|
||||
<p style="font-size:13px;color:#6b7280;margin:12px 0 20px;">By submitting, you agree we may contact you about your inquiry by email. You can change preferences or unsubscribe anytime from links in messages.{% if form.captcha %} Protected by reCAPTCHA.{% endif %}</p>
|
||||
<button class="button button-primary button-winona" type="submit" data-tianji-event="contact_form_submit">Send message</button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -181,9 +120,6 @@
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
{% block extra_head %}
|
||||
<link rel="stylesheet" href="{% static 'css/address-autocomplete.css' %}">
|
||||
{% endblock %}
|
||||
{% block tracking_events %}
|
||||
{% if "sent" in request.GET %}
|
||||
<script>
|
||||
@@ -193,6 +129,3 @@
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block extra_js %}
|
||||
<script src="{% static 'js/address-autocomplete.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
+3
-26
@@ -49,6 +49,7 @@ def robots_txt(request):
|
||||
"Allow: /",
|
||||
"Disallow: /portal/",
|
||||
"Disallow: /accounts/",
|
||||
"Disallow: /account/",
|
||||
"Disallow: /admin/",
|
||||
"Disallow: /api/",
|
||||
f"Sitemap: {site}/sitemap.xml",
|
||||
@@ -99,48 +100,24 @@ def contact(request):
|
||||
form = ContactForm(request.POST)
|
||||
if form.is_valid():
|
||||
data = form.cleaned_data
|
||||
postal = Contact.make_postal_address(
|
||||
line1=data.get("address_line1") or "",
|
||||
line2=data.get("address_line2") or "",
|
||||
city=data.get("address_city") or "",
|
||||
state=data.get("address_state") or "",
|
||||
zip_code=data.get("address_zip") or "",
|
||||
)
|
||||
submitted_email = data["email"].lower()
|
||||
contact_obj, _created, match_reason = upsert_contact(
|
||||
email=submitted_email,
|
||||
first_name=data["first_name"],
|
||||
last_name=data.get("last_name") or "",
|
||||
phone=data.get("phone") or "",
|
||||
postal_address=postal
|
||||
if Contact.postal_address_has_content(postal)
|
||||
else None,
|
||||
source=Contact.Source.CONTACT_FORM,
|
||||
merge_phone_address=False,
|
||||
)
|
||||
ConsentRecord.objects.update_or_create(
|
||||
contact=contact_obj,
|
||||
channel=Channel.EMAIL,
|
||||
defaults={"opted_in": True, "reason": "contact_form"},
|
||||
)
|
||||
if (data.get("phone") or "").strip():
|
||||
ConsentRecord.objects.update_or_create(
|
||||
contact=contact_obj,
|
||||
channel=Channel.SMS,
|
||||
defaults={"opted_in": True, "reason": "contact_form"},
|
||||
)
|
||||
if Contact.postal_address_has_content(postal):
|
||||
ConsentRecord.objects.get_or_create(
|
||||
contact=contact_obj,
|
||||
channel=Channel.POSTCARD,
|
||||
defaults={"opted_in": True, "reason": "contact_form"},
|
||||
)
|
||||
interest = data.get("interest") or ""
|
||||
interest_label = dict(ContactForm.INTEREST_CHOICES).get(interest, interest)
|
||||
body = data.get("message") or ""
|
||||
if interest_label:
|
||||
body = f"Interest: {interest_label}\n\n{body}".strip()
|
||||
if (
|
||||
match_reason in {"phone", "address"}
|
||||
match_reason
|
||||
and (contact_obj.email or "").lower() != submitted_email
|
||||
):
|
||||
body = (
|
||||
|
||||
Reference in New Issue
Block a user