· 6 years ago · Jun 24, 2019, 10:34 PM
1class pdf_email(View):
2
3 def get(self, request, airport_code='ORD', date_code=None, shift_code=None):
4
5 dates = get_perf_dates(date_code)
6 params = {"airportcode": airport_code,
7 "perfdates": dates,
8 "shift": shift_code,
9 "request": request
10 }
11
12 file = Render.render_to_file('pdf_report.html', params)
13
14 mail_d_list = []
15 for users in DistributionList.objects.all(): #.values_list('email', flat=True)
16 mail_d_list.append(users.email)
17 mail_name.append(users.name)
18 mail_subject = "Daily Report"
19 mail_content = "This is an automated message."
20 mail_from = '######@gmail.com'
21
22 email = EmailMessage(mail_subject,
23 mail_content,
24 mail_from,
25 mail_d_list,
26 )
27 file_name = "report.pdf"
28 file_path = os.path.join(os.path.abspath(os.path.dirname("__file__")), "store", file_name)
29 email.attach_file(file_path)
30 email.send()
31 os.remove(file_path)
32
33 return HttpResponse('Processed')
34
35class Command(BaseCommand):
36 help = "Sends out an email when called"
37 def handle(self, *args, **options):
38 '''Contact page view for technical support requests'''
39
40 pdf_email.as_view()