From 81e4d53f97027b462075a08e303972be6b802aba Mon Sep 17 00:00:00 2001 From: Jacob Wegner Date: Mon, 31 Oct 2016 08:26:44 -0500 Subject: [PATCH 1/7] update test matrix --- tox.ini | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tox.ini b/tox.ini index 6ff14f48..f1eaf5d1 100644 --- a/tox.ini +++ b/tox.ini @@ -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 = From 98785040cd16d78454832aebdf24104b9d617a3e Mon Sep 17 00:00:00 2001 From: Jacob Wegner Date: Mon, 31 Oct 2016 11:10:50 -0500 Subject: [PATCH 2/7] pass dict to render_to_string (BI change) In Django 1.10+, render_to_string no longer accepts a context instance as an argument. To maintain existing behavior (templates ending in .txt aren't auto-escaped), developers should explicitly wrap their short.txt and full.txt templates in an autoescape block. https://docs.djangoproject.com/en/1.9/ref/templates/language/#for-template-blocks --- pinax/notifications/backends/base.py | 8 ++------ pinax/notifications/backends/email.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pinax/notifications/backends/base.py b/pinax/notifications/backends/base.py index 6b8ca759..fa789adc 100644 --- a/pinax/notifications/backends/base.py +++ b/pinax/notifications/backends/base.py @@ -1,4 +1,3 @@ -from django.template import Context from django.template.loader import render_to_string from django.contrib.sites.models import Site @@ -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) @@ -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 - }) + } diff --git a/pinax/notifications/backends/email.py b/pinax/notifications/backends/email.py index e46e8312..0f538dd0 100644 --- a/pinax/notifications/backends/email.py +++ b/pinax/notifications/backends/email.py @@ -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", { - "message": messages["short.txt"], - }, context).splitlines()) + context.update({ + "messages": messages["short.txt"], + }) + 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({ + "messages": messages["full.txt"] + }) + body = render_to_string("pinax/notifications/email_body.txt", context) send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [recipient.email]) From 4a947ff23d13c9cd49a3fc9c645ded98206a42d5 Mon Sep 17 00:00:00 2001 From: Jacob Wegner Date: Fri, 4 Nov 2016 11:42:34 -0500 Subject: [PATCH 3/7] set autoescape off explicitly in default plain text templates --- pinax/notifications/templates/pinax/notifications/full.txt | 2 +- pinax/notifications/templates/pinax/notifications/short.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pinax/notifications/templates/pinax/notifications/full.txt b/pinax/notifications/templates/pinax/notifications/full.txt index 01f21b36..f1c83ff3 100644 --- a/pinax/notifications/templates/pinax/notifications/full.txt +++ b/pinax/notifications/templates/pinax/notifications/full.txt @@ -1 +1 @@ -{% load i18n %}{% blocktrans %}{{ notice }}{% endblocktrans %} +{% autoescape off %}{% load i18n %}{% blocktrans %}{{ notice }}{% endblocktrans %}{% endautoescape %} diff --git a/pinax/notifications/templates/pinax/notifications/short.txt b/pinax/notifications/templates/pinax/notifications/short.txt index e70ad6e5..d7f78303 100644 --- a/pinax/notifications/templates/pinax/notifications/short.txt +++ b/pinax/notifications/templates/pinax/notifications/short.txt @@ -1 +1 @@ -{% load i18n %}{% blocktrans %}{{ notice }}{% endblocktrans %} \ No newline at end of file +{% autoescape off %}{% load i18n %}{% blocktrans %}{{ notice }}{% endblocktrans %}{% endautoescape %} \ No newline at end of file From 74ffd9fae0e2adf61a6bafafbbfd9f2d298ac2a6 Mon Sep 17 00:00:00 2001 From: Jacob Wegner Date: Fri, 4 Nov 2016 11:49:48 -0500 Subject: [PATCH 4/7] backfill changelog --- docs/changelog.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 628ec8d7..0af90624 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,24 @@ _*BI*_ = backward incompatible change +## 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 From e50f1cfb1cdc1ea5c6790a2810dc3492e79456fa Mon Sep 17 00:00:00 2001 From: Jacob Wegner Date: Fri, 4 Nov 2016 11:50:15 -0500 Subject: [PATCH 5/7] note backwards incompatible change --- docs/changelog.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 0af90624..646c2893 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,13 @@ _*BI*_ = backward incompatible change +## 4.0 +* _*BI*_: To support changes to `render_to_string` in Django 1.10 and above, +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 From eb7caaecbb1dae6fbc911fafcd40b6509fc5094f Mon Sep 17 00:00:00 2001 From: Jacob Wegner Date: Fri, 4 Nov 2016 12:19:08 -0500 Subject: [PATCH 6/7] clarify the user's notices must be autoescaped --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 646c2893..17deae03 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,7 +4,7 @@ _*BI*_ = backward incompatible change ## 4.0 * _*BI*_: To support changes to `render_to_string` in Django 1.10 and above, -plain text templates must now be autoescaped explicitly using the +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)) From 28dd70c7216d58e20786faa0a816f1dbe860e3ec Mon Sep 17 00:00:00 2001 From: Jacob Wegner Date: Fri, 4 Nov 2016 12:26:19 -0500 Subject: [PATCH 7/7] fix message variable name in context --- pinax/notifications/backends/email.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pinax/notifications/backends/email.py b/pinax/notifications/backends/email.py index 0f538dd0..fc7cd03b 100644 --- a/pinax/notifications/backends/email.py +++ b/pinax/notifications/backends/email.py @@ -32,12 +32,12 @@ def deliver(self, recipient, sender, notice_type, extra_context): ), notice_type.label, context) context.update({ - "messages": messages["short.txt"], + "message": messages["short.txt"], }) subject = "".join(render_to_string("pinax/notifications/email_subject.txt", context).splitlines()) context.update({ - "messages": messages["full.txt"] + "message": messages["full.txt"] }) body = render_to_string("pinax/notifications/email_body.txt", context)