From fd58ba1695ed135187e9cd9f00ee00596bbc3827 Mon Sep 17 00:00:00 2001 From: Zak Timson Date: Sat, 30 Sep 2017 12:47:47 -0400 Subject: [PATCH] Fixed email url's breaking --- main/views.py | 6 +++--- newsletters/admin.py | 2 ++ newsletters/management/commands/sendnewsletters.py | 2 +- templates/email.html | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/main/views.py b/main/views.py index 7535e07..07a9559 100644 --- a/main/views.py +++ b/main/views.py @@ -25,7 +25,7 @@ def contact(request): result = False 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], - html_message=render_to_string('email.html', {'content': 'Someone has messaged you via the website contact form!

Subject:
%(subject)s
From: %(name)s (%(email)s)

%(body)s' % locals(), 'signature': ' '})) + html_message=render_to_string('email.html', {'content': 'Someone has messaged you via the website contact form!

Subject:
%(subject)s
From: %(name)s (%(email)s)

%(body)s' % locals(), 'signature': ' ', 'base_url': settings.BASE_URL})) 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.save() 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'): Subscriber.objects.create(email=request.POST.get('email')) if request.POST.get('caselaw'): 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) 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': '%(email)s 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': '%(email)s has requested case law access.', 'base_url': settings.BASE_URL})) auth.login(request, user) return redirect('/') else: diff --git a/newsletters/admin.py b/newsletters/admin.py index 9e52a24..7b5dea7 100644 --- a/newsletters/admin.py +++ b/newsletters/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin from django.utils import timezone +from OACPL import settings from .models import Newsletter, Subscriber @@ -27,6 +28,7 @@ class NewsletterAdmin(admin.ModelAdmin): def save_model(self, request, instance, form, change): user = request.user instance = form.save(commit=False) + instance.body = instance.body.replace('src="', 'src="' + settings.BASE_URL) instance.creator = user instance.save() return instance diff --git a/newsletters/management/commands/sendnewsletters.py b/newsletters/management/commands/sendnewsletters.py index a010efb..06829c0 100644 --- a/newsletters/management/commands/sendnewsletters.py +++ b/newsletters/management/commands/sendnewsletters.py @@ -19,7 +19,7 @@ class Command(BaseCommand): print('Found %s subscribers' % len(subscribers)) for newsletter in newsletters: 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.save() print('Complete!') diff --git a/templates/email.html b/templates/email.html index 50da85b..d6f1f34 100644 --- a/templates/email.html +++ b/templates/email.html @@ -2,7 +2,7 @@
- +
ONTARIO ASSOCIATION OF