From fe59d3883a3706a0852a589264b47f77bacae429 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 10 May 2024 23:46:48 +0800 Subject: [PATCH] Fixed email templates failing to load and updated README.md --- README.md | 14 ++++++++++++-- backend/config/settings.py | 4 ++-- backend/emails/templates.py | 10 +++++----- backend/payments/views.py | 5 ++--- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6f04b34..eef35fe 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ ## DRF-Template -This is a Django batteries-included template I personally use for my projects. This covers the following +This is a Django template that I personally use for my projects. This covers the following - Emails (and templated email designs) - Celery (For asynchronous tasks) - Celery Beat (For scheduled tasks) -- Caching (via Redis or optionally, Memcached) +- Caching (via Redis) - Performance profiling (via Django Silk) - Selenium (Optional, for webscraping with support for Chrome and Firefox drivers) - Stripe Subscriptions (Optional, with regular and pro-rated subscription support) @@ -16,3 +16,13 @@ This is a Django batteries-included template I personally use for my projects. T - Create a copy of the `.env.sample` file and name it as `.env` in the same directory - Populate .env with values - Run `docker-compose up` + +Be sure to follow through the steps shown in the `stripe-listener` container for initial setup with Stripe! + +## URLs + +- [Django Admin](http://localhost:8000/admin) +- [OpenAPI Swagger](http://localhost:8000/swagger) (For testing endpoints) +- [Inbucket](http://localhost:8025) (For email testing) +- [Flower](http://localhost:5555/) (For task monitoring) +- [Django Silk](http://localhost:8000/silk) (For performance profiling) diff --git a/backend/config/settings.py b/backend/config/settings.py index 33ed6c5..5e96c0a 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -87,7 +87,7 @@ EMAIL_HOST = get_secret('EMAIL_HOST') EMAIL_HOST_USER = get_secret('EMAIL_HOST_USER') EMAIL_HOST_PASSWORD = get_secret('EMAIL_HOST_PASSWORD') EMAIL_PORT = get_secret('EMAIL_PORT') -EMAIL_USE_TLS = get_secret('EMAIL_USE_TLS') +EMAIL_USE_TLS = (get_secret('EMAIL_USE_TLS') == 'True') EMAIL_ADDRESS = (get_secret('EMAIL_ADDRESS') == 'True') # Application definition @@ -183,7 +183,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ - BASE_DIR / 'templates', + BASE_DIR / 'emails/templates/', ], 'APP_DIRS': True, 'OPTIONS': { diff --git a/backend/emails/templates.py b/backend/emails/templates.py index 25d0f7d..8ffd36b 100644 --- a/backend/emails/templates.py +++ b/backend/emails/templates.py @@ -3,15 +3,15 @@ from django.utils import timezone class ActivationEmail(email.ActivationEmail): - template_name = 'templates/email_activation.html' + template_name = 'email_activation.html' class PasswordResetEmail(email.PasswordResetEmail): - template_name = 'templates/password_change.html' + template_name = 'password_change.html' class SubscriptionAvailedEmail(email.BaseEmailMessage): - template_name = "templates/subscription_availed.html" + template_name = "subscription_availed.html" def get_context_data(self): context = super().get_context_data() @@ -25,7 +25,7 @@ class SubscriptionAvailedEmail(email.BaseEmailMessage): class SubscriptionRefundedEmail(email.BaseEmailMessage): - template_name = "templates/subscription_refunded.html" + template_name = "subscription_refunded.html" def get_context_data(self): context = super().get_context_data() @@ -38,7 +38,7 @@ class SubscriptionRefundedEmail(email.BaseEmailMessage): class SubscriptionCancelledEmail(email.BaseEmailMessage): - template_name = "templates/subscription_cancelled.html" + template_name = "subscription_cancelled.html" def get_context_data(self): context = super().get_context_data() diff --git a/backend/payments/views.py b/backend/payments/views.py index 9dc6335..123ee21 100644 --- a/backend/payments/views.py +++ b/backend/payments/views.py @@ -135,10 +135,9 @@ def stripe_webhook_view(request): if event['type'] == 'customer.subscription.created': subscription = event['data']['object'] # Get the Invoice object from the Subscription object - invoice = stripe.Invoice.retrieve(subscription['latest_invoice'])[ - 'data']['object'] + invoice = stripe.Invoice.retrieve(subscription['latest_invoice']) # Get the Charge object from the Invoice object - charge = stripe.Charge.retrieve(invoice['charge'])['data']['object'] + charge = stripe.Charge.retrieve(invoice['charge']) # Get paying user customer = stripe.Customer.retrieve(subscription["customer"])