1
|
|
|
import datetime |
2
|
|
|
import os |
3
|
|
|
from celery import task |
4
|
|
|
|
5
|
|
|
from django.template import Context, loader |
6
|
|
|
# from django.template.loader import get_template |
7
|
|
|
|
8
|
|
|
from wye.workshops.models import Workshop |
9
|
|
|
from wye.base.emailer_html import send_email_to_id |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
EMAIL_HOST = os.environ.get('EMAIL_HOST_USER', '') |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
def intro_emails(organisation, email_context, email_id): |
16
|
|
|
subject = '[PythonExpress] Intro for workshop at {}, {}'.format( |
17
|
|
|
organisation.name, organisation.location.name) |
18
|
|
|
email_body = loader.get_template( |
19
|
|
|
'email_messages/workshop/workshop_intro_email.html').render( |
20
|
|
|
email_context) |
21
|
|
|
text_body = loader.get_template( |
22
|
|
|
'email_messages/workshop/workshop_intro_email.txt').render( |
23
|
|
|
email_context) |
24
|
|
|
send_email_to_id( |
25
|
|
|
subject, |
26
|
|
|
body=email_body, |
27
|
|
|
email_id=email_id, |
28
|
|
|
text_body=text_body) |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
def feedback_emails(organisation, email_context, email_id): |
32
|
|
|
subject = '[PythonExpress] Request for Workshop Feedback {}, {}'.format( |
33
|
|
|
organisation.name, organisation.location.name) |
34
|
|
|
email_body = loader.get_template( |
35
|
|
|
'email_messages/workshop/feedback_email.html').render( |
36
|
|
|
email_context) |
37
|
|
|
text_body = loader.get_template( |
38
|
|
|
'email_messages/workshop/feedback_email.txt').render( |
39
|
|
|
email_context) |
40
|
|
|
send_email_to_id( |
41
|
|
|
subject, |
42
|
|
|
body=email_body, |
43
|
|
|
email_id=email_id, |
44
|
|
|
text_body=text_body) |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
@task |
48
|
|
|
def workshop_reminder(days, intro): |
49
|
|
|
""" |
50
|
|
|
send workshop reminder and intro email to all register user |
51
|
|
|
:return: |
52
|
|
|
""" |
53
|
|
|
workshop_date = datetime.date.today() + datetime.timedelta(days=days) |
54
|
|
|
workshops = Workshop.objects.select_related( |
55
|
|
|
'workshop_section').filter( |
56
|
|
|
expected_date=workshop_date).filter( |
57
|
|
|
is_active=True) |
58
|
|
|
|
59
|
|
|
for workshop in workshops: |
60
|
|
|
organisation = workshop.requester |
61
|
|
|
|
62
|
|
|
context_dict = { |
63
|
|
|
'date': workshop_date, |
64
|
|
|
'workshop_title': workshop.workshop_section.name, |
65
|
|
|
} |
66
|
|
|
if intro: |
67
|
|
|
context_dict['poc_list'] = workshop.requester.user.all() |
68
|
|
|
context_dict['presenter_list'] = workshop.presenter.all() |
69
|
|
|
email_context = Context(context_dict) |
70
|
|
|
# Below loop is to send email individually |
71
|
|
|
for requester in workshop.requester.user.all(): |
72
|
|
|
intro_emails(organisation, email_context, requester.email) |
73
|
|
|
for presenter in workshop.presenter.all(): |
74
|
|
|
intro_emails(organisation, email_context, presenter.email) |
75
|
|
|
else: |
76
|
|
|
for presenter in workshop.presenter.all(): |
77
|
|
|
context_dict['poc_list'] = workshop.requester.user.all() |
78
|
|
|
context_dict['presenter_list'] = workshop.presenter.all() |
79
|
|
|
email_context = Context(context_dict) |
80
|
|
|
subject = '[PythonExpress] Intro for workshop at {},{}'.format( |
81
|
|
|
organisation.name, organisation.location.name) |
82
|
|
|
email_body = loader.get_template( |
83
|
|
|
'email_messages/workshop/workshop_intro_email.html').render( |
84
|
|
|
email_context) |
85
|
|
|
text_body = loader.get_template( |
86
|
|
|
'email_messages/workshop/workshop_intro_email.txt').render( |
87
|
|
|
email_context) |
88
|
|
|
send_email_to_id( |
89
|
|
|
subject, |
90
|
|
|
body=email_body, |
91
|
|
|
email_id=presenter.email, |
92
|
|
|
text_body=text_body) |
93
|
|
|
|
94
|
|
|
return True |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
@task |
98
|
|
|
def workshop_feedback(days=None): |
99
|
|
|
today = datetime.datetime.today() |
100
|
|
|
if days: |
101
|
|
|
workshop_date = today + datetime.timedelta(days=2) |
102
|
|
|
workshops = Workshop.objects.filter(expected_date=workshop_date) |
103
|
|
|
|
104
|
|
|
for workshop in workshops: |
105
|
|
|
context_dict = { |
106
|
|
|
'date': workshop_date, |
107
|
|
|
'workshop_title': workshop.workshop_section.name, |
108
|
|
|
} |
109
|
|
|
email_context = Context(context_dict) |
110
|
|
|
organisation = workshop.requester |
111
|
|
|
for requester in workshop.requester.user.all(): |
112
|
|
|
feedback_emails(organisation, email_context, requester.email) |
113
|
|
|
for presenter in workshop.presenter.all(): |
114
|
|
|
feedback_emails(organisation, email_context, presenter.email) |
115
|
|
|
|
116
|
|
|
return True |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
# def get_workshop_recipients(workshop): |
120
|
|
|
# """ |
121
|
|
|
# Filter out all recipients including requesters as well as presenters |
122
|
|
|
# :param workshop: workshop object |
123
|
|
|
# :return: list of all recipients w.r.t workshop |
124
|
|
|
# """ |
125
|
|
|
|
126
|
|
|
# presenter_email = list() |
127
|
|
|
# requester_email = list() |
128
|
|
|
|
129
|
|
|
# requesters = workshop.requester.user.all() |
130
|
|
|
# for requester in requesters: |
131
|
|
|
# requester_email.append(requester.email) |
132
|
|
|
|
133
|
|
|
# presenters = workshop.presenter.all() |
134
|
|
|
# for presenter in presenters: |
135
|
|
|
# presenter_email.append(presenter.email) |
136
|
|
|
|
137
|
|
|
# recipients = presenter_email + requester_email |
138
|
|
|
|
139
|
|
|
# return recipients |
140
|
|
|
|