generated from codersforcauses/django-nextjs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Issue 31 add email api and email configurations #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Viloetsisi
wants to merge
10
commits into
main
Choose a base branch
from
issue-31-Add_email_API_and_email_configurations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+471
−14
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
28e3621
WIP: email config
Viloetsisi f8445eb
Resolve merge conflict in settings.py and keep email + S3 config
Viloetsisi dc3c101
Add email configuration variables to .env.example
Viloetsisi f09fd57
Remove unnecessary requirements.txt from branch
Viloetsisi 0d53973
Resolve merge conflict in .env.example and remove DEFAULT_FROM_EMAIL
Viloetsisi 2b0f609
feat(email): update email_utils to support HTML templates
Viloetsisi 39a3d3d
chore(settings): enable api/templates directory for email HTML templates
Viloetsisi d5553cd
feat(email-template): add booking confirmed HTML template
Viloetsisi 554a44e
feat(email-template): add booking cancelled HTML template
Viloetsisi c75ce34
refactor: update email templates with Bloom Figma logo and add base t…
Viloetsisi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| from typing import Iterable | ||
|
|
||
| from django.conf import settings | ||
| from django.core.mail import send_mail | ||
| from django.template.loader import render_to_string | ||
| from django.utils.html import strip_tags | ||
| from django.templatetags.static import static | ||
|
|
||
|
|
||
| # Template paths under api/templates/emails | ||
| BOOKING_CONFIRMED_TEMPLATE = "emails/booking_confirmed.html" | ||
| BOOKING_CANCELLED_TEMPLATE = "emails/booking_cancelled.html" | ||
|
|
||
|
|
||
| def get_bloom_logo_url() -> str: | ||
| """ | ||
| URL for the Bloom logo used in emails. | ||
|
|
||
| Uses BLOOM_LOGO_URL from settings if present, otherwise falls | ||
| back to the static path (useful for local/dev). | ||
| """ | ||
| logo_url = getattr(settings, "BLOOM_LOGO_URL", None) | ||
| if logo_url: | ||
| return logo_url | ||
|
|
||
| # Fallback – relative static path; fine for local / console email previews | ||
| return static("images/bloom_logo.png") | ||
|
|
||
|
|
||
| def send_simple_email( | ||
| subject: str, | ||
| message: str | None, | ||
| recipients: Iterable[str], | ||
| *, | ||
| html_template: str | None = None, | ||
| context: dict | None = None, | ||
| from_email: str | None = None, | ||
| fail_silently: bool = False, | ||
| ) -> int: | ||
| """ | ||
| Wrapper for Django's send_mail using EMAIL_HOST_USER. | ||
|
|
||
| - If `html_template` is provided, it renders that template with `context` | ||
| and sends it as HTML email. | ||
| - If `message` is None, it will be generated by stripping HTML tags from | ||
| the rendered HTML so a plain-text body is still sent. | ||
| - Existing plain-text usage still works: pass `subject`, `message`, | ||
| and `recipients` without `html_template`. | ||
| """ | ||
| if from_email is None: | ||
| from_email = settings.EMAIL_HOST_USER | ||
|
|
||
| html_message = None | ||
|
|
||
| if html_template is not None: | ||
| context = context or {} | ||
| html_message = render_to_string(html_template, context) | ||
| # Derive plain text from HTML if not explicitly provided | ||
| if message is None: | ||
| message = strip_tags(html_message) | ||
|
|
||
| # Django requires a non-empty string for `message` | ||
| if message is None: | ||
| message = "" | ||
|
|
||
| return send_mail( | ||
| subject=subject, | ||
| message=message, | ||
| from_email=from_email, | ||
| recipient_list=list(recipients), | ||
| fail_silently=fail_silently, | ||
| html_message=html_message, | ||
| ) | ||
|
|
||
|
|
||
| def send_booking_confirmed_email( | ||
| recipients: Iterable[str], | ||
| *, | ||
| context: dict, | ||
| subject: str = "Booking confirmed!", | ||
| fail_silently: bool = False, | ||
| ) -> int: | ||
| """ | ||
| Convenience wrapper for the booking confirmed HTML template. | ||
| Expects `context` to match the variables used in | ||
| emails/booking_confirmed.html. | ||
| """ | ||
| ctx = dict(context or {}) | ||
| ctx.setdefault("bloom_logo_url", get_bloom_logo_url()) | ||
|
|
||
| return send_simple_email( | ||
| subject=subject, | ||
| message=None, | ||
| recipients=recipients, | ||
| html_template=BOOKING_CONFIRMED_TEMPLATE, | ||
| context=ctx, | ||
| fail_silently=fail_silently, | ||
| ) | ||
|
|
||
|
|
||
| def send_booking_cancelled_email( | ||
| recipients: Iterable[str], | ||
| *, | ||
| context: dict, | ||
| subject: str = "Booking cancelled!", | ||
| fail_silently: bool = False, | ||
| ) -> int: | ||
| """ | ||
| Convenience wrapper for the booking cancelled HTML template. | ||
| Expects `context` to match the variables used in | ||
| emails/booking_cancelled.html. | ||
| """ | ||
| ctx = dict(context or {}) | ||
| ctx.setdefault("bloom_logo_url", get_bloom_logo_url()) | ||
|
|
||
| return send_simple_email( | ||
| subject=subject, | ||
| message=None, | ||
| recipients=recipients, | ||
| html_template=BOOKING_CANCELLED_TEMPLATE, | ||
| context=ctx, | ||
| fail_silently=fail_silently, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>{% block title %}Bloom Notification{% endblock %}</title> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <style> | ||
| body { | ||
| margin: 0; | ||
| padding: 0; | ||
| background-color: #f4f4f6; | ||
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; | ||
| } | ||
|
|
||
| .wrapper { | ||
| width: 100%; | ||
| padding: 32px 0; | ||
| } | ||
|
|
||
| .container { | ||
| max-width: 640px; | ||
| margin: 0 auto; | ||
| background-color: #ffffff; | ||
| border-radius: 4px; | ||
| overflow: hidden; | ||
| box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08); | ||
| } | ||
|
|
||
| /* ==== HEADER (Figma-style) ==== */ | ||
| .header { | ||
| background-color: #000000; /* black bar */ | ||
| padding: 24px 0; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .logo-row { | ||
| display: inline-block; | ||
| } | ||
|
|
||
| .logo-image { | ||
| display: inline-block; | ||
| background-color: #ffffff; /* white box behind logo */ | ||
| padding: 8px 24px; /* spacing around logo */ | ||
| border-radius: 4px; /* optional: match card style */ | ||
| } | ||
|
|
||
| .logo-image img { | ||
| display: block; | ||
| height: 40px; /* consistent logo size */ | ||
| width: auto; | ||
| } | ||
|
|
||
| /* ==== MAIN CONTENT ==== */ | ||
| .content { | ||
| padding: 32px 32px 40px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .button { | ||
| display: inline-block; | ||
| padding: 12px 32px; | ||
| border-radius: 4px; | ||
| text-decoration: none; | ||
| font-size: 14px; | ||
| font-weight: 600; | ||
| background-color: #38bdf8; | ||
| color: #ffffff !important; | ||
| } | ||
|
|
||
| .footer { | ||
| margin-top: 24px; | ||
| font-size: 11px; | ||
| color: #9ca3af; | ||
| line-height: 1.6; | ||
| } | ||
|
|
||
| @media (max-width: 640px) { | ||
| .container { | ||
| border-radius: 0; | ||
| } | ||
| .content { | ||
| padding: 24px 16px 32px; | ||
| } | ||
| } | ||
|
|
||
| {% block extra_styles %}{% endblock %} | ||
| </style> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div class="wrapper"> | ||
| <div class="container"> | ||
|
|
||
| <!-- HEADER --> | ||
| <div class="header"> | ||
| <div class="logo-row"> | ||
| <div class="logo-image"> | ||
| <img src="{{ bloom_logo_url }}" alt="Bloom logo" /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- MAIN CONTENT --> | ||
| <div class="content"> | ||
| {% block content %}{% endblock %} | ||
|
|
||
| <div class="footer"> | ||
| {% block footer %} | ||
| You’re receiving this email because you made or updated a booking | ||
| with Bloom Room Booker. Please do not reply to this automated message. | ||
| {% endblock %} | ||
| </div> | ||
| </div> | ||
|
|
||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please don't hard code, think about using a function and pass the details. pls use the bloom logo that you can find in figma thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| {% extends "emails/base_booking_email.html" %} | ||
|
|
||
| {% block title %}Booking cancelled{% endblock %} | ||
|
|
||
| {% block extra_styles %} | ||
| h1 { | ||
| margin: 0 0 12px; | ||
| font-size: 22px; | ||
| font-weight: 600; | ||
| color: #111827; | ||
| } | ||
|
|
||
| .subtitle { | ||
| margin: 0 0 28px; | ||
| font-size: 14px; | ||
| color: #4b5563; | ||
| line-height: 1.6; | ||
| } | ||
| {% endblock %} | ||
|
|
||
| {% block content %} | ||
| <h1>Booking cancelled!</h1> | ||
|
|
||
| <p class="subtitle"> | ||
| Your {{ room_name }} booking for | ||
| {{ start|date:"d M Y" }} from {{ start|time:"g:i A" }} | ||
| to {{ end|time:"g:i A" }} has been cancelled. | ||
| </p> | ||
|
|
||
| {% if book_room_url %} | ||
| <a href="{{ book_room_url }}" class="button">Book room</a> | ||
| {% endif %} | ||
| {% endblock %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll have html content for the email message. I just added the design in figma:


pls update according to this