Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
1767719e
Commit
1767719e
authored
Oct 24, 2012
by
John Jarvis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating the certificates model for automatic certificate generation
parent
a5085565
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
111 deletions
+43
-111
lms/djangoapps/certificates/models.py
+43
-111
No files found.
lms/djangoapps/certificates/models.py
View file @
1767719e
from
django.conf
import
settings
as
settings
from
django.contrib.auth.models
import
User
from
django.db
import
models
...
...
@@ -14,131 +12,65 @@ 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.
If certificates are being generated on the fly, a GeneratedCertificate
should be created with the user, certificate_id, and enabled set
when a student requests a certificate. When the certificate has been
generated, the download_url should be set
.
Certificates are generated in batches by a cron job, when a
certificate is available for download the GeneratedCertificate
table is updated with information that will be displayed
on the course overview page
.
Certificates can also be pre-generated. In this case, the user,
certificate_id, and download_url are all set before the user does
anything. When the user requests the certificate, only enabled
needs to be set to true.
'''
class
GeneratedCertificate
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
db_index
=
True
)
# This is the name at the time of request
name
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
)
certificate_id
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
default
=
None
)
graded_certificate_id
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
default
=
None
)
download_url
=
models
.
CharField
(
max_length
=
128
,
null
=
True
)
graded_download_url
=
models
.
CharField
(
max_length
=
128
,
null
=
True
)
grade
=
models
.
CharField
(
max_length
=
5
,
null
=
True
)
# enabled should only be true if the student has earned a grade in the course
# The student must have a grade and request a certificate for enabled to be True
enabled
=
models
.
BooleanField
(
default
=
False
)
class
RevokedCertificate
(
models
.
Model
):
"""
This model is for when a GeneratedCertificate must be regenerated. This model
contains all the same fields, to store a record of what the GeneratedCertificate
was before it was revoked (at which time all of it's information can change when
it is regenerated).
GeneratedCertificate may be deleted once they are revoked, and then created again.
For this reason, the only link between a GeneratedCertificate and RevokedCertificate
is that they share the same user.
"""
####-------------------New Fields--------------------####
explanation
=
models
.
TextField
(
blank
=
True
)
user
=
models
.
ForeignKey
(
User
)
course_id
=
models
.
CharField
(
max_length
=
255
)
certificate_id
=
models
.
CharField
(
max_length
=
32
)
graded_certificate_id
=
models
.
CharField
(
max_length
=
32
)
####---------Fields from GeneratedCertificate---------####
user
=
models
.
ForeignKey
(
User
,
db_index
=
True
)
# This is the name at the time of request
name
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
)
certificate_id
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
default
=
None
)
graded_certificate_id
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
default
=
None
)
download_url
=
models
.
CharField
(
max_length
=
128
,
null
=
True
)
graded_download_url
=
models
.
CharField
(
max_length
=
128
,
null
=
True
)
grade
=
models
.
CharField
(
max_length
=
5
,
null
=
True
)
download_url
=
models
.
CharField
(
max_length
=
128
)
graded_download_url
=
models
.
CharField
(
max_length
=
128
)
grade
=
models
.
CharField
(
max_length
=
5
)
# enabled should only be true if the student has earned a passing grade
# in the course.
enabled
=
models
.
BooleanField
(
default
=
False
)
def
revoke_certificate
(
certificate
,
explanation
):
"""
This method takes a GeneratedCertificate. It records its information from the certificate
into a RevokedCertificate, and then marks the certificate as needing regenerating.
When the new certificiate is regenerated it will have new IDs and download URLS.
Once this method has been called, it is safe to delete the certificate, or modify the
certificate's name or grade until it has been generated again.
"""
revoked
=
RevokedCertificate
(
user
=
certificate
.
user
,
name
=
certificate
.
name
,
certificate_id
=
certificate
.
certificate_id
,
graded_certificate_id
=
certificate
.
graded_certificate_id
,
download_url
=
certificate
.
download_url
,
graded_download_url
=
certificate
.
graded_download_url
,
grade
=
certificate
.
grade
,
enabled
=
certificate
.
enabled
)
revoked
.
explanation
=
explanation
certificate
.
certificate_id
=
None
certificate
.
graded_certificate_id
=
None
certificate
.
download_url
=
None
certificate
.
graded_download_url
=
None
certificate
.
save
()
revoked
.
save
()
def
certificate_state_for_student
(
student
,
grade
):
def
certificate_state_for_student
(
student
):
'''
This returns a dictionary with a key for state, and other information.
The state is one of the
following:
This returns a dictionary with a key for state, and other information.
The state is one of the
following:
unavailable - A student is not eligible for a certificate.
requestable - A student is eligible to request a certificate
generating - A student has requested a certificate, but it is not generated yet.
downloadable - The certificate has been requested and is available for download.
unavailable - A student is not eligible for a certificate.
generating - A student has requested a certificate,
but it is not generated yet.
downloadable - The certificate has been requested and is
available for download.
If the state is "downloadable", the dictionary also contains "download_url" and "graded_download_url".
If the state is "downloadable", the dictionary also contains
"download_url" and "graded_download_url".
'''
if
grade
:
#TODO: Remove the following after debugging
if
settings
.
DEBUG_SURVEY
:
return
{
'state'
:
'requestable'
}
try
:
generated_certificate
=
GeneratedCertificate
.
objects
.
get
(
user
=
student
)
if
generated_certificate
.
enabled
:
if
generated_certificate
.
download_url
:
return
{
'state'
:
'downloadable'
,
'download_url'
:
generated_certificate
.
download_url
,
'graded_download_url'
:
generated_certificate
.
graded_download_url
}
else
:
return
{
'state'
:
'generating'
}
try
:
generated_certificate
=
GeneratedCertificate
.
objects
.
get
(
user
=
student
)
if
generated_certificate
.
enabled
:
if
generated_certificate
.
download_url
:
return
{
'state'
:
'downloadable'
,
'download_url'
:
generated_certificate
.
download_url
,
'graded_download_url'
:
generated_certificate
.
graded_download_url
}
else
:
# If enabled=False, it may have been pre-generated but not yet requested
# Our output will be the same as if the GeneratedCertificate did not exist
pass
except
GeneratedCertificate
.
DoesNotExist
:
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
return
{
'state'
:
'requestable'
}
else
:
# No grade, no certificate. No exceptions
return
{
'state'
:
'unavailable'
}
except
GeneratedCertificate
.
DoesNotExist
:
pass
return
{
'state'
:
'unavailable'
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment