Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
radiopanik
django-panik-newsletter
Commits
6b00be8d
Commit
6b00be8d
authored
Feb 09, 2018
by
fred
Browse files
use templates to render newsletter
parent
871b42b8
Changes
3
Show whitespace changes
Inline
Side-by-side
newsletter/models.py
View file @
6b00be8d
...
...
@@ -15,8 +15,10 @@ from django.db import models
from
django.core.urlresolvers
import
reverse
from
django.template
import
loader
,
Context
from
django.template.loader
import
render_to_string
from
django.conf
import
settings
from
django.utils.safestring
import
mark_safe
from
django.utils.translation
import
ugettext
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.core.mail
import
send_mail
...
...
@@ -81,12 +83,13 @@ class Newsletter(models.Model):
h2t
=
html2text
.
HTML2Text
()
h2t
.
unicode_snob
=
True
html
=
self
.
text
.
encode
(
'utf-8'
)
if
settings
.
NEWSLETTER_STYLE
:
html
+=
'''
\n
<style type="text/css">
\n
%s
\n
</style>'''
%
settings
.
NEWSLETTER_STYLE
context
=
{
'text_part'
:
mark_safe
(
h2t
.
handle
(
self
.
text
)),
'html_part'
:
mark_safe
(
self
.
text
),
}
part1
=
MIMEText
(
h2t
.
handle
(
self
.
t
e
xt
).
encode
(
'utf-8'
),
'plain'
,
_charset
=
'utf-8'
)
part2
=
MIMEText
(
html
,
'html'
,
_charset
=
'utf-8'
)
part1
=
MIMEText
(
render_to_string
(
'newsletter/email_body
.txt
'
,
context
),
'plain'
,
_charset
=
'utf-8'
)
part2
=
MIMEText
(
render_to_string
(
'newsletter/email_body.html'
,
context
)
,
'html'
,
_charset
=
'utf-8'
)
msg
.
attach
(
part1
)
msg
.
attach
(
part2
)
...
...
newsletter/templates/newsletter/email_body.html
0 → 100644
View file @
6b00be8d
{{html_part}}
newsletter/templates/newsletter/email_body.txt
0 → 100644
View file @
6b00be8d
{{text_part}}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment