-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
35 lines (31 loc) · 1.23 KB
/
tasks.py
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
from celery import Celery
from django.conf import settings
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from common.models import Profile
from opportunity.models import Opportunity
app = Celery("redis://")
@app.task
def send_email_to_assigned_user(
recipients, opportunity_id
):
""" Send Mail To Users When they are assigned to a opportunity """
opportunity = Opportunity.objects.get(id=opportunity_id)
created_by = opportunity.created_by
for user in recipients:
recipients_list = []
profile = Profile.objects.filter(id=user, is_active=True).first()
if profile:
recipients_list.append(profile.user.email)
context = {}
context["url"] = settings.DOMAIN_NAME
context["user"] = profile.user
context["opportunity"] = opportunity
context["created_by"] = created_by
subject = "Assigned an opportunity for you."
html_content = render_to_string(
"assigned_to/opportunity_assigned.html", context=context
)
msg = EmailMessage(subject, html_content, to=recipients_list)
msg.content_subtype = "html"
msg.send()