-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtasks.py
More file actions
115 lines (93 loc) · 3.66 KB
/
tasks.py
File metadata and controls
115 lines (93 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from notifications.models import EmailTemplate, EmailTemplateIdentifier
from integrations import slack
from grants.tasks import get_name
from users.models import User
import logging
from pycon.celery import app
logger = logging.getLogger(__name__)
@app.task
def notify_new_cfp_submission(*, submission_id, conference_id, admin_url):
from conferences.models import Conference
from submissions.models import Submission
conference = Conference.objects.get(id=conference_id)
submission = Submission.objects.get(id=submission_id)
title = submission.title.localize("en")
elevator_pitch = submission.elevator_pitch.localize("en")
submission_type = submission.type.name
speaker_id = submission.speaker_id
tags = ",".join(submission.tags.values_list("name", flat=True))
speaker = User.objects.get(id=speaker_id)
user_name = get_name(speaker)
slack.send_message(
[
{
"type": "section",
"text": {
"text": f"New _{submission_type}_ proposal by {user_name}",
"type": "mrkdwn",
},
}
],
[
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"*<{admin_url}|{title.capitalize()}>*\n"
f"*Elevator Pitch*\n{elevator_pitch}",
},
"fields": [
{"type": "mrkdwn", "text": "*Tags*"},
{"type": "plain_text", "text": str(tags)},
],
}
]
}
],
oauth_token=conference.get_slack_oauth_token(),
channel_id=conference.slack_new_proposal_channel_id,
)
@app.task
def send_proposal_rejected_email(proposal_id):
from submissions.models import Submission
proposal = Submission.objects.get(id=proposal_id)
proposal_speaker = proposal.speaker
conference = proposal.conference
language_code = proposal.languages.first().code
conference_name = proposal.conference.name
email_template = EmailTemplate.objects.for_conference(conference).get_by_identifier(
EmailTemplateIdentifier.proposal_rejected
)
email_template.send_email(
recipient=proposal_speaker,
placeholders={
"proposal_title": proposal.title.localize(language_code),
"proposal_type": proposal.type.name,
"conference_name": conference_name,
"speaker_name": get_name(proposal_speaker, "there"),
},
)
logger.info("Sending email to speaker for rejected proposal %s", proposal.id)
@app.task
def send_proposal_in_waiting_list_email(proposal_id):
from submissions.models import Submission
proposal = Submission.objects.get(id=proposal_id)
proposal_speaker = proposal.speaker
conference = proposal.conference
language_code = proposal.languages.first().code
conference_name = proposal.conference.name
email_template = EmailTemplate.objects.for_conference(conference).get_by_identifier(
EmailTemplateIdentifier.proposal_in_waiting_list
)
email_template.send_email(
recipient=proposal_speaker,
placeholders={
"proposal_title": proposal.title.localize(language_code),
"proposal_type": proposal.type.name,
"conference_name": conference_name,
"speaker_name": get_name(proposal_speaker, "there"),
},
)
logger.info("Sending email to speaker in waiting list for proposal %s", proposal.id)