Skip to content

Commit

Permalink
Merge pull request #139 from vintasoftware/feat/update-to-3.0.1
Browse files Browse the repository at this point in the history
Bump version: 3.0.0 → 3.0.1
  • Loading branch information
chocoelho authored Oct 22, 2022
2 parents cba05a7 + 989235d commit 6440f12
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 205 deletions.
3 changes: 1 addition & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[bumpversion]
current_version = 2.3.0
current_version = 3.0.1
commit = True
tag = True
tag_name = {new_version}

[bumpversion:file:setup.py]
search = VERSION = '{current_version}'
replace = VERSION = '{new_version}'

21 changes: 6 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
language: python

python:
- "3.5"

env:
- TOX_ENV=py27-flake8
- TOX_ENV=py35-django110
- TOX_ENV=py34-django110
- TOX_ENV=py27-django110
- TOX_ENV=py35-django19
- TOX_ENV=py34-django19
- TOX_ENV=py27-django19
- TOX_ENV=py35-django18
- TOX_ENV=py34-django18
- TOX_ENV=py27-django18
- "3.6"
- "3.7"
- "3.8"
- "3.9"

install:
- pip install tox
- pip install tox-travis
- pip install -r requirements.txt
- pip install coveralls

script:
- tox -e $TOX_ENV
- tox

after_script:
coveralls
17 changes: 17 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
v3.0.1
-----
Remove all newlines from subject

v3.0
-----
Add escaping to HTML parts in templates
Add tests for django main version

v2.4
-----
Add Python 3.7, 3.8 and 3.9 support
Drop Python <3.4 support
Add Django 3.1 and 3.2 support
Drop Django 3.0 support
Remove six dependency

v2.3
-----
Remove Django as explicit dependency
Expand Down
37 changes: 27 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ develop branch: https://github.com/vintasoftware/django-templated-email/blob/dev

stable pypi/master: https://github.com/vintasoftware/django-templated-email/blob/master/README.rst


Requirements
=================
* Python (3.6, 3.7, 3.8, 3.9)
* Django (2.2, 3.1, 3.2)

We **highly recommend** and only officially support the latest patch release of
each Python and Django series.


Getting going - installation
==============================

Expand Down Expand Up @@ -185,8 +195,8 @@ First get the image content from a file or a *ImageField*:
.. code-block:: python
# From a file
with open('lena.png', 'rb') as lena:
image = lena.read()
with open('pikachu.png', 'rb') as pikachu:
image = pikachu.read()
# From an ImageField
# Suppose we have this model
Expand All @@ -201,7 +211,7 @@ Then create an instance of *InlineImage*:
from templated_email import InlineImage
inline_image = InlineImage(filename="lena.png", content=image)
inline_image = InlineImage(filename="pikachu.png", content=image)
Now pass the object on the context to the template when you send the email.
Expand All @@ -210,13 +220,13 @@ Now pass the object on the context to the template when you send the email.
send_templated_mail(template_name='welcome',
from_email='from@example.com',
recipient_list=['to@example.com'],
context={'lena_image': inline_image})
context={'pikachu_image': inline_image})
Finally in your template add the image on the html template block:
.. code-block:: html
<img src="{{ lena_image }}">
<img src="{{ pikachu_image }}">
Note: All *InlineImage* objects you add to the context will be attached to the e-mail, even if they are not used in the template.
Expand Down Expand Up @@ -315,6 +325,7 @@ Methods:
**templated_email_get_recipients(self, form)** (mandatory):
Return the recipient list to whom the email will be sent to.
ie:

.. code-block:: python
def templated_email_get_recipients(self, form):
Expand All @@ -324,6 +335,7 @@ Methods:
Use this method to add extra data to the context used for rendering the template. You should get the parent class's context from
calling super.
ie:

.. code-block:: python
def templated_email_get_context_data(self, **kwargs):
Expand All @@ -334,6 +346,7 @@ Methods:
**templated_email_get_send_email_kwargs(self, valid, form)** (optional):
Add or change the kwargs that will be used to send the e-mail. You should call super to get the default kwargs.
ie:

.. code-block:: python
def templated_email_get_send_email_kwargs(valid, form):
Expand All @@ -356,7 +369,7 @@ Using django_templated_email in 3rd party applications

If you would like to use django_templated_email to handle mail in a reusable application, you should note that:

* Your calls to **send_templated_mail** should set a value for **template_dir**, so you can keep copies of your app-specific templates local to your app (although the loader will find your email templates if you store them in *<your app>/templates/templated_email*, if **TEMPLATED_EMAIL_TEMPLATE_DIR** has not been overidden)
* Your calls to **send_templated_mail** should set a value for **template_dir**, so you can keep copies of your app-specific templates local to your app (although the loader will find your email templates if you store them in *<your app>/templates/templated_email*, if **TEMPLATED_EMAIL_TEMPLATE_DIR** has not been overridden)
* If you do (and you should) set a value for **template_dir**, remember to include a trailing slash, i.e. *'my_app_email/'*
* The deployed app may use a different backend which doesn't use the django templating backend, and as such make a note in your README warning developers that if they are using django_templated_email already, with a different backend, they will need to ensure their email provider can send all your templates (ideally enumerate those somewhere convenient)

Expand Down Expand Up @@ -402,21 +415,25 @@ Execute the following commands::

bumpversion [major,minor,patch]
python setup.py publish
git push origin master --tags
git push origin --tags


