Fixed email url's breaking

This commit is contained in:
Zakary Timson 2017-09-30 12:47:47 -04:00
parent 5686631bfe
commit fd58ba1695
4 changed files with 7 additions and 5 deletions

View File

@ -25,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=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': ' '})) 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': ' ', 'base_url': settings.BASE_URL}))
return JsonResponse({'success': True if result else False}) return JsonResponse({'success': True if result else False})
@ -43,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')], html_message=render_to_string('email.html', {'content': 'You have successfully registered to the Ontario Association of Child Protection Lawyers!', 'name': user.username})) 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, 'base_url': settings.BASE_URL}))
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)
email = user.email email = user.email
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.'})) 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.', 'base_url': settings.BASE_URL}))
auth.login(request, user) auth.login(request, user)
return redirect('/') return redirect('/')
else: else:

View File

@ -1,6 +1,7 @@
from django.contrib import admin from django.contrib import admin
from django.utils import timezone from django.utils import timezone
from OACPL import settings
from .models import Newsletter, Subscriber from .models import Newsletter, Subscriber
@ -27,6 +28,7 @@ class NewsletterAdmin(admin.ModelAdmin):
def save_model(self, request, instance, form, change): def save_model(self, request, instance, form, change):
user = request.user user = request.user
instance = form.save(commit=False) instance = form.save(commit=False)
instance.body = instance.body.replace('src="', 'src="' + settings.BASE_URL)
instance.creator = user instance.creator = user
instance.save() instance.save()
return instance return instance

View File

@ -19,7 +19,7 @@ class Command(BaseCommand):
print('Found %s subscribers' % len(subscribers)) print('Found %s subscribers' % len(subscribers))
for newsletter in newsletters: for newsletter in newsletters:
print('Sending newsletter: "%s"' % newsletter.subject) print('Sending newsletter: "%s"' % newsletter.subject)
mail.send_mail(newsletter.subject, strip_tags(newsletter.body), settings.EMAIL_HOST_USER, subscribers, html_message=render_to_string('email.html', {'content': newsletter.body})) mail.send_mail(newsletter.subject, strip_tags(newsletter.body), settings.EMAIL_HOST_USER, subscribers, html_message=render_to_string('email.html', {'content': newsletter.body, 'base_url': settings.BASE_URL}))
newsletter.sent = True newsletter.sent = True
newsletter.save() newsletter.save()
print('Complete!') print('Complete!')

View File

@ -2,7 +2,7 @@
<div style="width: calc(100% - 2px); border: solid 1px rgba(0,0,0,0.2)"> <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"> <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=""> <img src="{{ base_url }}{% 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"> <div style="display: inline-block; font-size: 1.25rem; color: #0F4C85">
ONTARIO ASSOCIATION OF ONTARIO ASSOCIATION OF
<br> <br>