Fixed email templates failing to load and updated README.md

This commit is contained in:
Keannu Bernasol 2024-05-10 23:46:48 +08:00
parent 8d40a33882
commit fe59d3883a
4 changed files with 21 additions and 12 deletions

View file

@ -1,11 +1,11 @@
## DRF-Template ## 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) - Emails (and templated email designs)
- Celery (For asynchronous tasks) - Celery (For asynchronous tasks)
- Celery Beat (For scheduled tasks) - Celery Beat (For scheduled tasks)
- Caching (via Redis or optionally, Memcached) - Caching (via Redis)
- Performance profiling (via Django Silk) - Performance profiling (via Django Silk)
- Selenium (Optional, for webscraping with support for Chrome and Firefox drivers) - Selenium (Optional, for webscraping with support for Chrome and Firefox drivers)
- Stripe Subscriptions (Optional, with regular and pro-rated subscription support) - 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 - Create a copy of the `.env.sample` file and name it as `.env` in the same directory
- Populate .env with values - Populate .env with values
- Run `docker-compose up` - 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)

View file

@ -87,7 +87,7 @@ EMAIL_HOST = get_secret('EMAIL_HOST')
EMAIL_HOST_USER = get_secret('EMAIL_HOST_USER') EMAIL_HOST_USER = get_secret('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = get_secret('EMAIL_HOST_PASSWORD') EMAIL_HOST_PASSWORD = get_secret('EMAIL_HOST_PASSWORD')
EMAIL_PORT = get_secret('EMAIL_PORT') 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') EMAIL_ADDRESS = (get_secret('EMAIL_ADDRESS') == 'True')
# Application definition # Application definition
@ -183,7 +183,7 @@ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ 'DIRS': [
BASE_DIR / 'templates', BASE_DIR / 'emails/templates/',
], ],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {

View file

@ -3,15 +3,15 @@ from django.utils import timezone
class ActivationEmail(email.ActivationEmail): class ActivationEmail(email.ActivationEmail):
template_name = 'templates/email_activation.html' template_name = 'email_activation.html'
class PasswordResetEmail(email.PasswordResetEmail): class PasswordResetEmail(email.PasswordResetEmail):
template_name = 'templates/password_change.html' template_name = 'password_change.html'
class SubscriptionAvailedEmail(email.BaseEmailMessage): class SubscriptionAvailedEmail(email.BaseEmailMessage):
template_name = "templates/subscription_availed.html" template_name = "subscription_availed.html"
def get_context_data(self): def get_context_data(self):
context = super().get_context_data() context = super().get_context_data()
@ -25,7 +25,7 @@ class SubscriptionAvailedEmail(email.BaseEmailMessage):
class SubscriptionRefundedEmail(email.BaseEmailMessage): class SubscriptionRefundedEmail(email.BaseEmailMessage):
template_name = "templates/subscription_refunded.html" template_name = "subscription_refunded.html"
def get_context_data(self): def get_context_data(self):
context = super().get_context_data() context = super().get_context_data()
@ -38,7 +38,7 @@ class SubscriptionRefundedEmail(email.BaseEmailMessage):
class SubscriptionCancelledEmail(email.BaseEmailMessage): class SubscriptionCancelledEmail(email.BaseEmailMessage):
template_name = "templates/subscription_cancelled.html" template_name = "subscription_cancelled.html"
def get_context_data(self): def get_context_data(self):
context = super().get_context_data() context = super().get_context_data()

View file

@ -135,10 +135,9 @@ def stripe_webhook_view(request):
if event['type'] == 'customer.subscription.created': if event['type'] == 'customer.subscription.created':
subscription = event['data']['object'] subscription = event['data']['object']
# Get the Invoice object from the Subscription object # Get the Invoice object from the Subscription object
invoice = stripe.Invoice.retrieve(subscription['latest_invoice'])[ invoice = stripe.Invoice.retrieve(subscription['latest_invoice'])
'data']['object']
# Get the Charge object from the Invoice object # 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 # Get paying user
customer = stripe.Customer.retrieve(subscription["customer"]) customer = stripe.Customer.retrieve(subscription["customer"])