Replace contact page with contact email address

This commit is contained in:
Nathan Chapman 2022-07-14 19:28:49 -06:00
parent 0562cea479
commit 298998324c
9 changed files with 6 additions and 195 deletions

View File

@ -215,52 +215,6 @@ input[type=submit]:hover,
font-weight: bold;
}
/* Contact form
========================================================================== */
.contact-form {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 0 2rem;
}
.contact-form p:nth-child(6) {
grid-column: span 2;
}
.contact-form #id_captcha {
margin-bottom: 1rem;
display: flex;
justify-content: flex-end;
}
.contact-form div:last-child {
grid-column: 2;
}
.contact-form label {
display: block;
}
:is(.contact-form) input, select, textarea {
width: 100%;
}
@media screen and (max-width: 600px) {
.contact-form {
grid-template-columns: 1fr;
}
.contact-form p:nth-child(6),
.contact-form div:last-child {
grid-column: 1;
}
}
figure {
margin: 0;
padding: 0;

View File

@ -13,8 +13,6 @@ from captcha.fields import CaptchaField
from core.models import Order
from core import CoffeeGrind, ShippingContainer
from .tasks import contact_form_email
logger = logging.getLogger(__name__)
@ -137,34 +135,3 @@ class OrderCreateForm(forms.ModelForm):
class CouponApplyForm(forms.Form):
code = forms.CharField(label='Coupon code')
class ContactForm(forms.Form):
GOOGLE = 'Google Search'
SHOP = 'The coffee shop'
WOM = 'Word of mouth'
PRODUCT = 'Coffee Bag'
STORE = 'Store'
OTHER = 'Other'
REFERAL_CHOICES = [
(GOOGLE, 'Google Search'),
(SHOP, '"Better Living Through Coffee" coffee shop'),
(WOM, 'Friend/Relative'),
(PRODUCT, 'Our Coffee Bag'),
(STORE, 'PT Food Coop/other store'),
(OTHER, 'Other (please describe below)'),
]
full_name = forms.CharField()
email_address = forms.EmailField()
referal = forms.ChoiceField(
label='How did you find our website?',
choices=REFERAL_CHOICES
)
subject = forms.CharField()
message = forms.CharField(widget=forms.Textarea)
captcha = CaptchaField()
def send_email(self):
contact_form_email.delay(self.cleaned_data)

View File

@ -6,26 +6,3 @@ from django.core.mail import EmailMessage, send_mail
from templated_email import send_templated_mail
logger = get_task_logger(__name__)
CONTACT_FORM_TEMPLATE = 'storefront/contact_form'
@shared_task(name='contact_form_email')
def contact_form_email(formdata):
with open(f'{settings.BASE_DIR.parent}/.blacklist') as blacklist:
if formdata.get('email_address') not in blacklist.read():
send_templated_mail(
template_name=CONTACT_FORM_TEMPLATE,
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[settings.DEFAULT_CONTACT_EMAIL],
context=formdata
)
logger.info(
f"Contact form email sent from {formdata['email_address']}"
)
else:
logger.warn(
f"{formdata['email_address']} tried to send an email but was on the blacklist"
)

View File

@ -17,7 +17,7 @@
<input type="submit" value="Continue">
</p>
</form>
<p>We validate addresses with USPS, if you are having issues please contact us at <a href="mailto:support@ptcoffee.com">support@ptcoffee.com</a> or use the contact information found on our <a href="{% url 'storefront:contact' %}">contact</a> page.</p>
<p>We validate addresses with USPS, if you are having issues please contact us at <a href="mailto:support@ptcoffee.com">support@ptcoffee.com</a>.</p>
</section>
</article>
{% endblock %}

View File

@ -1,57 +0,0 @@
{% extends "base.html" %}
{% block head_title %}Contact | {% endblock %}
{% block content %}
<div class="site__banner site__banner--site">
<h1>Contact us</h1>
</div>
<article>
<header>
<h4>Problem with your online order or have a question?</h4>
<p>
Please contact us, were happy to help you over the phone<br>
<a href="tel:+13603855856">(360) 385-5856</a> Mon-Fri between 9:00 am and 5:00 pm Pacific Time.
</p>
<p>Or send us a message using the form below and we'll email you back as soon as we can.</p>
</header>
<section>
<form action="{% url 'storefront:contact' %}" method="post" class="contact-form">
{% csrf_token %}
{{ form.non_field_errors }}
<p>
{{ form.full_name.errors }}
<label for="{{ form.full_name.id_for_label }}">Full name:</label>
{{ form.full_name }}
</p>
<p>
{{ form.email_address.errors }}
<label for="{{ form.email_address.id_for_label }}">Email address</label>
{{ form.email_address }}
</p>
<p>
{{ form.referal.errors }}
<label for="{{ form.referal.id_for_label }}">How did you find our website?</label>
{{ form.referal }}
</p>
<p>
{{ form.subject.errors }}
<label for="{{ form.subject.id_for_label }}">Subject:</label>
{{ form.subject }}
</p>
<p>
{{ form.message.errors }}
<label for="{{ form.message.id_for_label }}">Message:</label>
{{ form.message }}
</p>
<div>
{{ form.captcha.errors }}
<p>
{{ form.captcha }}
</p>
<p><input type="submit" value="Send message"></p>
</div>
</form>
</section>
</article>
{% endblock %}

View File

@ -20,7 +20,7 @@ from storefront.views import (
PaymentDoneView, PaymentCanceledView,
CustomerDetailView, CustomerUpdateView, OrderDetailView,
CustomerAddressCreateView, CustomerAddressUpdateView,
AboutView, FairTradeView, ReviewListView, ContactFormView,
AboutView, FairTradeView, ReviewListView,
)
from storefront.cart import Cart
@ -426,21 +426,3 @@ class ReviewListViewTest(TestCase):
response = self.client.get(reverse('storefront:reviews'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'storefront/reviews.html')
class ContactFormViewTest(TestCase):
def setUp(self):
self.client = Client()
def test_view_url_exists_at_desired_location(self):
response = self.client.get('/contact/')
self.assertEqual(response.status_code, 200)
def test_view_url_accessible_by_name(self):
response = self.client.get(reverse('storefront:contact'))
self.assertEqual(response.status_code, 200)
def test_view_uses_correct_template(self):
response = self.client.get(reverse('storefront:contact'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'storefront/contact_form.html')

View File

@ -5,7 +5,6 @@ urlpatterns = [
path('about/', views.AboutView.as_view(), name='about'),
path('fair-trade/', views.FairTradeView.as_view(), name='fair-trade'),
path('reviews/', views.ReviewListView.as_view(), name='reviews'),
path('contact/', views.ContactFormView.as_view(), name='contact'),
path('', views.ProductListView.as_view(), name='product-list'),
path('products/<int:pk>/', include([

View File

@ -36,7 +36,7 @@ from core import OrderStatus, ShippingContainer
from .forms import (
AddToCartForm, UpdateCartItemForm, OrderCreateForm,
AddressForm, CouponApplyForm, ContactForm, CheckoutShippingForm,
AddressForm, CouponApplyForm, CheckoutShippingForm,
)
from .cart import Cart
from .payments import CaptureOrder
@ -491,14 +491,3 @@ class FairTradeView(TemplateView):
class ReviewListView(TemplateView):
template_name = 'storefront/reviews.html'
class ContactFormView(FormView, SuccessMessageMixin):
template_name = 'storefront/contact_form.html'
form_class = ContactForm
success_url = reverse_lazy('storefront:product-list')
success_message = 'Message sent.'
def form_valid(self, form):
form.send_email()
return super().form_valid(form)

View File

@ -51,7 +51,7 @@
<li><a class="nav__link" href="{% url 'storefront:reviews' %}">Reviews</a></li>
<li><a class="nav__link" href="{% url 'storefront:about' %}">About</a></li>
<li><a class="nav__link" href="https://bltcoffee.com/">Cafe</a></li>
<li><a class="nav__link" href="{% url 'storefront:contact' %}">Contact</a></li>
<li><a class="nav__link" href="mailto:support@ptcoffee.com">Contact</a></li>
</ul>
{% if user.is_authenticated %}
<div class="nav__menu nav__account">
@ -93,13 +93,13 @@
<p><button class="show-modal">Subscribe to our newsletter</button></p>
<p>
<strong>Problem with your online order or have a question?</strong><br>
Please <a href="{% url 'storefront:contact' %}">contact us</a>, were happy to help you over the phone at <a href="tel:+13603855856">(360) 385-5856</a><br>
Please <a href="mailto:support@ptcoffee.com">contact us</a>, were happy to help you over the phone at <a href="tel:+13603855856">(360) 385-5856</a><br>
Mon-Fri between 9:00 am and 5:00 pm Pacific Time.<br>
<address>854 East Park Ave. Suite 1, Port Townsend, WA 98368</address>
</p>
<p>
Better Living Food Company Inc.℠<br>
<small><a href="{% url 'storefront:contact' %}">Contact</a>&nbsp;|&nbsp;Fair Trade&nbsp;|&nbsp;Organic</small>
<small><a href="mailto:support@ptcoffee.com">Contact</a>&nbsp;|&nbsp;Fair Trade&nbsp;|&nbsp;Organic</small>
<br>
<small>Website by <a href="https://nathanjchapman.com">Nathan Chapman</a></small>
<br><br>