LIL-73 Use html template

remotes/origin/hasaccess
Sergey G 8 years ago
parent 5853ce29b8
commit b828933d64
  1. 1
      apps/auth/tests/test_registration.py
  2. 5
      apps/auth/views.py
  3. 0
      apps/notification/__init__.py
  4. 6
      apps/notification/apps.py
  5. 0
      apps/notification/migrations/__init__.py
  6. 75
      apps/notification/templates/notification/email/_base.html
  7. 5
      apps/notification/templates/notification/email/verification_email.html
  8. 3
      apps/notification/tests.py
  9. 9
      apps/notification/utils.py
  10. 1
      project/settings.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

@ -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)

@ -0,0 +1,6 @@
from django.apps import AppConfig
class NotificationConfig(AppConfig):
name = 'apps.notification'
label = 'lilcity_notification'

File diff suppressed because one or more lines are too long

@ -0,0 +1,5 @@
{% extends "notification/email/_base.html" %}
{% block content %}
{{ token }}
{% endblock content %}

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -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()

@ -42,6 +42,7 @@ INSTALLED_APPS = [
] + [
'apps.auth.apps',
'apps.user',
'apps.notification',
]
MIDDLEWARE = [

Loading…
Cancel
Save