-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sascha Dobbelaere
committed
Nov 28, 2023
1 parent
27f2661
commit 205002b
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,56 @@ | ||
from notifications.helpers import send_branded_mail | ||
|
||
from django.utils.translation import activate, get_language_info, deactivate | ||
from django.utils.translation import gettext_lazy as _ | ||
from django.template.loader import render_to_string | ||
|
||
from get_absolute_url.helpers import generate_absolute_url | ||
|
||
|
||
class SendBrandedEmail: | ||
subject = '' | ||
template_path = '' | ||
|
||
def __init__(self, user): | ||
self.user = user | ||
|
||
def set_template_variables(self): | ||
self.template_variables = { | ||
'user': self.user, | ||
'multi_tenant_company': self.user.multi_tenant_company | ||
} | ||
|
||
def compile_html_body(self): | ||
self.html_body = render_to_string(self.template_path, self.template_variables) | ||
|
||
def send_email(self): | ||
send_branded_mail(self.subject, self.html_body, self.user.email) | ||
|
||
def run(self): | ||
activate(self.user.language) | ||
self.set_template_variables() | ||
self.compile_html_body() | ||
self.send_email() | ||
deactivate() | ||
|
||
|
||
class SendWelcomeEmailFactory(SendBrandedEmail): | ||
subject = _("Welcome to OneSila. Let's kickstart your productivity.") | ||
template_path = 'notifications/email/welcome.html' | ||
|
||
def set_template_variables(self): | ||
super().set_template_variables() | ||
self.template_variables.update({ | ||
'dashboard_url': generate_absolute_url() | ||
}) | ||
|
||
|
||
class SendUserInviteEmailFactory(SendBrandedEmail): | ||
subject = _("Accept your invitation to OneSila.") | ||
template_path = 'notifications/email/invite_user.html' | ||
|
||
def set_template_variables(self): | ||
super().set_template_variables() | ||
self.template_variables.update({ | ||
'accept_invite_url': generate_absolute_url() | ||
}) |
This file contains 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,11 @@ | ||
from notifications.factories.email import SendWelcomeEmailFactory, SendUserInviteEmailFactory | ||
|
||
|
||
def send_welcome_email_flow(*, user): | ||
fac = SendWelcomeEmailFactory(user) | ||
fac.run() | ||
|
||
|
||
def send_user_invite_email_flow(*, user): | ||
fac = SendUserInviteEmailFactory(user) | ||
fac.run() |
6 changes: 6 additions & 0 deletions
6
OneSila/notifications/templates/notifications/email/base_email.html
This file contains 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,6 @@ | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
|
||
|
||
{% endblock %} |
20 changes: 20 additions & 0 deletions
20
OneSila/notifications/templates/notifications/email/invite_user.html
This file contains 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,20 @@ | ||
{% extends 'notifications/email/base_email.html' %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
{% translate "Hi" %} {{ name }} | ||
<br><br> | ||
{% blocktranslate %}You've been invited to '{{ multi_tenant_company }}'.{% endblocktranslate %} | ||
<br><br> | ||
<a href="{{ accept_invite_url }}">{% translate "Accept your invitation here." %}</a> | ||
<br><br> | ||
{% translate "Any help needed?" %} | ||
<br> | ||
{% translate "I'd love to hear from you." %} | ||
<br> | ||
{% translate "Best regards" %} | ||
<br> | ||
{% translate "Sascha Dobbelaere" %} | ||
<br> | ||
|
||
{% endblock %} |
21 changes: 21 additions & 0 deletions
21
OneSila/notifications/templates/notifications/email/welcome.html
This file contains 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,21 @@ | ||
{% extends 'notifications/email/base_email.html' %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
{% translate "Hi" %} {{ name }} | ||
<br><br> | ||
{% translate "We're amazed to go on this productivity journey together." %} | ||
{% translate "Let's start by logging in to your account and prepare your first produts and orders." %} | ||
<br><br> | ||
<a href="{{ dashboard_url }}">{% translate "Login to your dashboard here." %}</a> | ||
<br><br> | ||
{% translate "Any help needed?" %} | ||
<br> | ||
{% translate "I'd love to hear from you." %} | ||
<br> | ||
{% translate "Best regards" %} | ||
<br> | ||
{% translate "Sascha Dobbelaere" %} | ||
<br> | ||
|
||
{% endblock %} |