def handle(self, *args, **options): if not args: raise CommandError('Enter monitoring ID in command line!') for monitoring_pk in args: try: monitoring = Monitoring.objects.get(pk=monitoring_pk) except Monitoring.DoesNotExist: message = smart_str(self.style.ERROR('Monitoring with ID "%s" does not exist!\n' % monitoring_pk)) self.stderr.write(message) continue except ValueError: message = smart_str(self.style.ERROR('Invalid literal "%s" for monitoring ID!\n' % monitoring_pk)) self.stderr.write(message) continue context = comment_report(monitoring) context.update({'site': 'http://' + Site.objects.get_current().domain}) subject = u"Comment report from {monitoring.interact_date} to {today} for {monitoring.name}" subject = subject.format(today=date.today(), monitoring=monitoring) rcpt = [config_value('EmailServer', 'NOTIFY_LIST_REPORT')] # NOTE: User Story #1900 - Always send comment reports in Russian language. with translation.override('ru'): send_email.delay(ExmoEmail(template_basename='mail/comments_stats', context=context, to=rcpt, subject=subject))
def test_open_comments_count(self): # WHEN comment report is constructed report = comment_report(self.org.monitoring) # THEN length of expired, urgent and non-urgent comments lists should be correct self.assertEqual(len(report['expired']), 2) self.assertEqual(len(report['urgent']), 1) self.assertEqual(len(report['non_urgent']), 1)
def test_count_of_organizations_with_representatives(self): report = comment_report(self.monitoring) self.assertEqual(report['num_orgs_with_user'], 2) active_orgs = set(tuple(x.items()) for x in report['active_orgs']) expected = [ (('num_comments', 1), ('name', u'org1'), ('expert', u'expertB')), (('num_comments', 2), ('name', u'org2'), ('expert', u'expertB'))] self.assertEqual(active_orgs, set(expected)) active_experts = set((e.username, e.num_comments) for e in report['active_experts']) self.assertEqual(active_experts, set([('expertB', 2)])) self.assertEqual(report['num_answered'], 2) self.assertEqual(report['num_answered_late'], 1)
def test_count_of_organizations_with_representatives(self): report = comment_report(self.monitoring) self.assertEqual(report['num_orgs_with_user'], 2) active_orgs = set(tuple(x.items()) for x in report['active_orgs']) expected = [ (('num_comments', 1), ('name', u'org1'), ('expert', u'expertB')), (('num_comments', 2), ('name', u'org2'), ('expert', u'expertB')) ] self.assertEqual(active_orgs, set(expected)) active_experts = set( (e.username, e.num_comments) for e in report['active_experts']) self.assertEqual(active_experts, set([('expertB', 2)])) self.assertEqual(report['num_answered'], 2) self.assertEqual(report['num_answered_late'], 1)
def handle(self, *args, **options): if not args: raise CommandError('Enter monitoring ID in command line!') for monitoring_pk in args: try: monitoring = Monitoring.objects.get(pk=monitoring_pk) except Monitoring.DoesNotExist: message = smart_str( self.style.ERROR( 'Monitoring with ID "%s" does not exist!\n' % monitoring_pk)) self.stderr.write(message) continue except ValueError: message = smart_str( self.style.ERROR( 'Invalid literal "%s" for monitoring ID!\n' % monitoring_pk)) self.stderr.write(message) continue context = comment_report(monitoring) context.update( {'site': 'http://' + Site.objects.get_current().domain}) subject = u"Comment report from {monitoring.interact_date} to {today} for {monitoring.name}" subject = subject.format(today=date.today(), monitoring=monitoring) rcpt = [config_value('EmailServer', 'NOTIFY_LIST_REPORT')] # NOTE: User Story #1900 - Always send comment reports in Russian language. with translation.override('ru'): send_email.delay( ExmoEmail(template_basename='mail/comments_stats', context=context, to=rcpt, subject=subject))
from django.contrib.sites.models import Site from django.core.mail import send_mail from livesettings import config_value from custom_comments.utils import comment_report from exmo2010.models import Monitoring m_pk = sys.argv[1] monitoring = Monitoring.objects.get(pk=m_pk) start_date = monitoring.interact_date limit = time_to_answer = monitoring.time_to_answer report = comment_report(monitoring) end_date = report.get('end_date') comments_without_reply = report.get('comments_without_reply') fail_comments_without_reply = report.get('fail_comments_without_reply') fail_soon_comments_without_reply = report.get('fail_soon_comments_without_reply') fail_comments_with_reply = report.get('fail_comments_with_reply') comments_with_reply = report.get('comments_with_reply') org_comments = report.get('org_comments') iifd_all_comments = report.get('iifd_all_comments') active_organization_stats = report.get('active_organization_stats') total_org = report.get('total_org') reg_org = report.get('reg_org') active_iifd_person_stats = report.get('active_iifd_person_stats') t = loader.get_template('exmo2010/helpers/score_comments_stat.html')
def get_context_data(self, **kwargs): context = super(MonitoringCommentReportView, self).get_context_data(**kwargs) context.update(comment_report(self.monitoring)) return context