summaryrefslogtreecommitdiff
path: root/workshop_app/send_mails.py
diff options
context:
space:
mode:
authorAkshen2017-06-20 16:59:00 +0530
committerAkshen2017-06-20 16:59:00 +0530
commitc949cd31d178f85c223fbe045bab39d2dd0700a8 (patch)
treeb8b055e9b39f10c1963bb40cbcc41eecd0a0f8c6 /workshop_app/send_mails.py
parentd476027b82acf9cd224736790df0514633b13ded (diff)
downloadworkshop_booking-c949cd31d178f85c223fbe045bab39d2dd0700a8.tar.gz
workshop_booking-c949cd31d178f85c223fbe045bab39d2dd0700a8.tar.bz2
workshop_booking-c949cd31d178f85c223fbe045bab39d2dd0700a8.zip
Changes WorkshopType Model
- FileField Added to workshoptype model - Creates folder for each file upload - Send email uses the newly created folder to send attachments - structure name changed to flowchart
Diffstat (limited to 'workshop_app/send_mails.py')
-rw-r--r--workshop_app/send_mails.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/workshop_app/send_mails.py b/workshop_app/send_mails.py
index 7eb5fff..3f2e7c2 100644
--- a/workshop_app/send_mails.py
+++ b/workshop_app/send_mails.py
@@ -28,6 +28,7 @@ from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from time import sleep
+from .models import WorkshopType
def generate_activation_key(username):
"""Generates hashed secret key for email activation"""
@@ -239,20 +240,16 @@ def send_email( request, call_on,
subject = "FOSSEE Workshop booking confirmation on {0}".\
format(workshop_date)
msg = EmailMultiAlternatives(subject, message, SENDER_EMAIL, [request.user.email])
-
- files = listdir(settings.MEDIA_ROOT)
+ attachment_paths = path.join(settings.MEDIA_ROOT, workshop_title.replace(" ","_"))
+ files = listdir(attachment_paths)
for f in files:
- print(f, workshop_title)
- if f == workshop_title+' schedule.pdf' or \
- f == 'instructions-for-coordinators.pdf' or \
- f == 'instructions-for-participants.pdf':
- attachment = open(path.join(settings.MEDIA_ROOT,f), 'rb')
- part = MIMEBase('application', 'octet-stream')
- part.set_payload((attachment).read())
- encoders.encode_base64(part)
- part.add_header('Content-Disposition', "attachment; filename= %s " % f)
- msg.attach(part)
- sleep(1)
+ attachment = open(path.join(attachment_paths, f), 'rb')
+ part = MIMEBase('application', 'octet-stream')
+ part.set_payload((attachment).read())
+ encoders.encode_base64(part)
+ part.add_header('Content-Disposition', "attachment; filename= %s " % f)
+ msg.attach(part)
+ sleep(1)
msg.send()
else:
@@ -275,10 +272,10 @@ def send_email( request, call_on,
subject = "FOSSEE Workshop booking confirmation on {0}".\
format(workshop_date)
msg = EmailMultiAlternatives(subject, message, SENDER_EMAIL, [other_email])
-
- files = listdir(settings.MEDIA_ROOT)
+ attachment_paths = path.join(settings.MEDIA_ROOT, workshop_title.replace(" ","_"))
+ files = listdir(attachment_paths)
for f in files:
- attachment = open(path.join(settings.MEDIA_ROOT,f), 'rb')
+ attachment = open(path.join(attachment_paths, f), 'rb')
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)