Added email template
This commit is contained in:
parent
8842688a1a
commit
57b2dc6c72
@ -4,6 +4,7 @@ from django.contrib.auth.models import User, Permission
|
|||||||
from django.core import mail
|
from django.core import mail
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
from charter_members.models import Attorney
|
from charter_members.models import Attorney
|
||||||
from newsletters.models import Subscriber
|
from newsletters.models import Subscriber
|
||||||
@ -24,7 +25,7 @@ def contact(request):
|
|||||||
result = False
|
result = False
|
||||||
if name is not None and email is not None and subject is not None and body is not None:
|
if name is not None and email is not None and subject is not None and body is not None:
|
||||||
result = mail.send_mail('OACPL CONTACT: %(subject)s' % locals(), body, settings.EMAIL_HOST_USER, [settings.EMAIL_CONTACT],
|
result = mail.send_mail('OACPL CONTACT: %(subject)s' % locals(), body, settings.EMAIL_HOST_USER, [settings.EMAIL_CONTACT],
|
||||||
html_message='<strong>From:</strong> %(name)s (%(email)s)<br><br>{body}' % locals())
|
html_message=render_to_string('email.html', {'content': '<strong>Someone has messaged you via the website contact form!<br><br>Subject:</strong> %(subject)s<br><strong>From:</strong> %(name)s (%(email)s)<br><br>%(body)s' % locals(), 'signature': ' '}))
|
||||||
|
|
||||||
return JsonResponse({'success': True if result else False})
|
return JsonResponse({'success': True if result else False})
|
||||||
|
|
||||||
@ -42,14 +43,14 @@ def login(request):
|
|||||||
user = User.objects.create_user(request.POST.get('username'), email=request.POST.get('email'), password=request.POST.get('password'))
|
user = User.objects.create_user(request.POST.get('username'), email=request.POST.get('email'), password=request.POST.get('password'))
|
||||||
user.save()
|
user.save()
|
||||||
if settings.EMAIL_HOST:
|
if settings.EMAIL_HOST:
|
||||||
mail.send_mail('OACPL Registration', 'You have successfully registered to the Ontario Association of Child Protection Lawyers!', settings.EMAIL_HOST_USER, [request.POST.get('email')])
|
mail.send_mail('OACPL Registration', 'You have successfully registered to the Ontario Association of Child Protection Lawyers!', settings.EMAIL_HOST_USER, [request.POST.get('email')], html_message=render_to_string('email.html', {'content': 'You have successfully registered to the Ontario Association of Child Protection Lawyers!', 'name': user.username}))
|
||||||
if request.POST.get('newsletter'):
|
if request.POST.get('newsletter'):
|
||||||
Subscriber.objects.create(email=request.POST.get('email'))
|
Subscriber.objects.create(email=request.POST.get('email'))
|
||||||
if request.POST.get('caselaw'):
|
if request.POST.get('caselaw'):
|
||||||
perm = Permission.objects.get(codename='change_user')
|
perm = Permission.objects.get(codename='change_user')
|
||||||
admins = User.objects.filter(Q(groups__permissions=perm) | Q(user_permissions=perm) | Q(is_superuser=True)).distinct().values_list('email', flat=True)
|
admins = User.objects.filter(Q(groups__permissions=perm) | Q(user_permissions=perm) | Q(is_superuser=True)).distinct().values_list('email', flat=True)
|
||||||
print(admins)
|
email = user.email
|
||||||
mail.send_mail('OACPL Case Law Request', '%(user.email)s has requested case law access.', settings.EMAIL_HOST_USER, admins, html_message='<a href="#">%(user.email)s</a> has requested case law access.')
|
mail.send_mail('OACPL Case Law Request', '%(email)s has requested case law access.', settings.EMAIL_HOST_USER, admins, html_message=render_to_string('email.html', {'content': '<a href="#">%(email)s</a> has requested case law access.'}))
|
||||||
auth.login(request, user)
|
auth.login(request, user)
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
else:
|
else:
|
||||||
|
39
templates/email.html
Normal file
39
templates/email.html
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{% load static %}
|
||||||
|
|
||||||
|
<div style="width: calc(100% - 2px); border: solid 1px rgba(0,0,0,0.2)">
|
||||||
|
<div style="width: calc(100% - 1rem); background-color: #ffffff; padding: 0.5rem">
|
||||||
|
<img src="{% static 'main/img/logo.png' %}" width="30" height="30" style="display: inline-block; vertical-align: top" alt="">
|
||||||
|
<div style="display: inline-block; font-size: 1.25rem; color: #0F4C85">
|
||||||
|
ONTARIO ASSOCIATION OF
|
||||||
|
<br>
|
||||||
|
CHILD PROTECTION LAWYERS
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="background-color: #00305b; color: #ffffff; padding: 0.5rem; font-size: 1rem">
|
||||||
|
{% if name %}
|
||||||
|
Hello {{ name }},
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
{% endif %}
|
||||||
|
{% autoescape off %}
|
||||||
|
{{ content }}
|
||||||
|
{% endautoescape %}
|
||||||
|
{% if signature %}
|
||||||
|
{{ signature }}
|
||||||
|
{% else %}
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
--
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
Sincerely,
|
||||||
|
<br>
|
||||||
|
The OACPL Team
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<footer style="background-color: #ffffff; color: #0F4C85;">
|
||||||
|
<div style="text-align: center">
|
||||||
|
<p class="mb-0">© 2017 Ontario Association of Child Protection Lawyers.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</div>
|
Loading…
Reference in New Issue
Block a user