From 298998324c9def364028072f1c72a52b802bfc41 Mon Sep 17 00:00:00 2001 From: Nathan Chapman Date: Thu, 14 Jul 2022 19:28:49 -0600 Subject: [PATCH] Replace contact page with contact email address --- src/static/styles/main.css | 46 --------------- src/storefront/forms.py | 33 ----------- src/storefront/tasks.py | 23 -------- .../storefront/checkout_address.html | 2 +- .../templates/storefront/contact_form.html | 57 ------------------- src/storefront/tests/test_views.py | 20 +------ src/storefront/urls.py | 1 - src/storefront/views.py | 13 +---- src/templates/base.html | 6 +- 9 files changed, 6 insertions(+), 195 deletions(-) delete mode 100644 src/storefront/templates/storefront/contact_form.html diff --git a/src/static/styles/main.css b/src/static/styles/main.css index 2da802d..be9d5f3 100644 --- a/src/static/styles/main.css +++ b/src/static/styles/main.css @@ -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; diff --git a/src/storefront/forms.py b/src/storefront/forms.py index bf43d34..5a59231 100644 --- a/src/storefront/forms.py +++ b/src/storefront/forms.py @@ -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) diff --git a/src/storefront/tasks.py b/src/storefront/tasks.py index ba0cdab..7bda8fa 100644 --- a/src/storefront/tasks.py +++ b/src/storefront/tasks.py @@ -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" - ) diff --git a/src/storefront/templates/storefront/checkout_address.html b/src/storefront/templates/storefront/checkout_address.html index a618114..0f3e334 100644 --- a/src/storefront/templates/storefront/checkout_address.html +++ b/src/storefront/templates/storefront/checkout_address.html @@ -17,7 +17,7 @@

-

We validate addresses with USPS, if you are having issues please contact us at support@ptcoffee.com or use the contact information found on our contact page.

+

We validate addresses with USPS, if you are having issues please contact us at support@ptcoffee.com.

{% endblock %} diff --git a/src/storefront/templates/storefront/contact_form.html b/src/storefront/templates/storefront/contact_form.html deleted file mode 100644 index b180cca..0000000 --- a/src/storefront/templates/storefront/contact_form.html +++ /dev/null @@ -1,57 +0,0 @@ -{% extends "base.html" %} - -{% block head_title %}Contact | {% endblock %} - -{% block content %} -
-

Contact us

-
-
-
-

Problem with your online order or have a question?

-

- Please contact us, we’re happy to help you over the phone
- (360) 385-5856 Mon-Fri between 9:00 am and 5:00 pm Pacific Time. -

-

Or send us a message using the form below and we'll email you back as soon as we can.

-
-
-
- {% csrf_token %} - {{ form.non_field_errors }} -

- {{ form.full_name.errors }} - - {{ form.full_name }} -

-

- {{ form.email_address.errors }} - - {{ form.email_address }} -

-

- {{ form.referal.errors }} - - {{ form.referal }} -

-

- {{ form.subject.errors }} - - {{ form.subject }} -

-

- {{ form.message.errors }} - - {{ form.message }} -

-
- {{ form.captcha.errors }} -

- {{ form.captcha }} -

-

-
-
-
-
-{% endblock %} diff --git a/src/storefront/tests/test_views.py b/src/storefront/tests/test_views.py index 1b29480..dbade8b 100644 --- a/src/storefront/tests/test_views.py +++ b/src/storefront/tests/test_views.py @@ -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') diff --git a/src/storefront/urls.py b/src/storefront/urls.py index 534df8b..3c13553 100644 --- a/src/storefront/urls.py +++ b/src/storefront/urls.py @@ -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//', include([ diff --git a/src/storefront/views.py b/src/storefront/views.py index 82c0e33..541edc7 100644 --- a/src/storefront/views.py +++ b/src/storefront/views.py @@ -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) diff --git a/src/templates/base.html b/src/templates/base.html index c303547..05f88a8 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -51,7 +51,7 @@
  • Reviews
  • About
  • Cafe
  • -
  • Contact
  • +
  • Contact
  • {% if user.is_authenticated %}