def handle(self, *args, **options): if options['args_from_database']: options = self.get_args_from_database() log.info( u"notify_credentials starting, dry-run=%s, site=%s, delay=%d seconds", options['dry_run'], options['site'], options['delay'] ) try: site_config = SiteConfiguration.objects.get(site__domain=options['site']) if options['site'] else None except SiteConfiguration.DoesNotExist: log.error(u'No site configuration found for site %s', options['site']) course_keys = self.get_course_keys(options['courses']) if not (course_keys or options['start_date'] or options['end_date']): raise CommandError('You must specify a filter (e.g. --courses= or --start-date)') certs = get_recently_modified_certificates(course_keys, options['start_date'], options['end_date']) grades = get_recently_modified_grades(course_keys, options['start_date'], options['end_date']) if options['dry_run']: self.print_dry_run(certs, grades) else: self.send_notifications(certs, grades, site_config=site_config, delay=options['delay'], page_size=options['page_size'], verbose=options['verbose']) log.info('notify_credentials finished')
def handle(self, *args, **options): if options['args_from_database']: options = self.get_args_from_database() if options['auto']: options['end_date'] = datetime.now().replace(minute=0, second=0, microsecond=0) options['start_date'] = options['end_date'] - timedelta(hours=4) log.info( u"notify_credentials starting, dry-run=%s, site=%s, delay=%d seconds, page_size=%d, " u"from=%s, to=%s, notify_programs=%s, user_ids=%s, execution=%s", options['dry_run'], options['site'], options['delay'], options['page_size'], options['start_date'] if options['start_date'] else 'NA', options['end_date'] if options['end_date'] else 'NA', options['notify_programs'], options['user_ids'], 'auto' if options['auto'] else 'manual', ) try: site_config = SiteConfiguration.objects.get(site__domain=options['site']) if options['site'] else None except SiteConfiguration.DoesNotExist: log.error(u'No site configuration found for site %s', options['site']) course_keys = self.get_course_keys(options['courses']) if not (course_keys or options['start_date'] or options['end_date'] or options['user_ids']): raise CommandError('You must specify a filter (e.g. --courses= or --start-date or --user_ids)') certs = get_recently_modified_certificates( course_keys, options['start_date'], options['end_date'], options['user_ids'] ) users = None if options['user_ids']: users = User.objects.filter(id__in=options['user_ids']) grades = get_recently_modified_grades( course_keys, options['start_date'], options['end_date'], users ) log.info('notify_credentials Sending notifications for {certs} certificates and {grades} grades'.format( certs=certs.count(), grades=grades.count() )) if options['dry_run']: self.print_dry_run(certs, grades) else: self.send_notifications( certs, grades, site_config=site_config, delay=options['delay'], page_size=options['page_size'], verbose=options['verbose'], notify_programs=options['notify_programs'] ) log.info('notify_credentials finished')
def handle_notify_credentials(options, course_keys): """ Celery task to handle the notify_credentials management command. Finds the relevant cert and grade records, then starts other celery tasks to send the data. """ try: site_config = SiteConfiguration.objects.get( site__domain=options['site']) if options['site'] else None except SiteConfiguration.DoesNotExist: logger.exception('No site configuration found for site %s', options['site']) return # If a start_date or end_date are passed, this will include certificates # with a CertificateDateOverride modified within the time range certs = get_recently_modified_certificates(course_keys, options['start_date'], options['end_date'], options['user_ids']) users = None if options['user_ids']: users = User.objects.filter(id__in=options['user_ids']) grades = get_recently_modified_grades(course_keys, options['start_date'], options['end_date'], users) logger.info( 'notify_credentials Sending notifications for {certs} certificates and {grades} grades' .format(certs=certs.count(), grades=grades.count())) if options['dry_run']: log_dry_run(certs, grades) else: send_notifications(certs, grades, site_config=site_config, delay=options['delay'], page_size=options['page_size'], verbose=options['verbose'], notify_programs=options['notify_programs']) logger.info('notify_credentials finished')
def handle(self, *args, **options): if options['args_from_database']: options = self.get_args_from_database() log.info( u"notify_credentials starting, dry-run=%s, site=%s, delay=%d seconds", options['dry_run'], options['site'], options['delay']) try: site_config = SiteConfiguration.objects.get( site__domain=options['site']) if options['site'] else None except SiteConfiguration.DoesNotExist: log.error(u'No site configuration found for site %s', options['site']) course_keys = self.get_course_keys(options['courses']) if not (course_keys or options['start_date'] or options['end_date']): raise CommandError( 'You must specify a filter (e.g. --courses= or --start-date)') # pylint: disable=no-member certs = get_recently_modified_certificates(course_keys, options['start_date'], options['end_date']) grades = get_recently_modified_grades(course_keys, options['start_date'], options['end_date']) if options['dry_run']: self.print_dry_run(certs, grades) else: self.send_notifications(certs, grades, site_config=site_config, delay=options['delay'], page_size=options['page_size'], verbose=options['verbose']) log.info('notify_credentials finished')