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
9e76c612
Commit
9e76c612
authored
Oct 24, 2013
by
Joe Blaylock
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1286 from edx/jrbl/certs-single-user
Certificates: Add regeneration command
parents
b00d59ed
8ef8fc82
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
34 deletions
+100
-34
lms/djangoapps/certificates/management/commands/regenerate_user.py
+58
-0
lms/djangoapps/certificates/management/commands/ungenerated_certs.py
+7
-5
lms/djangoapps/certificates/models.py
+8
-8
lms/djangoapps/certificates/queue.py
+27
-21
No files found.
lms/djangoapps/certificates/management/commands/regenerate_user.py
0 → 100644
View file @
9e76c612
"""Django management command to force certificate regeneration for one user"""
from
optparse
import
make_option
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
from
certificates.queue
import
XQueueCertInterface
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.modulestore.django
import
modulestore
class
Command
(
BaseCommand
):
help
=
"""Put a request on the queue to recreate the certificate for a particular user in a particular course."""
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'-n'
,
'--noop'
,
action
=
'store_true'
,
dest
=
'noop'
,
default
=
False
,
help
=
"Don't grade or add certificate requests to the queue"
),
make_option
(
'-c'
,
'--course'
,
metavar
=
'COURSE_ID'
,
dest
=
'course'
,
default
=
False
,
help
=
'The course id (e.g., mit/6-002x/circuits-and-electronics) for which the student named in'
'<username> should be graded'
),
make_option
(
'-u'
,
'--user'
,
metavar
=
'USERNAME'
,
dest
=
'username'
,
default
=
False
,
help
=
'The username or email address for whom grading and certification should be requested'
),
)
def
handle
(
self
,
*
args
,
**
options
):
user
=
options
[
'username'
]
course_id
=
options
[
'course'
]
if
not
(
course_id
and
user
):
raise
CommandError
(
'both course id and student username are required'
)
student
=
None
print
"Fetching enrollment for student {0} in {1}"
.
format
(
user
,
course_id
)
if
'@'
in
user
:
student
=
User
.
objects
.
get
(
email
=
user
,
courseenrollment__course_id
=
course_id
)
else
:
student
=
User
.
objects
.
get
(
username
=
user
,
courseenrollment__course_id
=
course_id
)
print
"Fetching course data for {0}"
.
format
(
course_id
)
course
=
modulestore
()
.
get_instance
(
course_id
,
CourseDescriptor
.
id_to_location
(
course_id
),
depth
=
2
)
if
not
options
[
'noop'
]:
# Add the certificate request to the queue
xq
=
XQueueCertInterface
()
ret
=
xq
.
regen_cert
(
student
,
course_id
,
course
=
course
)
print
'{0} - {1}'
.
format
(
student
,
ret
)
else
:
print
"noop option given, skipping work queueing..."
lms/djangoapps/certificates/management/commands/ungenerated_certs.py
View file @
9e76c612
...
...
@@ -14,12 +14,13 @@ from pytz import UTC
class
Command
(
BaseCommand
):
help
=
"""
Find all students that need certificates
for courses that have finished and
put their cert requests on the queue
Find all students that need certificates for courses that have finished and
put their cert requests on the queue.
Use the --noop option to test without actually
putting certificates on the queue to be generated.
If --user is given, only grade and certify the requested username.
Use the --noop option to test without actually putting certificates on the
queue to be generated.
"""
option_list
=
BaseCommand
.
option_list
+
(
...
...
@@ -80,6 +81,7 @@ class Command(BaseCommand):
enrolled_students
=
User
.
objects
.
filter
(
courseenrollment__course_id
=
course_id
)
.
prefetch_related
(
"groups"
)
.
order_by
(
'username'
)
xq
=
XQueueCertInterface
()
total
=
enrolled_students
.
count
()
count
=
0
...
...
lms/djangoapps/certificates/models.py
View file @
9e76c612
...
...
@@ -52,15 +52,15 @@ Eligibility:
class
CertificateStatuses
(
object
):
unavailable
=
'unavailable'
generating
=
'generating'
regenerating
=
'regenerating'
deleting
=
'deleting'
deleted
=
'deleted'
deleted
=
'deleted'
deleting
=
'deleting'
downloadable
=
'downloadable'
notpassing
=
'notpassing'
restricted
=
'restricted'
error
=
'error'
error
=
'error'
generating
=
'generating'
notpassing
=
'notpassing'
regenerating
=
'regenerating'
restricted
=
'restricted'
unavailable
=
'unavailable'
class
CertificateWhitelist
(
models
.
Model
):
...
...
lms/djangoapps/certificates/queue.py
View file @
9e76c612
...
...
@@ -75,28 +75,34 @@ class XQueueCertInterface(object):
self
.
whitelist
=
CertificateWhitelist
.
objects
.
all
()
self
.
restricted
=
UserProfile
.
objects
.
filter
(
allow_certificate
=
False
)
def
regen_cert
(
self
,
student
,
course_id
):
"""
def
regen_cert
(
self
,
student
,
course_id
,
course
=
None
):
"""(Re-)Make certificate for a particular student in a particular course
Arguments:
student - User.object
student
- User.object
course_id - courseenrollment.course_id (string)
Removes certificate for a student, will change
the certificate status to 'regenerating'.
Certificate must be in the 'error' or 'downloadable' state
If the student has a passing grade a certificate
request will be put on the queue
If the student is not passing his state will change
to status.notpassing
WARNING: this command will leave the old certificate, if one exists,
laying around in AWS taking up space. If this is a problem,
take pains to clean up storage before running this command.
otherwise it will return the current state
Change the certificate status to unavailable (if it exists) and request
grading. Passing grades will put a certificate request on the queue.
Return the status object.
"""
raise
NotImplementedError
# TODO: when del_cert is implemented and plumbed through certificates
# repo also, do a deletion followed by a creation r/t a simple
# recreation. XXX: this leaves orphan cert files laying around in
# AWS. See note in the docstring too.
try
:
certificate
=
GeneratedCertificate
.
objects
.
get
(
user
=
student
,
course_id
=
course_id
)
certificate
.
status
=
status
.
unavailable
certificate
.
save
()
except
GeneratedCertificate
.
DoesNotExist
:
pass
return
self
.
add_cert
(
student
,
course_id
,
course
)
def
del_cert
(
self
,
student
,
course_id
):
...
...
@@ -134,7 +140,6 @@ class XQueueCertInterface(object):
If a student has allow_certificate set to False in the
userprofile table the status will change to 'restricted'
If a student does not have a passing grade the status
will change to status.notpassing
...
...
@@ -143,11 +148,12 @@ class XQueueCertInterface(object):
"""
VALID_STATUSES
=
[
status
.
generating
,
status
.
unavailable
,
status
.
deleted
,
status
.
error
,
status
.
notpassing
]
status
.
unavailable
,
status
.
deleted
,
status
.
error
,
status
.
notpassing
]
cert_status
=
certificate_status_for_student
(
student
,
course_id
)[
'status'
]
cert_status
=
certificate_status_for_student
(
student
,
course_id
)[
'status'
]
if
cert_status
in
VALID_STATUSES
:
# grade the student
...
...
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