Commercial Support
==================

This library, as others, is used in projects of Vinta clients. We are always looking for exciting work, so if you need any commercial support, feel free to get in touch: contact@vinta.com.br
.. image:: https://avatars2.githubusercontent.com/u/5529080?s=80&v=4
:alt: Vinta Logo
:target: https://www.vinta.com.br

This project, as other `Vinta Software <https://www.vinta.com.br/>`_ open-source projects is used in products of Vinta's clients. We are always looking for exciting work, so if you need any commercial support, feel free to get in touch: contact@vinta.com.br



.. _Django: http://djangoproject.com
.. |GitterBadge| image:: https://badges.gitter.im/vintasoftware/django-templated-email.svg
.. _GitterBadge: https://gitter.im/vintasoftware/django-templated-email?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
.. |TravisBadge| image:: https://travis-ci.org/vintasoftware/django-templated-email.svg?branch=develop
.. _TravisBadge: https://travis-ci.org/vintasoftware/django-templated-email
.. |TravisBadge| image:: https://travis-ci.com/vintasoftware/django-templated-email.svg?branch=develop
.. _TravisBadge: https://travis-ci.com/vintasoftware/django-templated-email
.. |CoverageBadge| image:: https://coveralls.io/repos/github/vintasoftware/django-templated-email/badge.svg?branch=develop
.. _CoverageBadge: https://coveralls.io/github/vintasoftware/django-templated-email?branch=develop
.. |PypiversionBadge| image:: https://img.shields.io/pypi/v/django-templated-email.svg
Expand Down
14 changes: 6 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
from setuptools import setup, find_packages

DESCRIPTION = "A Django oriented templated / transaction email abstraction"
VERSION = '2.3.0'
VERSION = '3.0.1'
LONG_DESCRIPTION = None
try:
LONG_DESCRIPTION = open('README.rst').read()
except:
pass

requirements = [
'django-render-block>=0.5',
'six>=1',
'django-render-block>=0.5'
]

# python setup.py publish
Expand All @@ -25,12 +24,10 @@
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Software Development :: Libraries :: Python Modules',
'Framework :: Django',
]
Expand All @@ -46,6 +43,7 @@
license='MIT',
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type='text/x-rst',
platforms=['any'],
classifiers=CLASSIFIERS,
install_requires=requirements,
Expand Down
4 changes: 1 addition & 3 deletions templated_email/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.conf import settings
from django.utils.module_loading import import_string

import six

from templated_email.backends.vanilla_django import TemplateBackend
from templated_email.utils import InlineImage # noqa

Expand All @@ -20,7 +18,7 @@ def get_connection(backend=None, template_prefix=None, template_suffix=None,
# django.core.mail.get_connection
klass_path = backend or getattr(settings, 'TEMPLATED_EMAIL_BACKEND',
TemplateBackend)
if isinstance(klass_path, six.string_types):
if isinstance(klass_path, str):
try:
# First check if class name is omitted and we have module in settings
klass = import_string(klass_path + '.' + 'TemplateBackend')
Expand Down
6 changes: 3 additions & 3 deletions templated_email/backends/vanilla_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.core.mail import get_connection
from django.template import Context
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django.core.files.storage import default_storage

from templated_email.utils import (
Expand Down Expand Up @@ -82,7 +82,6 @@ def _render_email(self, template_name, context,
template_dir=None, file_extension=None):
response = {}
errors = {}
render_context = Context(context, autoescape=False)

file_extension = file_extension or self.template_suffix
if file_extension.startswith('.'):
Expand All @@ -102,6 +101,7 @@ def _render_email(self, template_name, context,
full_template_names.append(one_full_template_name)

for part in ['subject', 'html', 'plain']:
render_context = Context(context, autoescape=(part == 'html'))
try:
response[part] = render_block_to_string(full_template_names, part, render_context)
except BlockNotFound as error:
Expand Down Expand Up @@ -158,7 +158,7 @@ def get_email_message(self, template_name, context, from_email=None, to=None,
subject_template = subject_dict.get(template_name,
_('%s email subject' % template_name))
subject = subject_template % context
subject = subject.strip('\n\r') # strip newlines from subject
subject = subject.strip('\n\r').replace('\n', ' ').replace('\r', ' ') # strip newlines from subject

if not plain_part:
plain_part = self._generate_plain_part(parts)
Expand Down
1 change: 0 additions & 1 deletion templated_email/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-10-05 17:09
from __future__ import unicode_literals

from django.db import migrations, models
import uuid
Expand Down
4 changes: 2 additions & 2 deletions templated_email/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.conf.urls import url
from django.urls import re_path

from templated_email.views import ShowEmailView

app_name = 'templated_email'
urlpatterns = [
url(r'^email/(?P<uuid>([a-f\d]{32})|([a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12}))/$', ShowEmailView.as_view(), name='show_email'),
re_path(r'^email/(?P<uuid>([a-f\d]{32})|([a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12}))/$', ShowEmailView.as_view(), name='show_email'),
]
4 changes: 1 addition & 3 deletions templated_email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
from django.utils.module_loading import import_string
from django.conf import settings

import six


def _get_klass_from_config(config_variable, default):
klass_path = getattr(settings, config_variable, default)
if isinstance(klass_path, six.string_types):
if isinstance(klass_path, str):
klass_path = import_string(klass_path)

return klass_path
Expand Down
Loading

0 comments on commit 6440f12

Please sign in to comment.