From b8cfe80145103ea7c90db47779ed32f34ba8ed2c Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Tue, 20 Nov 2012 15:18:09 -0500 Subject: [PATCH 1/2] Saving grade for non-passing students --- lms/djangoapps/certificates/queue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/certificates/queue.py b/lms/djangoapps/certificates/queue.py index b3a9ddc9c7..52a8dcae36 100644 --- a/lms/djangoapps/certificates/queue.py +++ b/lms/djangoapps/certificates/queue.py @@ -240,7 +240,7 @@ class XQueueCertInterface(object): cert.save() else: cert_status = status.notpassing - + cert.grade = grade['percent'] cert.status = cert_status cert.user = student cert.course_id = course_id From 6d28be0439b251dd1ba1ac91afd47e89145d40e0 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Tue, 20 Nov 2012 15:18:25 -0500 Subject: [PATCH 2/2] Adding management command to grade students who were not previously graded --- .../management/commands/fix_ungraded_certs.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py diff --git a/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py b/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py new file mode 100644 index 0000000000..4492c0dc36 --- /dev/null +++ b/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py @@ -0,0 +1,45 @@ +from certificates.models import GeneratedCertificate +from courseware import grades, courses +from django.test.client import RequestFactory +from django.core.management.base import BaseCommand +from optparse import make_option + + +class Command(BaseCommand): + + help = """ + Find all students that need to be graded + and grade them. + """ + + option_list = BaseCommand.option_list + ( + make_option('-n', '--noop', + action='store_true', + dest='noop', + default=False, + help="Print but do not update the GeneratedCertificate table"), + make_option('-c', '--course', + metavar='COURSE_ID', + dest='course', + default=False, + help='Grade ungraded users for this course'), + + ) + + def handle(self, *args, **options): + + course_id = options['course'] + print "Fetching ungraded students for {0}".format(course_id) + ungraded = GeneratedCertificate.objects.filter( + course_id__exact=course_id).filter(grade__exact='') + course = courses.get_course_by_id(course_id) + factory = RequestFactory() + request = factory.get('/') + + for cert in ungraded: + # grade the student + grade = grades.grade(cert.user, request, course) + print "grading {0} - {1}".format(cert.user, grade['percent']) + cert.grade = grade['percent'] + if not options['noop']: + cert.save()