Commit cb1489a7 by John Jarvis Committed by Carlos Andrés Rocha

docstring cleanup, grading for regen_cert

parent df37f111
...@@ -80,13 +80,11 @@ class XQueueCertInterface(object): ...@@ -80,13 +80,11 @@ class XQueueCertInterface(object):
Removes certificate for a student, will change Removes certificate for a student, will change
the certificate status to 'regenerating'. the certificate status to 'regenerating'.
Will invalidate the old certificate and generate
a new one.
When completed the certificate status will change Certificate must be in the 'error' or 'downloadable' state
to 'downloadable' and the student must have a passing grade.
Returns the certificate status. otherwise it will return the current state
""" """
...@@ -96,44 +94,49 @@ class XQueueCertInterface(object): ...@@ -96,44 +94,49 @@ class XQueueCertInterface(object):
student, course_id)['status'] student, course_id)['status']
if cert_status in VALID_STATUSES: if cert_status in VALID_STATUSES:
# grade the student
course = courses.get_course_by_id(course_id)
grade = grades.grade(student, self.request, course)
profile = UserProfile.objects.get(user=student) if grade['grade'] is not None:
try:
cert = GeneratedCertificate.objects.get(
user=student, course_id=course_id)
except GeneratedCertificate.DoesNotExist:
logger.warning("Attempting to regenerate a certificate"
"for a user that doesn't have one")
raise
cert.status = status.regenerating
cert.name = profile.name
contents = { profile = UserProfile.objects.get(user=student)
'action': 'regen', try:
'remove_verify_uuid': cert.verify_uuid, cert = GeneratedCertificate.objects.get(
'remove_download_uuid': cert.download_uuid, user=student, course_id=course_id)
'username': cert.user.username, except GeneratedCertificate.DoesNotExist:
'course_id': cert.course_id, logger.warning("Attempting to regenerate a certificate"
'name': profile.name, "for a user that doesn't have one")
} raise
cert.status = status.regenerating
cert.name = profile.name
key = cert.key contents = {
xheader = make_xheader( 'action': 'regen',
'http://{0}/certificate'.format(settings.SITE_NAME), 'remove_verify_uuid': cert.verify_uuid,
key, 'test-pull') 'remove_download_uuid': cert.download_uuid,
(error, msg) = self.xqueue_interface.send_to_queue( 'username': cert.user.username,
header=xheader, body=json.dumps(contents)) 'course_id': cert.course_id,
if error: 'name': profile.name,
logger.critical('Unable to add a request to the queue') }
raise Exception('Unable to send queue message')
cert.save() key = cert.key
xheader = make_xheader(
'http://{0}/certificate'.format(settings.SITE_NAME),
key, 'test-pull')
(error, msg) = self.xqueue_interface.send_to_queue(
header=xheader, body=json.dumps(contents))
if error:
logger.critical('Unable to add a request to the queue')
raise Exception('Unable to send queue message')
cert.save()
return cert_status return cert_status
def del_cert(self, student, course_id): def del_cert(self, student, course_id):
"""
"""
Arguments: Arguments:
student - User.object student - User.object
course_id - courseenrollment.course_id (string) course_id - courseenrollment.course_id (string)
...@@ -141,10 +144,8 @@ class XQueueCertInterface(object): ...@@ -141,10 +144,8 @@ class XQueueCertInterface(object):
Removes certificate for a student, will change Removes certificate for a student, will change
the certificate status to 'deleting'. the certificate status to 'deleting'.
When completed the certificate status will change Certificate must be in the 'error' or 'downloadable' state
to 'deleted'. otherwise it will return the current state
Returns the certificate status.
""" """
...@@ -189,19 +190,14 @@ class XQueueCertInterface(object): ...@@ -189,19 +190,14 @@ class XQueueCertInterface(object):
student - User.object student - User.object
course_id - courseenrollment.course_id (string) course_id - courseenrollment.course_id (string)
Adds a new certificate request to the queue only if Request a new certificate for a student.
the current certificate status is 'unavailable', 'error' Will change the certificate status to 'deleting'.
or 'deleted' and the student has a passing grade for
the course.
When completed the certificate status will change
to 'downloadable'.
If the current status is 'generating', 'regenerating' Certificate must be in the 'unavailable', 'error',
or 'deleting' this function will return that status or 'deleted' state and the student must have
a passing grade.
Returns 'unavailable' if the student is eligible for otherwise it will return the current state
a certificate but does not have a passing grade.
""" """
......
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