Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
Fix default text template, add correct dependancies, update version t…
Browse files Browse the repository at this point in the history
…o 0.2
  • Loading branch information
Kevin Renskers committed Dec 1, 2011
1 parent 4152cc2 commit a1aa1d6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ This email class doesn't know about mail queues. You can use a custom email back
# This will generate an error: when using default templates, you need to give at least one body (text or html)
email = Email('to@example.com', 'Subject')
email.send()

## Subclassing
If you want to create your own subclass that has different defaults (other templates, subject, etc), the best way to do
this is by changing the class properties instead of overriding the `__init__` method.
13 changes: 7 additions & 6 deletions generic_mail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ class Email(object):
text_template = None
html_template = None

kwargs = None

_default_text_template = 'email/base_text_email.html'
_default_html_template = 'email/base_html_email.html'
_kwargs = None
_context = None
_custom_templates = False
_markdown = None
Expand All @@ -62,7 +61,7 @@ def __init__(self, to=None, subject=None, text_body=None, html_body=None, attach
self.html_body = html_body or self.html_body
self.text_template = text_template or self.text_template
self.html_template = html_template or self.html_template
self.kwargs = kwargs
self._kwargs = kwargs

if self.text_template or self.html_template:
self._custom_templates = True
Expand Down Expand Up @@ -114,7 +113,7 @@ def get_context(self):
'text_body': self.get_text_body(),
'html_body': self.get_html_body()
}
self._context.update(self.kwargs)
self._context.update(self._kwargs)

return self._context

Expand Down Expand Up @@ -226,10 +225,12 @@ def send(self, text=None, html=None, fail_silent=False):
# and html_body is required when we want to send html email
if not self._custom_templates:
if send_text and not (self.text_body or self.html_body):
raise BodyNotSetException('When using the default email templates, and you want to send text, you will need to provide a body (either text_body or html_body)')
raise BodyNotSetException('When using the default email templates, and you want to send text,\
you will need to provide a body (either text_body or html_body)')

if send_html and not (self.html_body or self.text_body):
raise BodyNotSetException('When using the default email templates, and you want to send html, you will need to provide a body (either text_body or html_body)')
raise BodyNotSetException('When using the default email templates, and you want to send html,\
you will need to provide a body (either text_body or html_body)')

message = self.create_message(send_text, send_html)
if message:
Expand Down
2 changes: 1 addition & 1 deletion generic_mail/templates/email/base_text_email.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ body }}
{{ body|safe }}
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="django-generic-mail",
version='0.1',
version='0.2',
description="Easy to use, class based email for Django",
long_description=open("README.md").read(),
author="Kevin Renskers",
Expand All @@ -11,6 +11,10 @@
packages=[
"generic_mail",
],
install_requires=[
"django >= 1.2",
"Markdown",
],
package_dir={"generic_mail": "generic_mail"},
classifiers=[
"Development Status :: 4 - Beta",
Expand Down

0 comments on commit a1aa1d6

Please sign in to comment.