def run(self, **kwargs): logger = self.get_logger() logger.info('TASK :: send_cdr_report') list_users = User.objects.filter(is_staff=True, is_active=True) for c_user in list_users: if not c_user.email: logger.error("User (%s) -> This user doesn't have an email." % c_user.username) continue else: logger.error("Send Report from User (%s - %s)." % (c_user.username, c_user.email)) try: to_email = UserProfile.objects.get(user=c_user).multiple_email except UserProfile.DoesNotExist: logger.error('Error : UserProfile notfound (user_id:%d)' % c_user.id) continue if not to_email: logger.error('Error: UserProfile multiple_email not set (user_id:' + str(c_user.id) + ')') continue from_email = c_user.email mail_data = get_cdr_mail_report(c_user) subject = 'CDR Report' html_content = get_template('cdr/mail_report_template.html')\ .render(Context({ 'yesterday_date': mail_data['yesterday_date'], 'rows': mail_data['rows'], 'total_duration': mail_data['total_duration'], 'total_calls': mail_data['total_calls'], 'total_buy_cost': mail_data['total_buy_cost'], 'total_sell_cost': mail_data['total_sell_cost'], 'metric_aggr': mail_data['metric_aggr'], 'country_data': mail_data['country_data'], 'hangup_cause_data': mail_data['hangup_cause_data'] })) msg = EmailMultiAlternatives(subject, html_content, from_email, [to_email]) logger.info('Email sent to %s' % str(to_email)) msg.content_subtype = 'html' msg.send() logger.debug('TASK :: send_cdr_report finished') return True
def handle(self, *args, **options): """to send daily mail report via command line""" list_users = User.objects.filter(is_staff=True, is_active=True) for c_user in list_users: if not c_user.email: print "User (%s) -> This user doesn't have an email." % c_user.username continue else: print "Send Report from User (%s - %s)." % (c_user.username, c_user.email) try: to_email = UserProfile.objects.get(user=c_user).multiple_email except UserProfile.DoesNotExist: print 'Error: UserProfile not found (user_id:' + str( c_user.id) + ')' continue if not to_email: print 'Error: UserProfile multiple_email not set (user_id:' + str( c_user.id) + ')' continue from_email = c_user.email mail_data = get_cdr_mail_report(c_user) subject = 'CDR Report' html_content = get_template('cdr/mail_report_template.html')\ .render(Context({ 'yesterday_date': mail_data['yesterday_date'], 'rows': mail_data['rows'], 'total_duration': mail_data['total_duration'], 'total_calls': mail_data['total_calls'], 'total_buy_cost': mail_data['total_buy_cost'], 'total_sell_cost': mail_data['total_sell_cost'], 'metric_aggr': mail_data['metric_aggr'], 'country_data': mail_data['country_data'], 'hangup_cause_data': mail_data['hangup_cause_data'] })) msg = EmailMultiAlternatives(subject, html_content, from_email, [to_email]) print '\nEmail sent to ' + str(to_email) print '-' * 80 msg.content_subtype = 'html' msg.send()
def handle(self, *args, **options): """to send daily mail report via command line""" list_users = User.objects.filter(is_staff=True, is_active=True) for c_user in list_users: if not c_user.email: print "User (%s) -> This user doesn't have an email." % c_user.username continue else: print "Send Report from User (%s - %s)." % (c_user.username, c_user.email) try: to_email = UserProfile.objects.get(user=c_user).multiple_email except UserProfile.DoesNotExist: print 'Error: UserProfile not found (user_id:' + str(c_user.id) + ')' continue if not to_email: print 'Error: UserProfile multiple_email not set (user_id:' + str(c_user.id) + ')' continue from_email = c_user.email mail_data = get_cdr_mail_report(c_user) subject = 'CDR Report' html_content = get_template('cdr/mail_report_template.html')\ .render(Context({ 'yesterday_date': mail_data['yesterday_date'], 'rows': mail_data['rows'], 'total_duration': mail_data['total_duration'], 'total_calls': mail_data['total_calls'], 'total_buy_cost': mail_data['total_buy_cost'], 'total_sell_cost': mail_data['total_sell_cost'], 'metric_aggr': mail_data['metric_aggr'], 'country_data': mail_data['country_data'], 'hangup_cause_data': mail_data['hangup_cause_data'] })) msg = EmailMultiAlternatives(subject, html_content, from_email, [to_email]) print '\nEmail sent to ' + str(to_email) print '-' * 80 msg.content_subtype = 'html' msg.send()
def handle(self, *args, **options): """to send daily mail report via command line""" list_users = User.objects.filter(is_staff=True, is_active=True) for c_user in list_users: if not c_user.email: print "User (%s) -> This user doesn't have an email." % c_user.username continue from_email = c_user.email try: user_profile_obj = UserProfile.objects.get(user=c_user) to = user_profile_obj.multiple_email except UserProfile.DoesNotExist: print 'Error: UserProfile not found (user_id:' + str( c_user.id) + ')' continue mail_data = get_cdr_mail_report() subject = _('CDR Report') html_content = get_template('frontend/mail_report_template.html')\ .render(Context({ 'yesterday_date': mail_data['yesterday_date'], 'rows': mail_data['rows'], 'total_duration': mail_data['total_duration'], 'total_calls': mail_data['total_calls'], 'ACT': mail_data['ACT'], 'ACD': mail_data['ACD'], 'country_analytic_array': mail_data['country_analytic_array'], 'hangup_analytic_array': mail_data['hangup_analytic_array'] })) if to: msg = EmailMultiAlternatives(subject, html_content, from_email, [to]) print '\nEmail sent to ' + str(to) print '-' * 80 msg.content_subtype = 'html' msg.send() else: print "Error: email not sent"
def run(self, **kwargs): logger = self.get_logger() logger.info('TASK :: send_cdr_report') list_users = User.objects.filter(is_staff=True, is_active=True) for c_user in list_users: from_email = c_user.email try: user_profile_obj = UserProfile.objects.get(user=c_user) to = user_profile_obj.multiple_email except UserProfile.DoesNotExist: to = '' logger.error('Error : UserProfile notfound (user_id:%d)' % c_user.id) mail_data = get_cdr_mail_report() subject = _('CDR Report') html_content = get_template('frontend/mail_report_template.html')\ .render(Context({ 'yesterday_date': mail_data['yesterday_date'], 'rows': mail_data['rows'], 'total_duration': mail_data['total_duration'], 'total_calls': mail_data['total_calls'], 'ACT': mail_data['ACT'], 'ACD': mail_data['ACD'], 'country_analytic_array': mail_data['country_analytic_array'], 'hangup_analytic_array': mail_data['hangup_analytic_array'] } )) msg = EmailMultiAlternatives( subject, html_content, from_email, [to]) logger.info('Email sent to %s' % to) msg.content_subtype = 'html' msg.send() logger.debug('TASK :: send_cdr_report finished') return True
def run(self, **kwargs): logger = self.get_logger() logger.info('TASK :: send_cdr_report') list_users = User.objects.filter(is_staff=True, is_active=True) for c_user in list_users: from_email = c_user.email try: user_profile_obj = UserProfile.objects.get(user=c_user) to = user_profile_obj.multiple_email except UserProfile.DoesNotExist: to = '' logger.error('Error : UserProfile notfound (user_id:%d)' % c_user.id) mail_data = get_cdr_mail_report() subject = _('CDR Report') html_content = get_template('frontend/mail_report_template.html')\ .render(Context({ 'yesterday_date': mail_data['yesterday_date'], 'rows': mail_data['rows'], 'total_duration': mail_data['total_duration'], 'total_calls': mail_data['total_calls'], 'ACT': mail_data['ACT'], 'ACD': mail_data['ACD'], 'country_analytic_array': mail_data['country_analytic_array'], 'hangup_analytic_array': mail_data['hangup_analytic_array'] } )) msg = EmailMultiAlternatives(subject, html_content, from_email, [to]) logger.info('Email sent to %s' % to) msg.content_subtype = 'html' msg.send() logger.debug('TASK :: send_cdr_report finished') return True
def handle(self, *args, **options): """to send daily mail report via command line""" list_users = User.objects.filter(is_staff=True, is_active=True) for c_user in list_users: if not c_user.email: print "User (%s) -> This user doesn't have an email." % c_user.username continue from_email = c_user.email try: user_profile_obj = UserProfile.objects.get(user=c_user) to = user_profile_obj.multiple_email except UserProfile.DoesNotExist: print 'Error: UserProfile not found (user_id:' + str(c_user.id) + ')' continue mail_data = get_cdr_mail_report() subject = _('CDR Report') html_content = get_template('frontend/mail_report_template.html')\ .render(Context({ 'yesterday_date': mail_data['yesterday_date'], 'rows': mail_data['rows'], 'total_duration': mail_data['total_duration'], 'total_calls': mail_data['total_calls'], 'ACT': mail_data['ACT'], 'ACD': mail_data['ACD'], 'country_analytic_array': mail_data['country_analytic_array'], 'hangup_analytic_array': mail_data['hangup_analytic_array'] })) if to: msg = EmailMultiAlternatives(subject, html_content, from_email, [to]) print '\nEmail sent to ' + str(to) print '-' * 80 msg.content_subtype = 'html' msg.send() else: print "Error: email not sent"
def run(self, **kwargs): logger = self.get_logger() logger.info("TASK :: send_cdr_report") list_users = User.objects.filter(is_staff=True, is_active=True) for c_user in list_users: from_email = c_user.email try: user_profile_obj = UserProfile.objects.get(user=c_user) to = user_profile_obj.multiple_email except UserProfile.DoesNotExist: logger.error("Error : UserProfile notfound (user_id:%d)" % c_user.id) mail_data = get_cdr_mail_report() subject = _("CDR Report") html_content = get_template("cdr/mail_report_template.html").render( Context( { "yesterday_date": mail_data["yesterday_date"], "rows": mail_data["rows"], "total_duration": mail_data["total_duration"], "total_calls": mail_data["total_calls"], "ACT": mail_data["ACT"], "ACD": mail_data["ACD"], "country_analytic_array": mail_data["country_analytic_array"], "hangup_analytic_array": mail_data["hangup_analytic_array"], } ) ) msg = EmailMultiAlternatives(subject, html_content, from_email, [to]) logger.info("Email sent to %s" % to) msg.content_subtype = "html" msg.send() logger.debug("TASK :: send_cdr_report finished") return True