vintasend-django 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vintasend_django-0.1.0/LICENSE.txt +21 -0
- vintasend_django-0.1.0/PKG-INFO +21 -0
- vintasend_django-0.1.0/README.md +3 -0
- vintasend_django-0.1.0/pyproject.toml +171 -0
- vintasend_django-0.1.0/vintasend_django/__init__.py +0 -0
- vintasend_django-0.1.0/vintasend_django/apps.py +5 -0
- vintasend_django-0.1.0/vintasend_django/constants.py +18 -0
- vintasend_django-0.1.0/vintasend_django/migrations/0001_initial.py +116 -0
- vintasend_django-0.1.0/vintasend_django/migrations/__init__.py +0 -0
- vintasend_django-0.1.0/vintasend_django/models.py +43 -0
- vintasend_django-0.1.0/vintasend_django/services/__init__.py +0 -0
- vintasend_django-0.1.0/vintasend_django/services/notification_adapters/__init__.py +0 -0
- vintasend_django-0.1.0/vintasend_django/services/notification_adapters/django_email.py +61 -0
- vintasend_django-0.1.0/vintasend_django/services/notification_backends/__init__.py +0 -0
- vintasend_django-0.1.0/vintasend_django/services/notification_backends/django_db_notification_backend.py +231 -0
- vintasend_django-0.1.0/vintasend_django/services/notification_template_renderers/__init__.py +0 -0
- vintasend_django-0.1.0/vintasend_django/services/notification_template_renderers/django_templated_email_renderer.py +51 -0
- vintasend_django-0.1.0/vintasend_django/services/tests/__init__.py +0 -0
- vintasend_django-0.1.0/vintasend_django/services/tests/test_adapters.py +82 -0
- vintasend_django-0.1.0/vintasend_django/services/tests/test_django_db_notification_backend.py +375 -0
- vintasend_django-0.1.0/vintasend_django/services/tests/test_template_renderers.py +50 -0
- vintasend_django-0.1.0/vintasend_django/templates/vintasend_django/emails/base_notification.html +56 -0
- vintasend_django-0.1.0/vintasend_django/templates/vintasend_django/emails/test/test_templated_email_body.html +7 -0
- vintasend_django-0.1.0/vintasend_django/templates/vintasend_django/emails/test/test_templated_email_preheader.html +1 -0
- vintasend_django-0.1.0/vintasend_django/templates/vintasend_django/emails/test/test_templated_email_subject.txt +1 -0
- vintasend_django-0.1.0/vintasend_django/test_helpers.py +23 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Vinta Serviços e Soluções Tecnológicas Ltda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: vintasend-django
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A flexible package for implementing transactional notifications
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Hugo bessa
|
|
7
|
+
Author-email: hugo@vinta.com.br
|
|
8
|
+
Requires-Python: >=3.10,<3.13
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Dist: django (>=3.2,<5.3)
|
|
15
|
+
Requires-Dist: django-model-utils (>=5.0.0,<6.0.0)
|
|
16
|
+
Requires-Dist: vintasend
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# VintaSend Django
|
|
20
|
+
|
|
21
|
+
Django implementations for VintaSend
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "vintasend-django"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A flexible package for implementing transactional notifications"
|
|
5
|
+
authors = ["Hugo bessa <hugo@vinta.com.br>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
|
|
9
|
+
[tool.poetry.dependencies]
|
|
10
|
+
python = "<3.13,>=3.10"
|
|
11
|
+
django = "<5.3,>=3.2"
|
|
12
|
+
vintasend = "*"
|
|
13
|
+
django-model-utils = "^5.0.0"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
[tool.poetry.group.dev.dependencies]
|
|
17
|
+
freezegun = "^1.5.1"
|
|
18
|
+
coverage = "^7.6.4"
|
|
19
|
+
django-stubs = {version = "^5.1.1", extras=["compatible-mypy"]}
|
|
20
|
+
tox = "^4.23.2"
|
|
21
|
+
pytest = "^8.3.3"
|
|
22
|
+
pytest-xdist = {version = "^3.6.1", extras=["psutil"]}
|
|
23
|
+
coveralls = "^4.0.1"
|
|
24
|
+
pytest-cov = "^6.0.0"
|
|
25
|
+
pytest-django = "^4.9.0"
|
|
26
|
+
model-bakery = "^1.20.0"
|
|
27
|
+
|
|
28
|
+
[build-system]
|
|
29
|
+
requires = ["poetry-core"]
|
|
30
|
+
build-backend = "poetry.core.masonry.api"
|
|
31
|
+
|
|
32
|
+
[tool.mypy]
|
|
33
|
+
plugins = ["mypy_django_plugin.main"]
|
|
34
|
+
|
|
35
|
+
[tool.django-stubs]
|
|
36
|
+
django_settings_module = "settings.test"
|
|
37
|
+
|
|
38
|
+
[tool.ruff]
|
|
39
|
+
select = [
|
|
40
|
+
# pycodestyle
|
|
41
|
+
"E",
|
|
42
|
+
# Pyflakes
|
|
43
|
+
"F",
|
|
44
|
+
# pep8-naming
|
|
45
|
+
"N",
|
|
46
|
+
# pyupgrade
|
|
47
|
+
"UP",
|
|
48
|
+
# flake8-bugbear
|
|
49
|
+
"B",
|
|
50
|
+
# flake8-bandit
|
|
51
|
+
"S",
|
|
52
|
+
# flake8-blind-except
|
|
53
|
+
"BLE",
|
|
54
|
+
# flake8-builtins
|
|
55
|
+
"A",
|
|
56
|
+
# flake8-django
|
|
57
|
+
"DJ",
|
|
58
|
+
# isort
|
|
59
|
+
"I",
|
|
60
|
+
# flake8-logging-format
|
|
61
|
+
"G",
|
|
62
|
+
# flake8-no-pep420
|
|
63
|
+
"INP",
|
|
64
|
+
# Ruff-specific rules
|
|
65
|
+
"RUF",
|
|
66
|
+
]
|
|
67
|
+
exclude = [
|
|
68
|
+
".bzr",
|
|
69
|
+
".direnv",
|
|
70
|
+
".eggs",
|
|
71
|
+
".git",
|
|
72
|
+
".git-rewrite",
|
|
73
|
+
".hg",
|
|
74
|
+
".mypy_cache",
|
|
75
|
+
".nox",
|
|
76
|
+
".pants.d",
|
|
77
|
+
".pytype",
|
|
78
|
+
".ruff_cache",
|
|
79
|
+
".svn",
|
|
80
|
+
".tox",
|
|
81
|
+
".venv",
|
|
82
|
+
"__pypackages__",
|
|
83
|
+
"_build",
|
|
84
|
+
"buck-out",
|
|
85
|
+
"build",
|
|
86
|
+
"dist",
|
|
87
|
+
"node_modules",
|
|
88
|
+
"venv",
|
|
89
|
+
"virtualenvs",
|
|
90
|
+
"*/migrations/*",
|
|
91
|
+
]
|
|
92
|
+
ignore = [
|
|
93
|
+
# Disable eradicate (commented code removal)
|
|
94
|
+
"ERA001",
|
|
95
|
+
# Disable Conflicting lint rules,
|
|
96
|
+
# see https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
|
|
97
|
+
"W191",
|
|
98
|
+
"E501",
|
|
99
|
+
"E111",
|
|
100
|
+
"E117",
|
|
101
|
+
"D206",
|
|
102
|
+
"D300",
|
|
103
|
+
"Q000",
|
|
104
|
+
"Q001",
|
|
105
|
+
"Q002",
|
|
106
|
+
"Q003",
|
|
107
|
+
"COM812",
|
|
108
|
+
"COM819",
|
|
109
|
+
"ISC001",
|
|
110
|
+
"ISC002",
|
|
111
|
+
# Allow `except Exception`:
|
|
112
|
+
"BLE001",
|
|
113
|
+
# Disable unused `noqa` directive
|
|
114
|
+
"RUF100",
|
|
115
|
+
# Disable pyupgrade UP rules that conflict with django-ninja
|
|
116
|
+
"UP006",
|
|
117
|
+
"UP035",
|
|
118
|
+
"UP037",
|
|
119
|
+
"UP040",
|
|
120
|
+
]
|
|
121
|
+
line-length = 100
|
|
122
|
+
indent-width = 4
|
|
123
|
+
target-version = "py312"
|
|
124
|
+
# Allow unused variables when underscore-prefixed:
|
|
125
|
+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
|
126
|
+
|
|
127
|
+
[tool.ruff.pycodestyle]
|
|
128
|
+
ignore-overlong-task-comments = true
|
|
129
|
+
|
|
130
|
+
[tool.ruff.lint.isort]
|
|
131
|
+
section-order = [
|
|
132
|
+
"future",
|
|
133
|
+
"standard-library",
|
|
134
|
+
"django",
|
|
135
|
+
"third-party",
|
|
136
|
+
"first-party",
|
|
137
|
+
"local-folder",
|
|
138
|
+
]
|
|
139
|
+
lines-after-imports = 2
|
|
140
|
+
|
|
141
|
+
[tool.ruff.lint.isort.sections]
|
|
142
|
+
# Group all Django imports into a separate section.
|
|
143
|
+
"django" = ["django"]
|
|
144
|
+
|
|
145
|
+
[tool.ruff.per-file-ignores]
|
|
146
|
+
# Ignore "E402", "F403", "F405" (import violations) in __init__.py files.
|
|
147
|
+
# Ignore "S" (flake8-bandit) and "N802" (function name should be lowercase) in tests and docs.
|
|
148
|
+
# Ignore "RUF" (Ruff-specific rules) and "I" (isort) in migrations.
|
|
149
|
+
"__init__.py" = ["E402", "F403", "F405"]
|
|
150
|
+
"**/{tests,docs}/*" = ["E402", "F403", "F405", "S", "N802"]
|
|
151
|
+
"**/*test*.py" = ["E402", "F403", "F405", "S", "N802"]
|
|
152
|
+
"**/{settings}/*" = ["E402", "F403", "F405"]
|
|
153
|
+
"**/migrations/*" = ["RUF", "I"]
|
|
154
|
+
|
|
155
|
+
[tool.coverage.run]
|
|
156
|
+
branch = true
|
|
157
|
+
source = ["backend"]
|
|
158
|
+
omit = [
|
|
159
|
+
"**/venv/*",
|
|
160
|
+
"**/env/*",
|
|
161
|
+
"**/virtualenvs/*",
|
|
162
|
+
"**/node_modules/*",
|
|
163
|
+
"**/migrations/*",
|
|
164
|
+
"**/settings/*",
|
|
165
|
+
"**/tests/*",
|
|
166
|
+
]
|
|
167
|
+
|
|
168
|
+
[tool.pytest.ini_options]
|
|
169
|
+
DJANGO_SETTINGS_MODULE = "settings.test"
|
|
170
|
+
python_files = ["test_*.py"]
|
|
171
|
+
addopts = "--dist=loadscope"
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from vintasend.constants import NotificationStatus, NotificationTypes
|
|
2
|
+
from django.utils.translation import gettext_lazy as _
|
|
3
|
+
from django.db.models import TextChoices
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class NotificationStatusChoices(TextChoices):
|
|
7
|
+
PENDING_SEND = NotificationStatus.PENDING_SEND.value, _("Pending Send")
|
|
8
|
+
SENT = NotificationStatus.SENT.value, _("Sent")
|
|
9
|
+
CANCELLED = NotificationStatus.CANCELLED.value, _("Cancelled")
|
|
10
|
+
FAILED = NotificationStatus.FAILED.value, _("Failed")
|
|
11
|
+
READ = NotificationStatus.READ.value, _("Read")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class NotificationTypesChoices(TextChoices):
|
|
15
|
+
EMAIL = NotificationTypes.EMAIL.value, _("Email")
|
|
16
|
+
IN_APP = NotificationTypes.IN_APP.value, _("In App")
|
|
17
|
+
SMS = NotificationTypes.SMS.value, _("SMS")
|
|
18
|
+
PUSH = NotificationTypes.PUSH.value, _("Push")
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Generated by Django 5.1.3 on 2024-11-09 16:09
|
|
2
|
+
|
|
3
|
+
import django.db.models.deletion
|
|
4
|
+
import django.utils.timezone
|
|
5
|
+
import model_utils.fields
|
|
6
|
+
from django.conf import settings
|
|
7
|
+
from django.db import migrations, models
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Migration(migrations.Migration):
|
|
11
|
+
|
|
12
|
+
initial = True
|
|
13
|
+
|
|
14
|
+
dependencies = [
|
|
15
|
+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
operations = [
|
|
19
|
+
migrations.CreateModel(
|
|
20
|
+
name="Notification",
|
|
21
|
+
fields=[
|
|
22
|
+
(
|
|
23
|
+
"id",
|
|
24
|
+
models.BigAutoField(
|
|
25
|
+
auto_created=True,
|
|
26
|
+
primary_key=True,
|
|
27
|
+
serialize=False,
|
|
28
|
+
verbose_name="ID",
|
|
29
|
+
),
|
|
30
|
+
),
|
|
31
|
+
(
|
|
32
|
+
"notification_type",
|
|
33
|
+
models.CharField(
|
|
34
|
+
choices=[
|
|
35
|
+
("EMAIL", "Email"),
|
|
36
|
+
("IN_APP", "In App"),
|
|
37
|
+
("SMS", "SMS"),
|
|
38
|
+
("PUSH", "Push"),
|
|
39
|
+
],
|
|
40
|
+
max_length=50,
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
("title", models.CharField(max_length=255)),
|
|
44
|
+
(
|
|
45
|
+
"status",
|
|
46
|
+
models.CharField(
|
|
47
|
+
choices=[
|
|
48
|
+
("PENDING_SEND", "Pending Send"),
|
|
49
|
+
("SENT", "Sent"),
|
|
50
|
+
("CANCELLED", "Cancelled"),
|
|
51
|
+
("FAILED", "Failed"),
|
|
52
|
+
("READ", "Read"),
|
|
53
|
+
],
|
|
54
|
+
default="PENDING_SEND",
|
|
55
|
+
max_length=50,
|
|
56
|
+
),
|
|
57
|
+
),
|
|
58
|
+
("body_template", models.CharField(max_length=255)),
|
|
59
|
+
("subject_template", models.CharField(blank=True, max_length=255)),
|
|
60
|
+
("preheader_template", models.CharField(blank=True, max_length=255)),
|
|
61
|
+
("context_name", models.CharField(blank=True, max_length=255)),
|
|
62
|
+
("context_kwargs", models.JSONField(default=dict)),
|
|
63
|
+
("send_after", models.DateTimeField(null=True)),
|
|
64
|
+
(
|
|
65
|
+
"created",
|
|
66
|
+
model_utils.fields.AutoCreatedField(
|
|
67
|
+
db_index=True,
|
|
68
|
+
default=django.utils.timezone.now,
|
|
69
|
+
editable=False,
|
|
70
|
+
verbose_name="created",
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
(
|
|
74
|
+
"modified",
|
|
75
|
+
model_utils.fields.AutoLastModifiedField(
|
|
76
|
+
db_index=True,
|
|
77
|
+
default=django.utils.timezone.now,
|
|
78
|
+
editable=False,
|
|
79
|
+
verbose_name="modified",
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
(
|
|
83
|
+
"context_used",
|
|
84
|
+
models.JSONField(
|
|
85
|
+
null=True,
|
|
86
|
+
verbose_name="context used when notification was sent",
|
|
87
|
+
),
|
|
88
|
+
),
|
|
89
|
+
(
|
|
90
|
+
"user",
|
|
91
|
+
models.ForeignKey(
|
|
92
|
+
on_delete=django.db.models.deletion.CASCADE,
|
|
93
|
+
to=settings.AUTH_USER_MODEL,
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
(
|
|
97
|
+
"adapter_extra_parameters",
|
|
98
|
+
models.JSONField(
|
|
99
|
+
null=True,
|
|
100
|
+
verbose_name="Extra parameters for the notification adapter",
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
(
|
|
104
|
+
"adapter_used",
|
|
105
|
+
models.CharField(
|
|
106
|
+
max_length=255,
|
|
107
|
+
null=True,
|
|
108
|
+
verbose_name="Adapter used to send the notification",
|
|
109
|
+
),
|
|
110
|
+
),
|
|
111
|
+
],
|
|
112
|
+
options={
|
|
113
|
+
"ordering": ("-created",),
|
|
114
|
+
},
|
|
115
|
+
),
|
|
116
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from django.contrib.auth import get_user_model
|
|
2
|
+
from django.db import models
|
|
3
|
+
from django.utils.translation import gettext_lazy as _
|
|
4
|
+
|
|
5
|
+
from model_utils.fields import AutoCreatedField, AutoLastModifiedField
|
|
6
|
+
|
|
7
|
+
from vintasend_django.constants import NotificationStatusChoices, NotificationTypesChoices
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
User = get_user_model()
|
|
11
|
+
|
|
12
|
+
class Notification(models.Model):
|
|
13
|
+
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
14
|
+
notification_type = models.CharField(max_length=50, choices=NotificationTypesChoices)
|
|
15
|
+
title = models.CharField(max_length=255)
|
|
16
|
+
status = models.CharField(
|
|
17
|
+
max_length=50, choices=NotificationStatusChoices, default=NotificationStatusChoices.PENDING_SEND
|
|
18
|
+
)
|
|
19
|
+
body_template = models.CharField(max_length=255)
|
|
20
|
+
|
|
21
|
+
# Email specific fields
|
|
22
|
+
subject_template = models.CharField(max_length=255, blank=True)
|
|
23
|
+
preheader_template = models.CharField(max_length=255, blank=True)
|
|
24
|
+
context_name = models.CharField(max_length=255, blank=True)
|
|
25
|
+
context_kwargs = models.JSONField(default=dict)
|
|
26
|
+
|
|
27
|
+
send_after = models.DateTimeField(null=True)
|
|
28
|
+
|
|
29
|
+
created = AutoCreatedField(_("created"), db_index=True)
|
|
30
|
+
modified = AutoLastModifiedField(_("modified"), db_index=True)
|
|
31
|
+
|
|
32
|
+
adapter_extra_parameters = models.JSONField(_("adapter_extra_parameters"), null=True)
|
|
33
|
+
|
|
34
|
+
context_used = models.JSONField(_("context used when notification was sent"), null=True)
|
|
35
|
+
adapter_used = models.CharField(_("adapter used to send the notification"), max_length=255, null=True)
|
|
36
|
+
|
|
37
|
+
objects: models.Manager["Notification"]
|
|
38
|
+
|
|
39
|
+
class Meta:
|
|
40
|
+
ordering = ("-created",)
|
|
41
|
+
|
|
42
|
+
def __str__(self):
|
|
43
|
+
return f"{self.user} - {self.notification_type} - {self.title} - {self.status}{f' (scheduled to {self.send_after})' if self.send_after else ''}"
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Generic, TypeVar
|
|
2
|
+
|
|
3
|
+
from django.contrib.auth import get_user_model
|
|
4
|
+
from django.core.mail import EmailMessage
|
|
5
|
+
|
|
6
|
+
from vintasend.constants import NotificationTypes
|
|
7
|
+
|
|
8
|
+
from vintasend.services.dataclasses import Notification
|
|
9
|
+
from vintasend.services.notification_backends.base import BaseNotificationBackend
|
|
10
|
+
from vintasend.services.notification_adapters.base import BaseNotificationAdapter
|
|
11
|
+
from vintasend.services.notification_template_renderers.base_templated_email_renderer import BaseTemplatedEmailRenderer
|
|
12
|
+
from vintasend.app_settings import NotificationSettings
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from vintasend.services.notification_service import NotificationContextDict
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
User = get_user_model()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
B = TypeVar("B", bound=BaseNotificationBackend)
|
|
23
|
+
T = TypeVar("T", bound=BaseTemplatedEmailRenderer)
|
|
24
|
+
|
|
25
|
+
class DjangoEmailNotificationAdapter(Generic[B, T], BaseNotificationAdapter[B, T]):
|
|
26
|
+
notification_type = NotificationTypes.EMAIL
|
|
27
|
+
|
|
28
|
+
def send(
|
|
29
|
+
self,
|
|
30
|
+
notification: Notification,
|
|
31
|
+
context: "NotificationContextDict",
|
|
32
|
+
headers: dict[str, str] | None = None,
|
|
33
|
+
) -> None:
|
|
34
|
+
"""
|
|
35
|
+
Send the notification to the user through email.
|
|
36
|
+
|
|
37
|
+
:param notification: The notification to send.
|
|
38
|
+
:param context: The context to render the notification templates.
|
|
39
|
+
"""
|
|
40
|
+
notification_settings = NotificationSettings()
|
|
41
|
+
|
|
42
|
+
user_email = self.backend.get_user_email_from_notification(notification.id)
|
|
43
|
+
to = [user_email]
|
|
44
|
+
bcc = [email for email in notification_settings.NOTIFICATION_DEFAULT_BCC_EMAILS] or []
|
|
45
|
+
|
|
46
|
+
context_with_base_url: "NotificationContextDict" = context.copy()
|
|
47
|
+
context_with_base_url["base_url"] = f"{notification_settings.NOTIFICATION_DEFAULT_BASE_URL_PROTOCOL}://{notification_settings.NOTIFICATION_DEFAULT_BASE_URL_DOMAIN}"
|
|
48
|
+
|
|
49
|
+
template = self.template_renderer.render(notification, context_with_base_url)
|
|
50
|
+
|
|
51
|
+
email = EmailMessage(
|
|
52
|
+
subject=template.subject.strip(),
|
|
53
|
+
body=template.body,
|
|
54
|
+
from_email=notification_settings.NOTIFICATION_DEFAULT_FROM_EMAIL,
|
|
55
|
+
to=to,
|
|
56
|
+
bcc=bcc,
|
|
57
|
+
headers=headers,
|
|
58
|
+
)
|
|
59
|
+
email.content_subtype = "html"
|
|
60
|
+
|
|
61
|
+
email.send()
|
|
File without changes
|