Skip to content

Commit

Permalink
add forgotton files
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Dobbelaere committed Nov 28, 2023
1 parent 27f2661 commit 205002b
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
56 changes: 56 additions & 0 deletions OneSila/notifications/factories/email.py
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()
})
11 changes: 11 additions & 0 deletions OneSila/notifications/flows/email.py
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% load i18n %}

{% block content %}


{% endblock %}
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 OneSila/notifications/templates/notifications/email/welcome.html
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 %}

0 comments on commit 205002b

Please sign in to comment.