Commit f53b3c09 by John Jarvis

Certificate model for tracking certificate statuses

parent 8b437c26
...@@ -7,71 +7,68 @@ Certificates are created for a student and an offering of a course. ...@@ -7,71 +7,68 @@ Certificates are created for a student and an offering of a course.
When a certificate is generated, a unique ID is generated so that When a certificate is generated, a unique ID is generated so that
the certificate can be verified later. The ID is a UUID4, so that the certificate can be verified later. The ID is a UUID4, so that
it can't be easily guessed and so that it is unique. Even though it can't be easily guessed and so that it is unique.
we save these generated certificates (for later verification), we
also record the UUID so that if we regenerate the certificate it
will have the same UUID.
Certificates are generated in batches by a cron job, when a Certificates are generated in batches by a cron job, when a
certificate is available for download the GeneratedCertificate certificate is available for download the GeneratedCertificate
table is updated with information that will be displayed table is updated with information that will be displayed
on the course overview page. on the course overview page.
''' '''
class CertificateStatuses(object):
unavailable='unavailable'
generating='generating'
regenerating='regenerating'
deleting='deleting'
deleted='deleted'
downloadable='downloadable'
error='error'
class GeneratedCertificate(models.Model): class GeneratedCertificate(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User)
course_id = models.CharField(max_length=255, default=False) course_id = models.CharField(max_length=255, blank=True, default='')
certificate_id = models.CharField(max_length=32, default=False) verify_uuid = models.CharField(max_length=32, blank=True, default='')
graded_certificate_id = models.CharField(max_length=32, default=False) download_uuid = models.CharField(max_length=32, blank=True, default='')
download_url = models.CharField(max_length=128, blank=True, default='')
download_url = models.CharField(max_length=128, default=False) grade = models.CharField(max_length=5, blank=True, default='')
graded_download_url = models.CharField(max_length=128, default=False) key = models.CharField(max_length=32, blank=True, default='')
grade = models.CharField(max_length=5, default=False) distinction = models.BooleanField(default=False)
key = models.CharField(max_length=32, default=False) status = models.CharField(max_length=32, default='unavailable')
# enabled should only be true if the student has earned a passing grade class Meta:
# in the course. unique_together= (('user', 'course_id'),)
enabled = models.BooleanField(default=False)
def certificate_status_for_student(student, course_id):
def certificate_state_for_student(student):
''' '''
This returns a dictionary with a key for state, and other information. This returns a dictionary with a key for status, and other information.
The state is one of the following: The status is one of the following:
unavailable - A student is not eligible for a certificate. unavailable - A student is not eligible for a certificate.
generating - A student has requested a certificate, generating - A request has been made to generate a certificate,
but it is not generated yet. but it has not been generated yet.
downloadable - The certificate has been requested and is regenerating - A request has been made to regenerate a certificate,
available for download. but it has not been generated yet.
deleting - A request has been made to delete a certificate.
If the state is "downloadable", the dictionary also contains
"download_url" and "graded_download_url". deleted - The certificate has been deleted.
downloadable - The certificate is available for download.
If the status is "downloadable", the dictionary also contains
"download_url".
''' '''
try: try:
generated_certificate = GeneratedCertificate.objects.get( generated_certificate = GeneratedCertificate.objects.get(
user=student) user=student, course_id=course_id)
if generated_certificate.enabled: if generated_certificate.status == CertificateStatuses.downloadable:
if generated_certificate.download_url: return {
return { 'status': CertificateStatuses.downloadable,
'state': 'downloadable', 'download_url': generated_certificate.download_url,
'download_url': }
generated_certificate.download_url, else:
'graded_download_url': return {'status': generated_certificate.status}
generated_certificate.graded_download_url
}
else:
return {'state': 'generating'}
else:
# If enabled=False, there is no certificate available
# Our output will be the same as if the
# GeneratedCertificate did not exist
pass
except GeneratedCertificate.DoesNotExist: except GeneratedCertificate.DoesNotExist:
pass pass
return {'state': 'unavailable'} return {'status': 'unavailable'}
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