Pulled out url fix into a util
This commit is contained in:
parent
fd58ba1695
commit
faf1a9d0ed
8
OACPL/utils.py
Normal file
8
OACPL/utils.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from OACPL import settings
|
||||
|
||||
|
||||
def url_fix_render_to_string(template, context):
|
||||
temp = render_to_string(template, context)
|
||||
return temp.replace('src="/', 'src="%s/' % settings.BASE_URL).replace('href="/', 'href="%s/' % settings.BASE_URL)
|
@ -6,6 +6,7 @@ from django.db.models import Q
|
||||
from django.shortcuts import render, redirect
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from OACPL.utils import url_fix_render_to_string
|
||||
from charter_members.models import Attorney
|
||||
from newsletters.models import Subscriber
|
||||
from OACPL import settings
|
||||
@ -25,7 +26,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': '<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}))
|
||||
html_message=url_fix_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})
|
||||
|
||||
|
@ -3,9 +3,9 @@ from django.core import mail
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
from django.utils.html import strip_tags
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from OACPL import settings
|
||||
from OACPL.utils import url_fix_render_to_string
|
||||
from newsletters.models import Newsletter, Subscriber
|
||||
|
||||
|
||||
@ -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, 'base_url': settings.BASE_URL}))
|
||||
mail.send_mail(newsletter.subject, strip_tags(newsletter.body), settings.EMAIL_HOST_USER, subscribers, html_message=url_fix_render_to_string('email.html', {'content': newsletter.body}))
|
||||
newsletter.sent = True
|
||||
newsletter.save()
|
||||
print('Complete!')
|
||||
|
Loading…
Reference in New Issue
Block a user