Skip to content

Commit 9e93383

Browse files
author
elbuo8
committed
PEP8 all the things and better version mgmt
1 parent 964b9fd commit 9e93383

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from setuptools import setup, find_packages
22

3+
execfile('sgbackend/version.py')
4+
35
setup(
46
name='sendgrid-django',
5-
version='1.0.2',
7+
version=str(__version__),
68
author='Yamil Asusta',
79
author_email='yamil@sendgrid.com',
810
url='https://github.com/elbuo8/sendgrid-django',

sgbackend/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from .mail import SendGridBackend
1+
from .mail import SendGridBackend
2+
from .version import __version__

sgbackend/mail.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@
1010
except Exception as e:
1111
import email.utils as rfc822
1212

13+
1314
class SendGridBackend(BaseEmailBackend):
1415
'''
1516
SendGrid Web API Backend
1617
'''
1718
def __init__(self, fail_silently=False, **kwargs):
18-
super(SendGridBackend, self).__init__(fail_silently=fail_silently, **kwargs)
19+
super(SendGridBackend, self).__init__(
20+
fail_silently=fail_silently, **kwargs)
1921
self.api_user = getattr(settings, "SENDGRID_USER", None)
20-
self.api_key = getattr(settings, "SENDGRID_PASSWORD", None)
22+
self.api_key = getattr(settings, "SENDGRID_PASSWORD", None)
2123

22-
if self.api_user == None or self.api_key == None:
23-
raise ImproperlyConfigured('''Either SENDGRID_USER or SENDGRID_PASSWORD
24+
if self.api_user is None or self.api_key is None:
25+
raise ImproperlyConfigured('''
26+
Either SENDGRID_USER or SENDGRID_PASSWORD
2427
was not declared in settings.py''')
25-
self.sg = sendgrid.SendGridClient(self.api_user, self.api_key, raise_errors= not fail_silently)
28+
self.sg = sendgrid.SendGridClient(
29+
self.api_user, self.api_key,
30+
raise_errors=not fail_silently)
2631

2732
def open(self):
2833
pass
@@ -62,14 +67,14 @@ def _build_sg_mail(self, email):
6267
for alt in email.alternatives:
6368
if alt[1] == "text/html":
6469
mail.set_html(alt[0])
65-
if email.cc and not self.fail_silently:
66-
raise Exception("CC list must be empty for SendGridHttpsBackEnd. CC not supported by the web API")
6770

6871
for attachment in email.attachments:
6972
if isinstance(attachment, MIMEBase):
70-
mail.add_attachment_stream(attachment.get_filename(), attachment.get_payload())
73+
mail.add_attachment_stream(
74+
attachment.get_filename(),
75+
attachment.get_payload())
7176
elif isinstance(attachment, tuple):
72-
mail.add_attachment_stream(attachment[0],attachment[1])
77+
mail.add_attachment_stream(attachment[0], attachment[1])
7378

7479
if email.extra_headers:
7580
if "Reply-To" in email.extra_headers:

0 commit comments

Comments
 (0)