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

Commit

Permalink
Removed old example templates, changed __init__ function, so that aut…
Browse files Browse the repository at this point in the history
…ocompletion in IDE works
  • Loading branch information
Kevin Renskers committed Dec 1, 2011
1 parent dda8faf commit 4152cc2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Sending email should be as easy as creating an instance of the email class, prov
This email class doesn't know about mail queues. You can use a custom email backend or a project like [Django-mailer](https://github.com/jtauber/django-mailer) for that.

## Usage
from generic_email import Email
from generic_mail import Email

# This will send text email only, uses the email/base_text_email.html template with the "body" template variable
email = Email('to@example.com', 'Subject', 'Line one\n\nLine two')
Expand Down
18 changes: 12 additions & 6 deletions generic_mail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ class Email(object):
_custom_templates = False
_markdown = None

def __init__(self, **kwargs):
def __init__(self, to=None, subject=None, text_body=None, html_body=None, attachments=None, cc=None, bcc=None,
from_address=None, text_template=None, html_template=None, **kwargs):
"""
Init the class, the kwargs will be used as context variables
"""
for key in kwargs.copy():
if hasattr(self, key) and not key.startswith('_'):
setattr(self, key, kwargs[key])
del kwargs[key]

self.to = to or self.to
self.subject = subject or self.subject
self.attachments = attachments or self.attachments
self.cc = cc or self.cc
self.bcc = bcc or self.bcc
self.from_address = from_address or self.from_address
self.text_body = text_body or self.text_body
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

if self.text_template or self.html_template:
Expand Down
2 changes: 0 additions & 2 deletions generic_mail/templates/email/base_html_email.html
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<p>Hello,</p>
{{ body|safe }}
<p>Goodbye.</p>
4 changes: 0 additions & 4 deletions generic_mail/templates/email/base_text_email.html
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
Hello,

{{ body }}

This comment has been minimized.

Copy link
@hvdklauw

hvdklauw Dec 1, 2011

Contributor

Here you also want a |safe escape.

Reasoning: It's text mail and you don't want any html tags to be escaped, they will be displayed as is.
<strong> vs &lt;strong&gt;

This comment has been minimized.

Copy link
@kevinrenskers

kevinrenskers Dec 1, 2011

Owner

Will do


Goodbye.
3 changes: 0 additions & 3 deletions generic_mail/templates/email/my_html_email.html

This file was deleted.

5 changes: 0 additions & 5 deletions generic_mail/templates/email/my_text_email.html

This file was deleted.

0 comments on commit 4152cc2

Please sign in to comment.