Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
a9b26cb8
Commit
a9b26cb8
authored
12 years ago
by
John Jarvis
Committed by
Carlos Andrés Rocha
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup, docstrings, recording name in certificate table
parent
f589adcd
No related branches found
Branches containing commit
Tags
release-2021-06-22-18.58
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/certificates/models.py
+22
-0
22 additions, 0 deletions
lms/djangoapps/certificates/models.py
lms/djangoapps/certificates/queue.py
+56
-15
56 additions, 15 deletions
lms/djangoapps/certificates/queue.py
with
78 additions
and
15 deletions
lms/djangoapps/certificates/models.py
+
22
−
0
View file @
a9b26cb8
...
...
@@ -14,6 +14,27 @@ certificate is available for download the GeneratedCertificate
table is updated with information that will be displayed
on the course overview page.
State diagram:
[deleted,error,unavailable] [error,downloadable]
+ + +
| | |
| | |
add_cert regen_cert del_cert
| | |
v v v
[generating] [regenerating] [deleting]
+ + +
| | |
certificate certificate certificate
created removed,created deleted
+----------------+-------------+------->[error]
| | |
| | |
v v v
[downloadable] [downloadable] [deleted]
'''
...
...
@@ -37,6 +58,7 @@ class GeneratedCertificate(models.Model):
key
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
default
=
''
)
distinction
=
models
.
BooleanField
(
default
=
False
)
status
=
models
.
CharField
(
max_length
=
32
,
default
=
'
unavailable
'
)
name
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
)
class
Meta
:
unique_together
=
((
'
user
'
,
'
course_id
'
),)
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/certificates/queue.py
+
56
−
15
View file @
a9b26cb8
...
...
@@ -19,6 +19,35 @@ logger = logging.getLogger(__name__)
class
XQueueCertInterface
(
object
):
"""
XQueueCertificateInterface provides an
interface to the xqueue server for
managing student certificates.
Instantiating an object will create a new
connection to the queue server.
See models.py for valid state transitions,
summary of methods:
add_cert: Add a new certificate. Puts a single
request on the queue for the student/course.
Once the certificate is generated a post
will be made to the update_certificate
view which will save the certificate
download URL.
regen_cert: Regenerate an existing certificate.
For a user that already has a certificate
this will delete the existing one and
generate a new cert.
del_cert: Delete an existing certificate
For a user that already has a certificate
this will delete his cert.
"""
def
__init__
(
self
,
request
=
None
):
...
...
@@ -45,7 +74,6 @@ class XQueueCertInterface(object):
def
regen_cert
(
self
,
student
,
course_id
):
"""
Arguments:
student - User.object
course_id - courseenrollment.course_id (string)
...
...
@@ -62,7 +90,7 @@ class XQueueCertInterface(object):
"""
VALID_STATUSES
=
[
status
.
downloadable
]
VALID_STATUSES
=
[
status
.
error
,
status
.
downloadable
]
cert_status
=
certificate_status_for_student
(
student
,
course_id
)[
'
status
'
]
...
...
@@ -70,11 +98,16 @@ class XQueueCertInterface(object):
if
cert_status
in
VALID_STATUSES
:
profile
=
UserProfile
.
objects
.
get
(
user
=
student
)
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
=
GeneratedCertificate
.
objects
.
get
(
user
=
student
,
course_id
=
course_id
)
cert
.
status
=
status
.
regenerating
cert
.
save
()
cert
.
name
=
profile
.
name
contents
=
{
'
action
'
:
'
regen
'
,
...
...
@@ -94,10 +127,11 @@ class XQueueCertInterface(object):
if
error
:
logger
.
critical
(
'
Unable to add a request to the queue
'
)
raise
Exception
(
'
Unable to send queue message
'
)
cert
.
save
()
return
cert_status
def
remove
_cert
(
self
,
student
,
course_id
):
def
del
_cert
(
self
,
student
,
course_id
):
"""
Arguments:
...
...
@@ -114,17 +148,22 @@ class XQueueCertInterface(object):
"""
VALID_STATUSES
=
[
status
.
downloadable
]
VALID_STATUSES
=
[
status
.
error
,
status
.
downloadable
]
cert_status
=
certificate_status_for_student
(
student
,
course_id
)[
'
status
'
]
if
cert_status
in
VALID_STATUSES
:
cert
=
GeneratedCertificate
.
objects
.
get
(
user
=
student
,
course_id
=
course_id
)
try
:
cert
=
GeneratedCertificate
.
objects
.
get
(
user
=
student
,
course_id
=
course_id
)
except
GeneratedCertificate
.
DoesNotExist
:
logger
.
warning
(
"
Attempting to delete a certificate
"
"
for a user that doesn
'
t have one
"
)
raise
cert
.
status
=
status
.
deleting
cert
.
save
()
contents
=
{
'
action
'
:
'
remove
'
,
...
...
@@ -140,9 +179,10 @@ class XQueueCertInterface(object):
(
error
,
msg
)
=
self
.
xqueue_interface
.
send_to_queue
(
header
=
xheader
,
body
=
json
.
dumps
(
contents
))
cert
.
save
()
return
cert_status
def
add_cert
_to_queue
(
self
,
student
,
course_id
):
def
add_cert
(
self
,
student
,
course_id
):
"""
Arguments:
...
...
@@ -150,8 +190,8 @@ class XQueueCertInterface(object):
course_id - courseenrollment.course_id (string)
Adds a new certificate request to the queue only if
the current certificate status is
'
unavailable
'
or
'
deleted
'
and the student has a passing grade for
the current certificate status is
'
unavailable
'
,
'
err
or
'
or
'
deleted
'
and the student has a passing grade for
the course.
When completed the certificate status will change
...
...
@@ -165,7 +205,7 @@ class XQueueCertInterface(object):
"""
VALID_STATUSES
=
[
status
.
unavailable
,
status
.
deleted
]
VALID_STATUSES
=
[
status
.
unavailable
,
status
.
deleted
,
status
.
error
]
cert_status
=
certificate_status_for_student
(
student
,
course_id
)[
'
status
'
]
...
...
@@ -187,7 +227,7 @@ class XQueueCertInterface(object):
cert
.
user
=
student
cert
.
course_id
=
course_id
cert
.
key
=
key
cert
.
save
()
cert
.
name
=
profile
.
name
contents
=
{
'
action
'
:
'
create
'
,
...
...
@@ -204,5 +244,6 @@ class XQueueCertInterface(object):
if
error
:
logger
.
critical
(
'
Unable to post results to qserver
'
)
raise
Exception
(
'
Unable to send queue message
'
)
cert
.
save
()
return
cert_status
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment