import datetime from service models import AlertDate Group Service Cli

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import datetime
from service.models import AlertDate, Group, Service, Client, Record
from django.shortcuts import render_to_response
from django.core.mail import send_mail
def check_alert(request):
records = Record.objects.filter(end_date__gt=datetime.datetime.now())
for i in records:
if (i.end_date - datetime.timedelta(days=i.alert.days)) == datetime.date.today():
groups = []
for k in i.alert_group.all():
groups.append(k)
emails = []
for v in groups:
for z in v.user.all():
emails.append(z.email)
send_mail('Service %s for company %s will expire in %s days' % (i.service, i.client, i.alert.days),
'The service %s is about expire in %s day, here is the description: \n %s' % (i.service, i.alert.days, i.description),
'alerts@syslogics.co.il', emails, fail_silently=False )
return render_to_response('check.html',{'records':records})