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
fb48d264
Commit
fb48d264
authored
Nov 15, 2012
by
John Jarvis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
parent
1bf8edcc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
23 deletions
+22
-23
lms/djangoapps/certificates/management/commands/gen_cert_report.py
+22
-23
No files found.
lms/djangoapps/certificates/management/commands/gen_cert_report.py
View file @
fb48d264
from
django.core.management.base
import
BaseCommand
from
certificates.models
import
certificate_status_for_student
from
certificates.models
import
CertificateStatuses
from
certificates.models
import
GeneratedCertificate
from
django.contrib.auth.models
import
User
from
optparse
import
make_option
from
django.conf
import
settings
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.modulestore.django
import
modulestore
from
collections
import
Counter
from
django.db.models
import
Count
class
Command
(
BaseCommand
):
...
...
@@ -56,8 +55,7 @@ class Command(BaseCommand):
else
:
ended_courses
=
self
.
_ended_courses
()
total_enrolled
=
{}
cert_statuses
=
{}
cert_data
=
{}
for
course_id
in
ended_courses
:
...
...
@@ -66,34 +64,35 @@ class Command(BaseCommand):
enrolled_students
=
User
.
objects
.
filter
(
courseenrollment__course_id
=
course_id
)
.
prefetch_related
(
"groups"
)
.
order_by
(
'username'
)
total_enrolled
[
course_id
]
=
enrolled_students
.
count
()
cert_statuses
=
[
attr
# all possible certificate statuses
for
attr
in
dir
(
CertificateStatuses
())
if
not
callable
(
attr
)
and
not
attr
.
startswith
(
"__"
)]
# tally up certificate statuses for every student
# enrolled in the course
cert_statuses
=
{
status
:
GeneratedCertificate
.
objects
.
filter
(
course_id__exact
=
course_id
,
status
=
status
)
.
count
()
for
status
in
cert_statuses
}
unavailable_count
=
enrolled_students
.
count
()
-
\
GeneratedCertificate
.
objects
.
filter
(
course_id__exact
=
course_id
)
.
count
()
cert_data
[
course_id
]
=
{
'enrolled'
:
enrolled_students
.
count
()}
cert_data
[
course_id
]
.
update
({
'unavailable'
:
unavailable_count
})
tallies
=
GeneratedCertificate
.
objects
.
values
(
'status'
)
.
annotate
(
dcount
=
Count
(
'status'
))
cert_data
[
course_id
]
.
update
(
{
status
[
'status'
]:
status
[
'dcount'
]
for
status
in
tallies
})
print
cert_data
# all states we have seen far all courses
status_headings
=
set
(
[
status
for
course
in
cert_
statuses
for
status
in
cert_
statuses
[
course
]])
[
status
for
course
in
cert_
data
for
status
in
cert_
data
[
course
]])
# print the heading for the report
print
"{
0:>20}{1:>10}"
.
format
(
"course ID"
,
"enrolled
"
),
print
"{
:>20}"
.
format
(
"course ID
"
),
print
' '
.
join
([
"{:>12}"
.
format
(
heading
)
for
heading
in
status_headings
])
# print the report
for
course_id
in
total_enrolled
:
print
"{0:>20}{1:>10}"
.
format
(
course_id
[
0
:
18
],
total_enrolled
[
course_id
]),
for
course_id
in
cert_data
:
print
"{0:>20}"
.
format
(
course_id
[
0
:
18
]),
for
heading
in
status_headings
:
if
heading
in
cert_
statuses
[
course_id
]:
print
"{:>12}"
.
format
(
cert_
statuses
[
course_id
][
heading
]),
if
heading
in
cert_
data
[
course_id
]:
print
"{:>12}"
.
format
(
cert_
data
[
course_id
][
heading
]),
else
:
print
" "
*
12
,
print
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