From 0f2f69b74c92ab2e7b5fc9d18fef88f8850ccea3 Mon Sep 17 00:00:00 2001 From: mattfreire Date: Thu, 2 Apr 2020 00:01:51 +0200 Subject: [PATCH 01/25] Home view --- core/__init__.py | 0 core/admin.py | 3 +++ core/apps.py | 5 +++++ core/migrations/__init__.py | 0 core/models.py | 3 +++ core/tests.py | 3 +++ core/views.py | 6 ++++++ ecom/settings.py | 2 ++ ecom/urls.py | 9 ++++++-- templates/index.html | 43 +++++++++++++++++++++++++++++++++++++ 10 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 core/__init__.py create mode 100644 core/admin.py create mode 100644 core/apps.py create mode 100644 core/migrations/__init__.py create mode 100644 core/models.py create mode 100644 core/tests.py create mode 100644 core/views.py create mode 100644 templates/index.html diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/admin.py b/core/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/core/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/core/apps.py b/core/apps.py new file mode 100644 index 0000000..26f78a8 --- /dev/null +++ b/core/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CoreConfig(AppConfig): + name = 'core' diff --git a/core/migrations/__init__.py b/core/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/models.py b/core/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/core/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/core/tests.py b/core/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/core/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/core/views.py b/core/views.py new file mode 100644 index 0000000..dce1582 --- /dev/null +++ b/core/views.py @@ -0,0 +1,6 @@ +from django.shortcuts import render +from django.views import generic + + +class HomeView(generic.TemplateView): + template_name = 'index.html' diff --git a/ecom/settings.py b/ecom/settings.py index fa1d2b8..77926a5 100644 --- a/ecom/settings.py +++ b/ecom/settings.py @@ -20,6 +20,8 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + + 'core' ] MIDDLEWARE = [ diff --git a/ecom/urls.py b/ecom/urls.py index a3c3eca..b0ab8b3 100644 --- a/ecom/urls.py +++ b/ecom/urls.py @@ -3,10 +3,15 @@ from django.contrib import admin from django.urls import path +from core import views + urlpatterns = [ path('admin/', admin.site.urls), + path('', views.HomeView.as_view(), name='home') ] if settings.DEBUG: - urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + urlpatterns += static(settings.STATIC_URL, + document_root=settings.STATIC_ROOT) + urlpatterns += static(settings.MEDIA_URL, + document_root=settings.MEDIA_ROOT) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..cd356a5 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,43 @@ +{% extends "base.html" %} +{% load static %} + +{% block content %} + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+

Pay with Paypal

+

Use server-side PayPal integration for handling payments.

+
+
+
+ + Django icon + + +
+

Made with Django

+

Django makes it easy to quickly build awesome web apps.

+
+
+
+
+
+ +{% endblock content %} \ No newline at end of file From 4a4a8c7d07d008d476a580533c4cf87bf5ee0836 Mon Sep 17 00:00:00 2001 From: mattfreire Date: Thu, 2 Apr 2020 00:25:24 +0200 Subject: [PATCH 02/25] Contact form --- core/forms.py | 13 +++++++++++++ core/views.py | 36 +++++++++++++++++++++++++++++++++++- ecom/.template.env | 4 +++- ecom/settings.py | 7 +++++++ ecom/urls.py | 3 ++- requirements.txt | 2 ++ templates/contact.html | 36 ++++++++++++++++++++++++++++++++++++ templates/navbar.html | 2 +- 8 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 core/forms.py create mode 100644 templates/contact.html diff --git a/core/forms.py b/core/forms.py new file mode 100644 index 0000000..1acf327 --- /dev/null +++ b/core/forms.py @@ -0,0 +1,13 @@ +from django import forms + + +class ContactForm(forms.Form): + name = forms.CharField(max_length=100, widget=forms.TextInput(attrs={ + 'placeholder': "Your name" + })) + email = forms.EmailField(widget=forms.TextInput(attrs={ + 'placeholder': "Your e-mail" + })) + message = forms.CharField(widget=forms.Textarea(attrs={ + 'placeholder': 'Your message' + })) diff --git a/core/views.py b/core/views.py index dce1582..650cd27 100644 --- a/core/views.py +++ b/core/views.py @@ -1,6 +1,40 @@ -from django.shortcuts import render +from django.conf import settings +from django.contrib import messages +from django.core.mail import send_mail +from django.shortcuts import reverse from django.views import generic +from .forms import ContactForm class HomeView(generic.TemplateView): template_name = 'index.html' + + +class ContactView(generic.FormView): + form_class = ContactForm + template_name = 'contact.html' + + def get_success_url(self): + return reverse("contact") + + def form_valid(self, form): + messages.info( + self.request, "Thanks for getting in touch. We have received your message.") + name = form.cleaned_data.get('name') + email = form.cleaned_data.get('email') + message = form.cleaned_data.get('message') + + full_message = f""" + Received message below from {name}, {email} + ________________________ + + + {message} + """ + send_mail( + subject="Received contact form submission", + message=full_message, + from_email=settings.DEFAULT_FROM_EMAIL, + recipient_list=[settings.NOTIFY_EMAIL] + ) + return super(ContactView, self).form_valid(form) diff --git a/ecom/.template.env b/ecom/.template.env index 2e8b31f..45b816a 100644 --- a/ecom/.template.env +++ b/ecom/.template.env @@ -1,2 +1,4 @@ DEBUG= -SECRET_KEY= \ No newline at end of file +SECRET_KEY= +DEFAULT_FROM_EMAIL= +NOTIFY_EMAIL= \ No newline at end of file diff --git a/ecom/settings.py b/ecom/settings.py index 77926a5..94a278c 100644 --- a/ecom/settings.py +++ b/ecom/settings.py @@ -21,9 +21,14 @@ 'django.contrib.messages', 'django.contrib.staticfiles', + 'crispy_forms', + 'core' ] +DEFAULT_FROM_EMAIL = env('DEFAULT_FROM_EMAIL') +NOTIFY_EMAIL = env('NOTIFY_EMAIL') + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -76,6 +81,8 @@ }, ] +CRISPY_TEMPLATE_PACK = 'bootstrap4' + LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True diff --git a/ecom/urls.py b/ecom/urls.py index b0ab8b3..4996f60 100644 --- a/ecom/urls.py +++ b/ecom/urls.py @@ -7,7 +7,8 @@ urlpatterns = [ path('admin/', admin.site.urls), - path('', views.HomeView.as_view(), name='home') + path('', views.HomeView.as_view(), name='home'), + path('contact/', views.ContactView.as_view(), name='contact'), ] if settings.DEBUG: diff --git a/requirements.txt b/requirements.txt index 3b99618..ebf5802 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,7 @@ asgiref==3.2.7 Django==3.0.5 +django-crispy-forms==1.9.0 +django-environ==0.4.5 psycopg2-binary==2.8.4 pytz==2019.3 sqlparse==0.3.1 diff --git a/templates/contact.html b/templates/contact.html new file mode 100644 index 0000000..3eacd11 --- /dev/null +++ b/templates/contact.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} +{% load crispy_forms_tags %} + +{% block content %} + +
+
+
+
+ Home + / + Contact +
+
+
+
+ +
+
+
+
+

Get in touch

+
+
+
+ {% csrf_token %} + {{ form|crispy }} + +
+
+
+
+
+ + +{% endblock content %} \ No newline at end of file diff --git a/templates/navbar.html b/templates/navbar.html index 7de44ee..fa5aea5 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -3,7 +3,7 @@