Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template rendering for compatibility with Django 1.10+ #70

Merged
merged 7 commits into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

_*BI*_ = backward incompatible change

## 4.0
* _*BI*_: To support changes to `render_to_string` in Django 1.10 and above,
your notice `full.txt` and `short.txt` plain text templates must now be autoescaped explicitly using the
`{% autoescape %}` tag.
([#68](https://github.com/pinax/pinax-notifications/issues/68#issuecomment-258383323))


## 3.0.1
* initial support for Django 1.10


## 3.0
* fix compatability with Django migrations


## 2.1.0
* add Django migrations


## 2.0

* renamed app as pinax-notifications
* added the ability to override NoticeSetting model
* added documentation on scoping notifications


## 1.1.1

Expand Down
8 changes: 2 additions & 6 deletions pinax/notifications/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.template import Context
from django.template.loader import render_to_string

from django.contrib.sites.models import Site
Expand Down Expand Up @@ -36,9 +35,6 @@ def get_formatted_messages(self, formats, label, context):
"""
format_templates = {}
for fmt in formats:
# conditionally turn off autoescaping for .txt extensions in format
if fmt.endswith(".txt"):
context.autoescape = False
format_templates[fmt] = render_to_string((
"pinax/notifications/{0}/{1}".format(label, fmt),
"pinax/notifications/{0}".format(fmt)), context)
Expand All @@ -49,8 +45,8 @@ def default_context(self):
default_http_protocol = "https" if use_ssl else "http"
current_site = Site.objects.get_current()
base_url = "{0}://{1}".format(default_http_protocol, current_site.domain)
return Context({
return {
"default_http_protocol": default_http_protocol,
"current_site": current_site,
"base_url": base_url
})
}
12 changes: 7 additions & 5 deletions pinax/notifications/backends/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ def deliver(self, recipient, sender, notice_type, extra_context):
"full.txt"
), notice_type.label, context)

subject = "".join(render_to_string("pinax/notifications/email_subject.txt", {
context.update({
"message": messages["short.txt"],
}, context).splitlines())
})
subject = "".join(render_to_string("pinax/notifications/email_subject.txt", context).splitlines())

body = render_to_string("pinax/notifications/email_body.txt", {
"message": messages["full.txt"],
}, context)
context.update({
"message": messages["full.txt"]
})
body = render_to_string("pinax/notifications/email_body.txt", context)

send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [recipient.email])
2 changes: 1 addition & 1 deletion pinax/notifications/templates/pinax/notifications/full.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{% load i18n %}{% blocktrans %}{{ notice }}{% endblocktrans %}
{% autoescape off %}{% load i18n %}{% blocktrans %}{{ notice }}{% endblocktrans %}{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{% load i18n %}{% blocktrans %}{{ notice }}{% endblocktrans %}
{% autoescape off %}{% load i18n %}{% blocktrans %}{{ notice }}{% endblocktrans %}{% endautoescape %}
12 changes: 6 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ exclude = migrations/*,docs/*

[tox]
envlist =
py27-{1.8,1.9,master},
py33-{1.8},
py34-{1.8,1.9,master},
py35-{1.8,1.9,master}
py27-{1.8,1.9,1.10,master},
py34-{1.8,1.9,1.10,master},
py35-{1.8,1.9,1.10,master}

[testenv]
deps =
coverage == 4.0.2
flake8 == 2.5.0
py{27,33,34,35}: coverage==4.0.2
flake8==2.5.0
1.8: Django>=1.8,<1.9
1.9: Django>=1.9,<1.10
1.10: Django>=1.10,<1.11
master: https://github.com/django/django/tarball/master
usedevelop = True
setenv =
Expand Down