def alert_generate_timesheet(request, alert_id, user_list=[], attach='', comments=''): ''' Time Sheet Alerts ''' try: total_to_email_list = [] total_cc_email_list = [] today_date = datetime.now().date().strftime('%m/%d/%Y') alert_configuration = AlertDataConfiguration.objects.get(pk=alert_id) if (alert_configuration.is_active == 0): return "Inactive" subject_content = alert_configuration.subject subject_content = subject_content % str(today_date) if (comments != ''): body_content += comments to_email = alert_configuration.toemail.values() for each_email in to_email: total_to_email_list.append(each_email.get('username')) # total_to_email_list = total_to_email_list + to_id if alert_id != 'alertdataconfig10': user_list.extend(total_to_email_list) for usr in user_list: record = User.objects.filter(username=usr) alert_body = alert_configuration.body if attach == '': body_content = alert_body % (str(record[0].first_name)) else: body_content = alert_body mail_id = str(record[0].email) alert_transaction = AlertDataTransaction(alert_id=alert_id, record_id=str( record[0].id), to_id=mail_id, body=body_content, subject=subject_content) alert_transaction.save() EmailWithCC().send_email(subject_content, body_content, [mail_id], settings.EMAIL_CONTENT_TYPE, attach, '', total_cc_email_list) except: errMessage = ERROR_MESSAGE % (sys.exc_info()[1], sys.exc_info()[2].tb_lineno) print 'errMessage', errMessage
def alert_generate(request, module_name, alert_id, record_id, to_id=[], cc_id=[], comments=''): ''' Event alerts ''' try: total_to_email_list = [] total_cc_email_list = [] to_id_list = [] subject_fields_lsit = [] body_fields_list = [] alert_configuration = AlertDataConfiguration.objects.get(pk=alert_id) if (alert_configuration.is_lock == False): return "Inactive" model_object = eval(module_name).objects.get(pk=record_id) subject_fields = alert_configuration.subject_fields.split(',') if str(alert_configuration.subject_fields).strip() != '': for each_subfield in subject_fields: subject_fields_lsit.append( eval('model_object.' + str(each_subfield))) body_fields = alert_configuration.body_fields.split(',') if str(alert_configuration.body_fields).strip() != '': for each_bodyfield in body_fields: body_fields_list.append( eval('model_object.' + str(each_bodyfield))) subject_content = alert_configuration.subject % tuple( subject_fields_lsit) alert_body = alert_configuration.body #body_fields_list.append(request.user.first_name+' '+request.user.last_name) body_content = alert_body % tuple(body_fields_list) if (comments != ''): body_content += comments to_email = alert_configuration.toemail.values() for each_email in to_email: total_to_email_list.append(each_email.get('email')) to_cc = alert_configuration.cc.values() for each_cc in to_cc: total_cc_email_list.append(each_cc.get('email')) to_bcc = alert_configuration.bcc.values() for each_bcc in to_bcc: total_cc_email_list.append(each_bcc.get('email')) if (len(to_id) > 0): total_to_email_list = total_to_email_list + to_id if (len(cc_id) > 0): total_cc_email_list = total_cc_email_list + cc_id total_to_email_list = filter(None, total_to_email_list) total_cc_email_list = filter(None, total_cc_email_list) if len(total_to_email_list) > 0: total_to_email_list = reduce( lambda x, y: x + y if y[0] not in x else x, map(lambda x: [x], total_to_email_list)) if len(total_cc_email_list) > 0: total_cc_email_list = reduce( lambda x, y: x + y if y[0] not in x else x, map(lambda x: [x], total_cc_email_list)) print 'total_to_email_list', total_to_email_list, total_cc_email_list send_mail_flag = True if (send_mail_flag): alert_transaction = AlertDataTransaction(alert_id=alert_id, record_id=record_id, to_id=total_to_email_list, cc_id=total_cc_email_list, body=body_content, subject=subject_content) alert_transaction.save() if (alert_configuration.is_email): total_to_email_list = total_to_email_list + total_cc_email_list EmailWithCC().send_email(subject_content, body_content, total_to_email_list, settings.EMAIL_CONTENT_TYPE) except: errMessage = ERROR_MESSAGE % (sys.exc_info()[1], sys.exc_info()[2].tb_lineno) '''
def alert_generate(request, module_name, alert_id, record_id, to_id=[], cc_id=[], comments=''): ''' Event alerts ''' try: total_to_email_list = [] total_cc_email_list = [] to_id_list = [] subject_fields_lsit = [] body_fields_list = [] alert_configuration = AlertDataConfiguration.objects.get(pk=alert_id) if (alert_configuration.is_lock == False): return "Inactive" model_object = eval(module_name).objects.get(pk=record_id) subject_fields = alert_configuration.subject_fields.split(',') if str(alert_configuration.subject_fields).strip() != '': for each_subfield in subject_fields: subject_fields_lsit.append( eval('model_object.' + str(each_subfield))) body_fields = alert_configuration.body_fields.split(',') if str(alert_configuration.body_fields).strip() != '': for each_bodyfield in body_fields: body_fields_list.append( eval('model_object.' + str(each_bodyfield))) subject_content = alert_configuration.subject % tuple( subject_fields_lsit) alert_body = alert_configuration.body #body_fields_list.append(request.user.first_name+' '+request.user.last_name) body_content = alert_body % tuple(body_fields_list) if alert_id == 'alertdataconfig18' or alert_id == 'alertdataconfig19' or alert_id == 'alertdataconfig20' or alert_id == 'alertdataconfig26' or alert_id == 'alertdataconfig27': expend_tbl = Expenditure_Reimburs.objects.filter( reimbursement__id=record_id) reimbus = Reimbursement.objects.filter(id=record_id)[0] body_content += '<table border="1"><th> Expenditure</th><th>Amount</th>' for expend in expend_tbl: body_content += '<tr><td>' + expend.expenditure_name + '</td>' body_content += '<td>' + str(expend.amount) + '</td></tr>' body_content += '</table><br>' body_content += 'Total Amount:' + \ str(reimbus.total_expenditure) + '<br><br>' body_content += 'Best Regards,<br>Admin<br><br>' body_content += 'This is a system generated alert. We request you not to reply to this message.' if alert_id == 'alertdataconfig22' or alert_id == 'alertdataconfig23' or alert_id == 'alertdataconfig24' or alert_id == 'alertdataconfig28' or alert_id == 'alertdataconfig29': expend_tbl = Expenditure.objects.filter(travel__id=record_id) travel = Travel.objects.filter(id=record_id)[0] body_content += '<table border="1"><th> Expenditure Date </th><th>Client Name</th><th>Destination</th><th>KM</th>' for expend in expend_tbl: body_content += '<tr><td>' + str(expend.expend_date) + '</td>' body_content += '<td>' + str(expend.client_name) + '</td>' body_content += '<td>' + str(expend.destination) + '</td>' body_content += '<td>' + str(expend.km) + '</td></tr>' body_content += '</table><br>' body_content += 'Total KM:' + str(travel.total_km) + '<br>' body_content += 'Total Amount:' + str(travel.total_rs) + '<br><br>' body_content += 'Best Regards,<br>Admin<br><br>' body_content += 'This is a system generated alert. We request you not to reply to this message.' if (comments != ''): body_content += comments to_email = alert_configuration.toemail.values() for each_email in to_email: total_to_email_list.append(each_email.get('email')) to_cc = alert_configuration.cc.values() for each_cc in to_cc: total_cc_email_list.append(each_cc.get('email')) to_bcc = alert_configuration.bcc.values() for each_bcc in to_bcc: total_cc_email_list.append(each_bcc.get('email')) if (len(to_id) > 0): total_to_email_list = total_to_email_list + to_id if (len(cc_id) > 0): total_cc_email_list = total_cc_email_list + cc_id total_to_email_list = filter(None, total_to_email_list) total_cc_email_list = filter(None, total_cc_email_list) if len(total_to_email_list) > 0: total_to_email_list = reduce( lambda x, y: x + y if y[0] not in x else x, map(lambda x: [x], total_to_email_list)) if len(total_cc_email_list) > 0: total_cc_email_list = reduce( lambda x, y: x + y if y[0] not in x else x, map(lambda x: [x], total_cc_email_list)) send_mail_flag = True if (send_mail_flag): alert_transaction = AlertDataTransaction(alert_id=alert_id, record_id=record_id, to_id=total_to_email_list, cc_id=total_cc_email_list, body=body_content, subject=subject_content) alert_transaction.save() if (alert_configuration.is_email): total_to_email_list = total_to_email_list + total_cc_email_list EmailWithCC().send_email(subject_content, body_content, total_to_email_list, settings.EMAIL_CONTENT_TYPE) except BaseException: errMessage = ERROR_MESSAGE % (sys.exc_info()[1], sys.exc_info()[2].tb_lineno) '''