Skip to content

Commit b657a1e

Browse files
committed
Version 0.4.0 with support for Django 1.11. Closes #23
1 parent d5f5efe commit b657a1e

File tree

14 files changed

+33
-41
lines changed

14 files changed

+33
-41
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/django_yubin.egg-info/
55
/docs/_build
66
.idea/*
7+
.vscode/
78
.eggs/
89
.DS_Store
910

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ env:
1717
- TOXENV=py27-django18
1818
- TOXENV=py27-django19
1919
- TOXENV=py27-django110
20+
- TOXENV=py27-django111
2021

2122
- TOXENV=py33-django18
2223

2324
- TOXENV=py34-django18
2425
- TOXENV=py34-django19
2526
- TOXENV=py34-django110
27+
- TOXENV=py34-django111
2628

2729
- TOXENV=py35-django18
2830
- TOXENV=py35-django19
2931
- TOXENV=py35-django110
32+
- TOXENV=py35-django111

README.rst

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ django-yubin
1919

2020
Django Yubin allows the programmer to control when he wants to send the e-mail
2121
in this application, making the web application to answer fast as it not has to
22-
wait for the mail server.
22+
wait for the mail server.
2323

2424
As in our projects we use always two django packages for dealing with emails:
2525
django-mailer2 (our own fork in APSL) and django-mailviews to compose the
2626
emails we decided to create this package to fit our own needs and share with
2727
the community.
2828

2929
As you can see it seems django-mailer2 is not accepting patches, so in
30-
order to put a new version on pypi a new name was mandatory. So django-yubin was born
30+
order to put a new version on pypi a new name was mandatory. So django-yubin was born
3131
(yubin is postal mail in japanese). The name attribution is for @morenosan.
3232

3333
How it works
@@ -48,8 +48,8 @@ Advantages
4848

4949
* Yubin allows to define prioritary queues, resend e-mails
5050

51-
* Yubin helps in your development. It's a good way to work when you're developping
52-
the application and you don't want to flood your test users with
51+
* Yubin helps in your development. It's a good way to work when you're developping
52+
the application and you don't want to flood your test users with
5353
e-mails. With Django Yubin, and without running the cron commands, you can see how
5454
your e-mails are, retrieve them and even delete them with out sending it.
5555

@@ -58,7 +58,7 @@ someting like
5858

5959
* * * * * (cd $PROJECT; python manage.py send_mail >> $PROJECT/cron_mail.log 2>&1)
6060

61-
This will send the queued e-mail every minute.
61+
This will send the queued e-mail every minute.
6262

6363
Django Yubin is a fork from django-mailer2 with some addtions from django-mailviews and
6464
additional improvements made from apsl.net that we need for our daly basis workd. It
@@ -81,6 +81,7 @@ You can read the package documentation at http://django-yubin.readthedocs.org/en
8181

8282
Changelog
8383
---------
84+
* 0.4.0 Support Django 1.11: subject and body are no longer unscaped, you need to add {% autoescape off %} to your non HTML templates.
8485
* 0.3.1 Delete unused template that caused an error with django-compressor offline. testmail command now generates HTML emails.
8586
* 0.3.0 Support Django >= 1.8 and <=1.10, Python 2.7, 3.3, 3.4 and 3.5. Re-send mails admin action. Fix bug in status_mail command. Demo project configured to send mails with the same mail fake-server used for tests.
8687
* 0.2.3 Removed {% load url from future %} to support Django 1.9. Now Django < 1.5 is not supported.

demo/demo.sqlite

4 KB
Binary file not shown.

demo/demo/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44

55
from django.views.generic import TemplateView
66

7+
78
class IndexView(TemplateView):
89
template_name = 'index.html'

django_yubin/mail_utils.py

-10
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
# ----------------------------------------------------------------------------
44

55
import hashlib
6-
from django.template import Context
76

87

98
def unimplemented(*args, **kwargs):
109
raise NotImplementedError
1110

1211

13-
def unescape(context):
14-
"""
15-
Accepts a context object, returning a new context with autoescape off.
16-
17-
Useful for rendering plain-text templates without having to wrap the entire
18-
template in an `{% autoescape off %}` tag.
19-
"""
20-
return Context(context, autoescape=False)
21-
2212
class Attachment(object):
2313
"""
2414
Utility class to contain the attachment information

django_yubin/messages.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
from django.template.loader import get_template, select_template
1515
from django.contrib.sites.models import Site
1616

17-
from django_yubin.mail_utils import unescape
18-
19-
2017

2118
class EmailMessageView(object):
2219
"""
@@ -196,35 +193,28 @@ def _set_body_template(self, template):
196193
#: will be used instead.
197194
body_template = property(_get_body_template, _set_body_template)
198195

199-
200196
def render_subject(self, context):
201197
"""
202198
Renders the message subject for the given context.
203199
204-
The context data is automatically unescaped to avoid rendering HTML
205-
entities in ``text/plain`` content.
206-
207200
:param context: The context to use when rendering the subject template.
208201
:type context: :class:`~django.template.Context`
209202
:returns: A rendered subject.
210203
:rtype: :class:`str`
211204
"""
212-
rendered = self.subject_template.render(unescape(context))
205+
rendered = self.subject_template.render(context)
213206
return rendered.strip()
214207

215208
def render_body(self, context):
216209
"""
217210
Renders the message body for the given context.
218211
219-
The context data is automatically unescaped to avoid rendering HTML
220-
entities in ``text/plain`` content.
221-
222212
:param context: The context to use when rendering the body template.
223213
:type context: :class:`~django.template.Context`
224214
:returns: A rendered body.
225215
:rtype: :class:`str`
226216
"""
227-
return self.body_template.render(unescape(context))
217+
return self.body_template.render(context)
228218

229219

230220
class TemplatedHTMLEmailMessageView(TemplatedEmailMessageView):

docs/contributing.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ the next section you'll find information about how to write the test.
1717
Please follow the PEP8 coventions and in case you write additional features don't
1818
forget to write the tests for them.
1919

20-
At http://apsl.net we use yubin for most of our own projects, so we'll try to
20+
At http://apsl.net we use yubin for most of our own projects, so we'll try to
2121
mantain it as bug free as stable as possible. That said we can't not guarantee
2222
that we could patch the program in the way you like, add that new feature, etc.
2323

@@ -50,7 +50,7 @@ of the Python versions you have installed in your system (Python 2.7, 3.2 until
5050
Run ``detox`` if you prefer parallelizing. To run a single environment, you have
5151
some options::
5252

53-
$ tox -e py27-django19 # run Python 2.7 and Django 1.9
53+
$ tox -e py35-django111 # run Python 3.4 and Django 1.11
5454

5555
or, in a virtualenv for example::
5656

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
setup(
2424
name='django-yubin',
25-
version='0.3.1',
25+
version='0.4.0',
2626
description=("A reusable Django app for composing and queueing emails "
2727
"Adds django-mailer2 + django-mailviews + others"),
2828
long_description=long_description,
@@ -55,5 +55,6 @@
5555
'Framework :: Django :: 1.8',
5656
'Framework :: Django :: 1.9',
5757
'Framework :: Django :: 1.10',
58+
'Framework :: Django :: 1.11',
5859
]
5960
)

tests/tests/templates/mail/body.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{ body }}
1+
{% autoescape off %}{{ body }}{% endautoescape %}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{ subject }}
1+
{% autoescape off %}{{ subject }}{% endautoescape %}

tests/tests/test_messages.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def setUp(self):
7373
self.context = Context(self.context_dict)
7474

7575
self.render_subject = functools.partial(self.message.render_subject,
76-
context=self.context)
76+
context=self.context)
7777
self.render_body = functools.partial(self.message.render_body,
78-
context=self.context)
78+
context=self.context)
7979

8080
def add_templates_to_message(self):
8181
"""
@@ -99,7 +99,7 @@ def test_subject_template_name(self):
9999
self.assertTemplateExists(template)
100100

101101
self.message.subject_template_name = template
102-
self.assertEqual(self.render_subject(), self.subject)
102+
self.assertEqual(self.render_subject(context=self.context_dict), self.subject)
103103

104104
def test_subject_template(self):
105105
self.message.subject_template = self.subject_template
@@ -120,7 +120,7 @@ def test_body_template_name(self):
120120
self.assertTemplateExists(template)
121121

122122
self.message.body_template_name = template
123-
self.assertEqual(self.render_body(), u"%s\n" % self.body)
123+
self.assertEqual(self.render_body(context=self.context_dict), u"%s\n" % self.body)
124124

125125
def test_body_template(self):
126126
self.message.body_template = self.body_template
@@ -204,7 +204,7 @@ def test_html_body_template_name(self):
204204
self.assertTemplateExists(template)
205205

206206
self.message.html_body_template_name = template
207-
self.assertEqual(self.render_html_body(), u"%s\n" % self.html_body)
207+
self.assertEqual(self.render_html_body(context=self.context_dict), u"%s\n" % self.html_body)
208208

209209
def test_html_body_template(self):
210210
self.message.html_body_template = self.html_body_template
@@ -250,7 +250,8 @@ def add_templates_to_message(self):
250250
def test_render_to_message(self):
251251
self.add_templates_to_message()
252252
attachment = os.path.join(os.path.dirname(__file__), 'files/attachment.pdf'),
253-
message = self.message.render_to_message(extra_context=self.context_dict, attachment=attachment,
253+
message = self.message.render_to_message(extra_context=self.context_dict,
254+
attachment=attachment,
254255
mimetype="application/pdf")
255256
self.assertEqual(message.subject, self.subject)
256257
self.assertEqual(message.body, self.body)
@@ -290,9 +291,9 @@ def setUp(self):
290291
self.context = Context(self.context_dict)
291292

292293
self.render_subject = functools.partial(self.message.render_subject,
293-
context=self.context)
294+
context=self.context_dict)
294295
self.render_body = functools.partial(self.message.render_body,
295-
context=self.context)
296+
context=self.context_dict)
296297

297298
def add_templates_to_message(self):
298299
"""

tests/urls.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
urlpatterns = []

tox.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py{27,py,33,34,35}-django{18},py{27,py,34,35}-django{19,110}
2+
envlist = py{27,py,33,34,35}-django{18},py{27,py,34,35}-django{19,110,111}
33
skip_missing_interpreters = true
44

55
[testenv]
@@ -9,6 +9,7 @@ deps =
99
django18: Django>=1.8,<1.9
1010
django19: Django>=1.9,<1.10
1111
django110: Django>=1.10,<1.11
12+
django111: Django>=1.11,<1.12
1213
commands=
1314
coverage run --rcfile={toxinidir}/.coveragerc {toxinidir}/setup.py test
1415
coverage report --omit=*test*

0 commit comments

Comments
 (0)