diff options
author | pnshiralkar | 2020-05-18 21:03:36 +0530 |
---|---|---|
committer | pnshiralkar | 2020-05-18 21:03:36 +0530 |
commit | f3d52e04644857eac3c10f1788e46a5e29e1b4ae (patch) | |
tree | 420a467edb747a7a70f631f0d286b5f68434e0bd /workshop_app | |
parent | 5d8b002b48da791b090314a2df3e500734b5b62f (diff) | |
download | workshop_booking-f3d52e04644857eac3c10f1788e46a5e29e1b4ae.tar.gz workshop_booking-f3d52e04644857eac3c10f1788e46a5e29e1b4ae.tar.bz2 workshop_booking-f3d52e04644857eac3c10f1788e46a5e29e1b4ae.zip |
Fixed accept workshop without files bug
Diffstat (limited to 'workshop_app')
-rw-r--r-- | workshop_app/send_mails.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/workshop_app/send_mails.py b/workshop_app/send_mails.py index a704ee1..d4a11b7 100644 --- a/workshop_app/send_mails.py +++ b/workshop_app/send_mails.py @@ -3,6 +3,8 @@ __author__ = "Akshen Doke" import hashlib import logging import logging.config +import os + import yaml import re from django.core.mail import send_mail @@ -225,7 +227,10 @@ def send_email( request, call_on, format(workshop_date) msg = EmailMultiAlternatives(subject, message, SENDER_EMAIL, [request.user.email]) attachment_paths = path.join(settings.MEDIA_ROOT, workshop_title.replace(" ","_")) - files = listdir(attachment_paths) + if os.path.exists(attachment_paths): + files = listdir(attachment_paths) + else: + files = [] for f in files: attachment = open(path.join(attachment_paths, f), 'rb') part = MIMEBase('application', 'octet-stream') @@ -257,7 +262,10 @@ def send_email( request, call_on, format(workshop_date) msg = EmailMultiAlternatives(subject, message, SENDER_EMAIL, [other_email]) attachment_paths = path.join(settings.MEDIA_ROOT, workshop_title.replace(" ","_")) - files = listdir(attachment_paths) + if os.path.exists(attachment_paths): + files = listdir(attachment_paths) + else: + files = [] for f in files: attachment = open(path.join(attachment_paths, f), 'rb') part = MIMEBase('application', 'octet-stream') @@ -392,7 +400,7 @@ def send_email( request, call_on, workshop_date, new_workshop_date)) logging.info("Workshop Date Changed Done by {0} from {1} to {2}" - .format(request.user.email, + .format(request.user.email, new_workshop_date, workshop_date)) try: send_mail( @@ -419,7 +427,7 @@ def send_email( request, call_on, try: send_mail( - "FOSSEE Python Workshop Date Changed", + "FOSSEE Python Workshop Date Changed", message, SENDER_EMAIL, [other_email], fail_silently=True ) |