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
1f849e44
Commit
1f849e44
authored
10 years ago
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix management commands
parent
9dc48c00
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
26 deletions
+51
-26
common/djangoapps/student/management/commands/anonymized_id_mapping.py
+7
-5
common/djangoapps/student/management/commands/change_enrollment.py
+11
-1
common/djangoapps/student/management/commands/create_random_users.py
+13
-5
common/djangoapps/student/management/commands/transfer_students.py
+19
-14
lms/djangoapps/instructor/management/commands/openended_stats.py
+1
-1
No files found.
common/djangoapps/student/management/commands/anonymized_id_mapping.py
View file @
1f849e44
...
...
@@ -13,7 +13,9 @@ import csv
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
from
opaque_keys
import
InvalidKeyError
from
student.models
import
anonymous_id_for_user
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
...
...
@@ -35,16 +37,16 @@ class Command(BaseCommand):
raise
CommandError
(
"Usage: unique_id_mapping
%
s"
%
" "
.
join
((
"<
%
s>"
%
arg
for
arg
in
Command
.
args
)))
course_
id
=
args
[
0
]
course_
key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
0
])
# Generate the output filename from the course ID.
# Change slashes to dashes first, and then append .csv extension.
output_filename
=
course_
id
.
replace
(
'/'
,
'-'
)
+
".csv"
output_filename
=
course_
key
.
to_deprecated_string
()
.
replace
(
'/'
,
'-'
)
+
".csv"
# Figure out which students are enrolled in the course
students
=
User
.
objects
.
filter
(
courseenrollment__course_id
=
course_
id
)
students
=
User
.
objects
.
filter
(
courseenrollment__course_id
=
course_
key
)
if
len
(
students
)
==
0
:
self
.
stdout
.
write
(
"No students enrolled in
%
s"
%
course_
id
)
self
.
stdout
.
write
(
"No students enrolled in
%
s"
%
course_
key
.
to_deprecated_string
()
)
return
# Write mapping to output file in CSV format with a simple header
...
...
@@ -60,7 +62,7 @@ class Command(BaseCommand):
csv_writer
.
writerow
((
student
.
id
,
anonymous_id_for_user
(
student
,
None
),
anonymous_id_for_user
(
student
,
course_
id
)
anonymous_id_for_user
(
student
,
course_
key
)
))
except
IOError
:
raise
CommandError
(
"Error writing to file:
%
s"
%
output_filename
)
...
...
This diff is collapsed.
Click to expand it.
common/djangoapps/student/management/commands/change_enrollment.py
View file @
1f849e44
from
django.core.management.base
import
BaseCommand
,
CommandError
from
opaque_keys
import
InvalidKeyError
from
optparse
import
make_option
from
student.models
import
CourseEnrollment
,
User
from
xmodule.modulestore.keys
import
CourseKey
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
...
...
@@ -55,8 +59,14 @@ class Command(BaseCommand):
raise
CommandError
(
"You must specify a course id for this command"
)
if
not
options
[
'from_mode'
]
or
not
options
[
'to_mode'
]:
raise
CommandError
(
'You must specify a "to" and "from" mode as parameters'
)
try
:
course_key
=
CourseKey
.
from_string
(
options
[
'course_id'
])
except
InvalidKeyError
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
options
[
'course_id'
])
filter_args
=
dict
(
course_id
=
options
[
'course_id'
]
,
course_id
=
course_key
,
mode
=
options
[
'from_mode'
]
)
if
options
[
'user'
]:
...
...
This diff is collapsed.
Click to expand it.
common/djangoapps/student/management/commands/create_random_users.py
View file @
1f849e44
...
...
@@ -7,12 +7,12 @@ from student.models import CourseEnrollment
from
student.views
import
_do_create_account
,
get_random_post_override
def
create
(
n
,
course_
id
):
"""Create n users, enrolling them in course_
id
if it's not None"""
def
create
(
n
,
course_
key
):
"""Create n users, enrolling them in course_
key
if it's not None"""
for
i
in
range
(
n
):
(
user
,
user_profile
,
_
)
=
_do_create_account
(
get_random_post_override
())
if
course_
id
is
not
None
:
CourseEnrollment
.
enroll
(
user
,
course_
id
)
if
course_
key
is
not
None
:
CourseEnrollment
.
enroll
(
user
,
course_
key
)
class
Command
(
BaseCommand
):
...
...
@@ -32,5 +32,13 @@ Examples:
return
n
=
int
(
args
[
0
])
course_id
=
args
[
1
]
if
len
(
args
)
==
2
else
None
if
len
(
args
)
==
2
:
try
:
course_key
=
CourseKey
.
from_string
(
args
[
1
])
except
InvalidKeyError
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
1
])
else
:
course_id
=
None
create
(
n
,
course_id
)
This diff is collapsed.
Click to expand it.
common/djangoapps/student/management/commands/transfer_students.py
View file @
1f849e44
...
...
@@ -3,6 +3,7 @@ from django.core.management.base import BaseCommand
from
django.contrib.auth.models
import
User
from
student.models
import
CourseEnrollment
from
shoppingcart.models
import
CertificateItem
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
...
...
@@ -30,32 +31,35 @@ class Command(BaseCommand):
)
def
handle
(
self
,
*
args
,
**
options
):
source
=
options
[
'source_course'
]
dest
=
options
[
'dest_course'
]
source
_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
options
[
'source_course'
])
dest
_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
options
[
'dest_course'
])
source_students
=
User
.
objects
.
filter
(
courseenrollment__course_id
=
source
)
courseenrollment__course_id
=
source_key
)
for
user
in
source_students
:
if
CourseEnrollment
.
is_enrolled
(
student
,
dest
):
if
CourseEnrollment
.
is_enrolled
(
user
,
dest_key
):
# Un Enroll from source course but don't mess
# with the enrollment in the destination course.
CourseEnrollment
.
unenroll
(
user
,
source
)
print
(
"Unenrolled {} from {}"
.
format
(
user
.
username
,
source
))
CourseEnrollment
.
unenroll
(
user
,
source_key
)
print
(
"Unenrolled {} from {}"
.
format
(
user
.
username
,
source
_key
.
to_deprecated_string
()
))
msg
=
"Skipping {}, already enrolled in destination course {}"
print
(
msg
.
format
(
user
.
username
,
dest
))
print
(
msg
.
format
(
user
.
username
,
dest
_key
.
to_deprecated_string
()
))
continue
print
(
"Moving {}."
.
format
(
user
.
username
))
# Find the old enrollment.
enrollment
=
CourseEnrollment
.
objects
.
get
(
user
=
user
,
course_id
=
source
)
enrollment
=
CourseEnrollment
.
objects
.
get
(
user
=
user
,
course_id
=
source_key
)
# Move the Student between the classes.
mode
=
enrollment
.
mode
old_is_active
=
enrollment
.
is_active
CourseEnrollment
.
unenroll
(
user
,
source
)
new_enrollment
=
CourseEnrollment
.
enroll
(
user
,
dest
,
mode
=
mode
)
CourseEnrollment
.
unenroll
(
user
,
source_key
)
new_enrollment
=
CourseEnrollment
.
enroll
(
user
,
dest
_key
,
mode
=
mode
)
# Unenroll from the new coures if the user had unenrolled
# form the old course.
...
...
@@ -65,12 +69,13 @@ class Command(BaseCommand):
if
mode
==
'verified'
:
try
:
certificate_item
=
CertificateItem
.
objects
.
get
(
course_id
=
source
,
course_enrollment
=
enrollment
)
course_id
=
source_key
,
course_enrollment
=
enrollment
)
except
CertificateItem
.
DoesNotExist
:
print
(
"No certificate for {}"
.
format
(
user
))
continue
certificate_item
.
course_id
=
dest
certificate_item
.
course_id
=
dest
_key
certificate_item
.
course_enrollment
=
new_enrollment
certificate_item
.
save
()
This diff is collapsed.
Click to expand it.
lms/djangoapps/instructor/management/commands/openended_stats.py
View file @
1f849e44
...
...
@@ -40,7 +40,7 @@ class Command(BaseCommand):
if
len
(
args
)
==
2
:
course_id
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
0
])
usage_key
=
UsageKey
.
from
_string
(
args
[
1
])
usage_key
=
course_id
.
make_usage_key_from_deprecated
_string
(
args
[
1
])
else
:
print
self
.
help
return
...
...
This diff is collapsed.
Click to expand it.
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