feat: allow notify_credentials to take a list of usernames
This commit is contained in:
@@ -157,7 +157,7 @@ def get_certificates_for_user_by_course_keys(user, course_keys):
|
||||
}
|
||||
|
||||
|
||||
def get_recently_modified_certificates(course_keys=None, start_date=None, end_date=None, username=None):
|
||||
def get_recently_modified_certificates(course_keys=None, start_date=None, end_date=None, usernames=None):
|
||||
"""
|
||||
Returns a QuerySet of GeneratedCertificate objects filtered by the input
|
||||
parameters and ordered by modified_date.
|
||||
@@ -173,8 +173,8 @@ def get_recently_modified_certificates(course_keys=None, start_date=None, end_da
|
||||
if end_date:
|
||||
cert_filter_args['modified_date__lte'] = end_date
|
||||
|
||||
if username:
|
||||
cert_filter_args['user__username'] = username
|
||||
if usernames:
|
||||
cert_filter_args['user__username__in'] = usernames
|
||||
|
||||
return GeneratedCertificate.objects.filter(**cert_filter_args).order_by('modified_date')
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ def clear_prefetched_course_and_subsection_grades(course_key):
|
||||
_PersistentCourseGrade.clear_prefetched_data(course_key)
|
||||
|
||||
|
||||
def get_recently_modified_grades(course_keys, start_date, end_date, user=None):
|
||||
def get_recently_modified_grades(course_keys, start_date, end_date, users=None):
|
||||
"""
|
||||
Returns a QuerySet of PersistentCourseGrade objects filtered by the input
|
||||
parameters and ordered by modified date.
|
||||
@@ -47,8 +47,8 @@ def get_recently_modified_grades(course_keys, start_date, end_date, user=None):
|
||||
grade_filter_args['modified__gte'] = start_date
|
||||
if end_date:
|
||||
grade_filter_args['modified__lte'] = end_date
|
||||
if user:
|
||||
grade_filter_args['user_id'] = user.id
|
||||
if users:
|
||||
grade_filter_args['user_id__in'] = [u.id for u in users]
|
||||
|
||||
return _PersistentCourseGrade.objects.filter(**grade_filter_args).order_by('modified')
|
||||
|
||||
|
||||
@@ -162,9 +162,10 @@ class Command(BaseCommand):
|
||||
help='Send program award notifications with course notification tasks',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--username',
|
||||
'--usernames',
|
||||
default=None,
|
||||
help='Run the command for a single user',
|
||||
nargs='+',
|
||||
help='Run the command for the given user or list of users',
|
||||
)
|
||||
|
||||
def get_args_from_database(self):
|
||||
@@ -189,7 +190,7 @@ class Command(BaseCommand):
|
||||
|
||||
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, username=%s, execution=%s",
|
||||
u"from=%s, to=%s, notify_programs=%s, usernames=%s, execution=%s",
|
||||
options['dry_run'],
|
||||
options['site'],
|
||||
options['delay'],
|
||||
@@ -197,7 +198,7 @@ class Command(BaseCommand):
|
||||
options['start_date'] if options['start_date'] else 'NA',
|
||||
options['end_date'] if options['end_date'] else 'NA',
|
||||
options['notify_programs'],
|
||||
options['username'],
|
||||
options['usernames'],
|
||||
'auto' if options['auto'] else 'manual',
|
||||
)
|
||||
|
||||
@@ -207,18 +208,18 @@ class Command(BaseCommand):
|
||||
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['username']):
|
||||
raise CommandError('You must specify a filter (e.g. --courses= or --start-date or --username)')
|
||||
if not (course_keys or options['start_date'] or options['end_date'] or options['usernames']):
|
||||
raise CommandError('You must specify a filter (e.g. --courses= or --start-date or --usernames)')
|
||||
|
||||
certs = get_recently_modified_certificates(
|
||||
course_keys, options['start_date'], options['end_date'], options['username']
|
||||
course_keys, options['start_date'], options['end_date'], options['usernames']
|
||||
)
|
||||
|
||||
user = None
|
||||
if options['username']:
|
||||
user = User.objects.get(username=options['username'])
|
||||
users = None
|
||||
if options['usernames']:
|
||||
users = User.objects.filter(username__in=options['usernames'])
|
||||
grades = get_recently_modified_grades(
|
||||
course_keys, options['start_date'], options['end_date'], user
|
||||
course_keys, options['start_date'], options['end_date'], users
|
||||
)
|
||||
|
||||
log.info('notify_credentials Sending notifications for {certs} certificates and {grades} grades'.format(
|
||||
|
||||
Reference in New Issue
Block a user