diff --git a/apps/auth/tests/test_registration.py b/apps/auth/tests/test_registration.py index 231a3d69..2db6d749 100644 --- a/apps/auth/tests/test_registration.py +++ b/apps/auth/tests/test_registration.py @@ -48,6 +48,7 @@ class LearnerRegistrationTest(TestCase): self.client.post(self.url, self.user_data) self.assertEqual(len(mail.outbox), 1) + self.assertListEqual(mail.outbox[0].to, [self.user_data['email']]) def test_should_redirect_main_page_when_user_not_anonymous(self): # todo pass diff --git a/apps/auth/views.py b/apps/auth/views.py index 2f57c47f..d3af957a 100644 --- a/apps/auth/views.py +++ b/apps/auth/views.py @@ -1,11 +1,11 @@ from django.contrib.auth import get_user_model, logout, login from django.contrib.auth.forms import AuthenticationForm -from django.core.mail import EmailMessage from django.http import JsonResponse from django.views.generic import FormView, View from .forms import LearnerRegistrationForm from .tokens import verification_email_token +from apps.notification.utils import send_email User = get_user_model() @@ -26,8 +26,7 @@ class LearnerRegistrationView(FormView): # fixme: change email text # fixme: async send email token = verification_email_token.make_token(user) - email = EmailMessage('VerificationEmail', f"{token}", to=[email]) - email.send() + send_email('Verification Email', email, "notification/email/verification_email.html", token=token) return JsonResponse({"success": True}, status=201) diff --git a/apps/notification/__init__.py b/apps/notification/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/notification/apps.py b/apps/notification/apps.py new file mode 100644 index 00000000..387c42ec --- /dev/null +++ b/apps/notification/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class NotificationConfig(AppConfig): + name = 'apps.notification' + label = 'lilcity_notification' diff --git a/apps/notification/migrations/__init__.py b/apps/notification/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/notification/templates/notification/email/_base.html b/apps/notification/templates/notification/email/_base.html new file mode 100644 index 00000000..92d6d367 --- /dev/null +++ b/apps/notification/templates/notification/email/_base.html @@ -0,0 +1,75 @@ + + + + Email + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + +
+ + + + +
Первая онлайн-школа креативного мышления Lil City School
+
+
+ {% block content %} +

A Brief History Of Creation

+

Comment On The Importance Of Human Life

+

The preservation of human life is the ultimate value, a pillar of ethics and the foundation of all morality. This held true in most cultures and societies throughout history.

+

On first impression, the last sentence sounds patently wrong. We all know about human collectives that regarded human lives as dispensable, that murdered and tortured, that cleansed and annihilated whole populations in recurrent genocides. Surely, these defy the aforementioned statement?

+

Liberal philosophies claim that human life was treated as a prime value throughout the ages. Authoritarian regimes do not contest the over-riding importance of this value. Life is sacred, valuable, to be cherished and preserved. But, in totalitarian societies, it can be deferred, subsumed, subjected to higher goals, quantized, and, therefore, applied with differential rigor in the following circumstances: 1.. Quantitative – when a lesser evil prevents a greater one. Sacrificing the lives of the few to save the lives of the many is a principle enshrined and embedded in activities such as war and medicinal care. All cultures, no matter how steeped (or rooted) in liberal lore accept it. They all send soldiers to die to save the more numerous civilian population. Medical doctors sacrifice lives daily, to save others.

+ {% endblock content %} +
+ + + + + + + + +
2017 © Lil City, UAB. + + + + + + + + + + + + + + Отписаться от рассылки +
+
+
+ + diff --git a/apps/notification/templates/notification/email/verification_email.html b/apps/notification/templates/notification/email/verification_email.html new file mode 100644 index 00000000..0a3bbeff --- /dev/null +++ b/apps/notification/templates/notification/email/verification_email.html @@ -0,0 +1,5 @@ +{% extends "notification/email/_base.html" %} + +{% block content %} + {{ token }} +{% endblock content %} \ No newline at end of file diff --git a/apps/notification/tests.py b/apps/notification/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/apps/notification/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/apps/notification/utils.py b/apps/notification/utils.py new file mode 100644 index 00000000..ddbc37b4 --- /dev/null +++ b/apps/notification/utils.py @@ -0,0 +1,9 @@ +from django.core.mail import EmailMessage +from django.template.loader import get_template + + +def send_email(subject, to_email, template_name, **kwargs): + html = get_template(template_name).render(kwargs) + email = EmailMessage(subject, html, to=[to_email]) + email.content_subtype = 'html' + email.send() diff --git a/project/settings.py b/project/settings.py index 855b10b9..821b4d8f 100644 --- a/project/settings.py +++ b/project/settings.py @@ -42,6 +42,7 @@ INSTALLED_APPS = [ ] + [ 'apps.auth.apps', 'apps.user', + 'apps.notification', ] MIDDLEWARE = [