From c949cd31d178f85c223fbe045bab39d2dd0700a8 Mon Sep 17 00:00:00 2001
From: Akshen
Date: Tue, 20 Jun 2017 16:59:00 +0530
Subject: 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
---
workshop_app/data/Basic Python Schedule.pdf | Bin 55260 -> 0 bytes
.../data/Basics_of_Python/Basics_of_Python.pdf | Bin 0 -> 55260 bytes
.../instructions-for-coordinators.pdf | Bin 0 -> 36506 bytes
.../instructions-for-participants.pdf | Bin 0 -> 51627 bytes
workshop_app/data/ISCP schedule.pdf | Bin 32900 -> 0 bytes
workshop_app/data/ISCP/Basics_of_Python.pdf | Bin 0 -> 55260 bytes
workshop_app/data/ISCP/ISCP.pdf | Bin 0 -> 32900 bytes
.../data/ISCP/instructions-for-participants.pdf | Bin 0 -> 51627 bytes
workshop_app/data/flowchart.pdf | Bin 0 -> 27485 bytes
.../data/instructions-for-coordinators.pdf | Bin 36506 -> 0 bytes
.../data/instructions-for-participants.pdf | Bin 51627 -> 0 bytes
workshop_app/data/structure.pdf | Bin 27485 -> 0 bytes
workshop_app/forms.py | 3 +--
workshop_app/models.py | 9 +++++++
workshop_app/send_mails.py | 29 +++++++++------------
workshop_app/templates/workshop_app/index.html | 2 +-
workshop_app/views.py | 11 ++++----
17 files changed, 30 insertions(+), 24 deletions(-)
delete mode 100755 workshop_app/data/Basic Python Schedule.pdf
create mode 100644 workshop_app/data/Basics_of_Python/Basics_of_Python.pdf
create mode 100644 workshop_app/data/Basics_of_Python/instructions-for-coordinators.pdf
create mode 100644 workshop_app/data/Basics_of_Python/instructions-for-participants.pdf
delete mode 100755 workshop_app/data/ISCP schedule.pdf
create mode 100644 workshop_app/data/ISCP/Basics_of_Python.pdf
create mode 100644 workshop_app/data/ISCP/ISCP.pdf
create mode 100644 workshop_app/data/ISCP/instructions-for-participants.pdf
create mode 100644 workshop_app/data/flowchart.pdf
delete mode 100755 workshop_app/data/instructions-for-coordinators.pdf
delete mode 100755 workshop_app/data/instructions-for-participants.pdf
delete mode 100644 workshop_app/data/structure.pdf
diff --git a/workshop_app/data/Basic Python Schedule.pdf b/workshop_app/data/Basic Python Schedule.pdf
deleted file mode 100755
index 00401d0..0000000
Binary files a/workshop_app/data/Basic Python Schedule.pdf and /dev/null differ
diff --git a/workshop_app/data/Basics_of_Python/Basics_of_Python.pdf b/workshop_app/data/Basics_of_Python/Basics_of_Python.pdf
new file mode 100644
index 0000000..00401d0
Binary files /dev/null and b/workshop_app/data/Basics_of_Python/Basics_of_Python.pdf differ
diff --git a/workshop_app/data/Basics_of_Python/instructions-for-coordinators.pdf b/workshop_app/data/Basics_of_Python/instructions-for-coordinators.pdf
new file mode 100644
index 0000000..7601616
Binary files /dev/null and b/workshop_app/data/Basics_of_Python/instructions-for-coordinators.pdf differ
diff --git a/workshop_app/data/Basics_of_Python/instructions-for-participants.pdf b/workshop_app/data/Basics_of_Python/instructions-for-participants.pdf
new file mode 100644
index 0000000..93a3e5d
Binary files /dev/null and b/workshop_app/data/Basics_of_Python/instructions-for-participants.pdf differ
diff --git a/workshop_app/data/ISCP schedule.pdf b/workshop_app/data/ISCP schedule.pdf
deleted file mode 100755
index 203f5e0..0000000
Binary files a/workshop_app/data/ISCP schedule.pdf and /dev/null differ
diff --git a/workshop_app/data/ISCP/Basics_of_Python.pdf b/workshop_app/data/ISCP/Basics_of_Python.pdf
new file mode 100644
index 0000000..00401d0
Binary files /dev/null and b/workshop_app/data/ISCP/Basics_of_Python.pdf differ
diff --git a/workshop_app/data/ISCP/ISCP.pdf b/workshop_app/data/ISCP/ISCP.pdf
new file mode 100644
index 0000000..203f5e0
Binary files /dev/null and b/workshop_app/data/ISCP/ISCP.pdf differ
diff --git a/workshop_app/data/ISCP/instructions-for-participants.pdf b/workshop_app/data/ISCP/instructions-for-participants.pdf
new file mode 100644
index 0000000..93a3e5d
Binary files /dev/null and b/workshop_app/data/ISCP/instructions-for-participants.pdf differ
diff --git a/workshop_app/data/flowchart.pdf b/workshop_app/data/flowchart.pdf
new file mode 100644
index 0000000..35e6776
Binary files /dev/null and b/workshop_app/data/flowchart.pdf differ
diff --git a/workshop_app/data/instructions-for-coordinators.pdf b/workshop_app/data/instructions-for-coordinators.pdf
deleted file mode 100755
index 7601616..0000000
Binary files a/workshop_app/data/instructions-for-coordinators.pdf and /dev/null differ
diff --git a/workshop_app/data/instructions-for-participants.pdf b/workshop_app/data/instructions-for-participants.pdf
deleted file mode 100755
index 93a3e5d..0000000
Binary files a/workshop_app/data/instructions-for-participants.pdf and /dev/null differ
diff --git a/workshop_app/data/structure.pdf b/workshop_app/data/structure.pdf
deleted file mode 100644
index 35e6776..0000000
Binary files a/workshop_app/data/structure.pdf and /dev/null differ
diff --git a/workshop_app/forms.py b/workshop_app/forms.py
index ec6db80..b5c3d27 100644
--- a/workshop_app/forms.py
+++ b/workshop_app/forms.py
@@ -1,4 +1,3 @@
-
from django import forms
from django.utils import timezone
from .models import (
@@ -25,7 +24,7 @@ position_choices = (
)
department_choices = (
- ("computer", "Computer Science"),
+ ("computer engineering", "Computer Science"),
("information technology", "Information Technology"),
("civil engineering", "Civil Engineering"),
("electrical engineering", "Electrical Engineering"),
diff --git a/workshop_app/models.py b/workshop_app/models.py
index 9745fd3..35a1f38 100644
--- a/workshop_app/models.py
+++ b/workshop_app/models.py
@@ -3,6 +3,7 @@ from django.db import models
from django.contrib.auth.models import User
from django.core.validators import RegexValidator
from recurrence.fields import RecurrenceField
+import os
position_choices = (
("coordinator", "Coordinator"),
@@ -27,6 +28,9 @@ def has_profile(user):
""" check if user has profile """
return True if hasattr(user, 'profile') else False
+def attachments(instance, filename):
+ return os.sep.join((instance.workshoptype_name.replace(" ", '_'), filename))
+
class Profile(models.Model):
"""Profile for users(instructors and coordinators)"""
@@ -70,6 +74,11 @@ class WorkshopType(models.Model):
workshoptype_duration = models.CharField(max_length=32,
help_text='Please write this in \
following format eg: 3days, 8hours a day')
+ workshoptype_attachments = models.FileField(upload_to=attachments, blank=True,
+ help_text='Please upload workshop documents one by one, \
+ ie.workshop schedule, instructions etc. \
+ Please Note: Name of Schedule file should be similar to \
+ WorkshopType Name')
def __str__(self):
return u"{0} {1}".format(self.workshoptype_name,
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)
diff --git a/workshop_app/templates/workshop_app/index.html b/workshop_app/templates/workshop_app/index.html
index 4b57b46..e13677c 100644
--- a/workshop_app/templates/workshop_app/index.html
+++ b/workshop_app/templates/workshop_app/index.html
@@ -76,7 +76,7 @@