Commit eab95114 by David Ormsbee

Merge pull request #1295 from MITx/feature/jarv/certificate-force-update

Feature/jarv/certificate force update
parents 07785e3c 08b8a9f6
...@@ -16,7 +16,6 @@ class Command(BaseCommand): ...@@ -16,7 +16,6 @@ class Command(BaseCommand):
This command does not do anything other than report the current This command does not do anything other than report the current
certificate status. certificate status.
unavailable - A student is not eligible for a certificate.
generating - A request has been made to generate a certificate, generating - A request has been made to generate a certificate,
but it has not been generated yet. but it has not been generated yet.
regenerating - A request has been made to regenerate a certificate, regenerating - A request has been made to regenerate a certificate,
...@@ -64,11 +63,7 @@ class Command(BaseCommand): ...@@ -64,11 +63,7 @@ class Command(BaseCommand):
enrolled_students = User.objects.filter( enrolled_students = User.objects.filter(
courseenrollment__course_id=course_id).prefetch_related( courseenrollment__course_id=course_id).prefetch_related(
"groups").order_by('username') "groups").order_by('username')
unavailable_count = enrolled_students.count() - \
GeneratedCertificate.objects.filter(
course_id__exact=course_id).count()
cert_data[course_id] = {'enrolled': enrolled_students.count()} cert_data[course_id] = {'enrolled': enrolled_students.count()}
cert_data[course_id].update({'unavailable': unavailable_count})
tallies = GeneratedCertificate.objects.filter( tallies = GeneratedCertificate.objects.filter(
course_id__exact=course_id).values('status').annotate( course_id__exact=course_id).values('status').annotate(
......
...@@ -23,26 +23,37 @@ class Command(BaseCommand): ...@@ -23,26 +23,37 @@ class Command(BaseCommand):
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
make_option('-n', '--noop', make_option('-n', '--noop',
action='store_true', action='store_true',
dest='noop', dest='noop',
default=False, default=False,
help="Don't add certificate requests to the queue"), help="Don't add certificate requests to the queue"),
make_option('-c', '--course', make_option('-c', '--course',
metavar='COURSE_ID', metavar='COURSE_ID',
dest='course', dest='course',
default=False, default=False,
help='Grade and generate certificates for a specific course'), help='Grade and generate certificates '
'for a specific course'),
make_option('-f', '--force-gen',
metavar='STATUS',
dest='force',
default=False,
help='Will generate new certificates for only those users '
'whose entry in the certificate table matches STATUS. '
'STATUS can be generating, unavailable, deleted, error '
'or notpassing.'),
) )
def handle(self, *args, **options): def handle(self, *args, **options):
# Will only generate a certificate if the current # Will only generate a certificate if the current
# status is in this state # status is in the unavailable state, can be set
# to something else with the force flag
VALID_STATUSES = [ if options['force']:
CertificateStatuses.unavailable valid_statuses = getattr(CertificateStatuses, options['force'])
] else:
valid_statuses = [CertificateStatuses.unavailable]
# Print update after this many students # Print update after this many students
...@@ -54,8 +65,8 @@ class Command(BaseCommand): ...@@ -54,8 +65,8 @@ class Command(BaseCommand):
# Find all courses that have ended # Find all courses that have ended
ended_courses = [] ended_courses = []
for course_id in [course # all courses in COURSE_LISTINGS for course_id in [course # all courses in COURSE_LISTINGS
for sub in settings.COURSE_LISTINGS for sub in settings.COURSE_LISTINGS
for course in settings.COURSE_LISTINGS[sub]]: for course in settings.COURSE_LISTINGS[sub]]:
course_loc = CourseDescriptor.id_to_location(course_id) course_loc = CourseDescriptor.id_to_location(course_id)
course = modulestore().get_instance(course_id, course_loc) course = modulestore().get_instance(course_id, course_loc)
if course.has_ended(): if course.has_ended():
...@@ -64,8 +75,8 @@ class Command(BaseCommand): ...@@ -64,8 +75,8 @@ class Command(BaseCommand):
for course_id in ended_courses: for course_id in ended_courses:
print "Fetching enrolled students for {0}".format(course_id) print "Fetching enrolled students for {0}".format(course_id)
enrolled_students = User.objects.filter( enrolled_students = User.objects.filter(
courseenrollment__course_id=course_id).prefetch_related( courseenrollment__course_id=course_id).prefetch_related(
"groups").order_by('username') "groups").order_by('username')
xq = XQueueCertInterface() xq = XQueueCertInterface()
total = enrolled_students.count() total = enrolled_students.count()
count = 0 count = 0
...@@ -81,11 +92,11 @@ class Command(BaseCommand): ...@@ -81,11 +92,11 @@ class Command(BaseCommand):
hours, remainder = divmod(timeleft.seconds, 3600) hours, remainder = divmod(timeleft.seconds, 3600)
minutes, seconds = divmod(remainder, 60) minutes, seconds = divmod(remainder, 60)
print "{0}/{1} completed ~{2:02}:{3:02}m remaining".format( print "{0}/{1} completed ~{2:02}:{3:02}m remaining".format(
count, total, hours, minutes) count, total, hours, minutes)
start = datetime.datetime.now() start = datetime.datetime.now()
if certificate_status_for_student( if certificate_status_for_student(
student, course_id)['status'] in VALID_STATUSES: student, course_id)['status'] in valid_statuses:
if not options['noop']: if not options['noop']:
# Add the certificate request to the queue # Add the certificate request to the queue
ret = xq.add_cert(student, course_id) ret = xq.add_cert(student, course_id)
......
...@@ -192,7 +192,7 @@ class XQueueCertInterface(object): ...@@ -192,7 +192,7 @@ class XQueueCertInterface(object):
Will change the certificate status to 'deleting'. Will change the certificate status to 'deleting'.
Certificate must be in the 'unavailable', 'error', Certificate must be in the 'unavailable', 'error',
or 'deleted' state. 'deleted' or 'generating' state.
If a student has a passing grade a request will made If a student has a passing grade a request will made
for a new cert for a new cert
...@@ -204,7 +204,8 @@ class XQueueCertInterface(object): ...@@ -204,7 +204,8 @@ class XQueueCertInterface(object):
""" """
VALID_STATUSES = [status.unavailable, status.deleted, status.error, VALID_STATUSES = [ status.generating,
status.unavailable, status.deleted, status.error,
status.notpassing] status.notpassing]
cert_status = certificate_status_for_student( cert_status = certificate_status_for_student(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment