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
May 21, 2014
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
...
@@ -13,7 +13,9 @@ import csv
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
opaque_keys
import
InvalidKeyError
from
student.models
import
anonymous_id_for_user
from
student.models
import
anonymous_id_for_user
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
...
@@ -35,16 +37,16 @@ class Command(BaseCommand):
...
@@ -35,16 +37,16 @@ class Command(BaseCommand):
raise
CommandError
(
"Usage: unique_id_mapping
%
s"
%
raise
CommandError
(
"Usage: unique_id_mapping
%
s"
%
" "
.
join
((
"<
%
s>"
%
arg
for
arg
in
Command
.
args
)))
" "
.
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.
# Generate the output filename from the course ID.
# Change slashes to dashes first, and then append .csv extension.
# 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
# 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
:
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
return
# Write mapping to output file in CSV format with a simple header
# Write mapping to output file in CSV format with a simple header
...
@@ -60,7 +62,7 @@ class Command(BaseCommand):
...
@@ -60,7 +62,7 @@ class Command(BaseCommand):
csv_writer
.
writerow
((
csv_writer
.
writerow
((
student
.
id
,
student
.
id
,
anonymous_id_for_user
(
student
,
None
),
anonymous_id_for_user
(
student
,
None
),
anonymous_id_for_user
(
student
,
course_
id
)
anonymous_id_for_user
(
student
,
course_
key
)
))
))
except
IOError
:
except
IOError
:
raise
CommandError
(
"Error writing to file:
%
s"
%
output_filename
)
raise
CommandError
(
"Error writing to file:
%
s"
%
output_filename
)
...
...
common/djangoapps/student/management/commands/change_enrollment.py
View file @
1f849e44
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
opaque_keys
import
InvalidKeyError
from
optparse
import
make_option
from
optparse
import
make_option
from
student.models
import
CourseEnrollment
,
User
from
student.models
import
CourseEnrollment
,
User
from
xmodule.modulestore.keys
import
CourseKey
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
...
@@ -55,8 +59,14 @@ class Command(BaseCommand):
...
@@ -55,8 +59,14 @@ class Command(BaseCommand):
raise
CommandError
(
"You must specify a course id for this command"
)
raise
CommandError
(
"You must specify a course id for this command"
)
if
not
options
[
'from_mode'
]
or
not
options
[
'to_mode'
]:
if
not
options
[
'from_mode'
]
or
not
options
[
'to_mode'
]:
raise
CommandError
(
'You must specify a "to" and "from" mode as parameters'
)
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
(
filter_args
=
dict
(
course_id
=
options
[
'course_id'
]
,
course_id
=
course_key
,
mode
=
options
[
'from_mode'
]
mode
=
options
[
'from_mode'
]
)
)
if
options
[
'user'
]:
if
options
[
'user'
]:
...
...
common/djangoapps/student/management/commands/create_random_users.py
View file @
1f849e44
...
@@ -7,12 +7,12 @@ from student.models import CourseEnrollment
...
@@ -7,12 +7,12 @@ from student.models import CourseEnrollment
from
student.views
import
_do_create_account
,
get_random_post_override
from
student.views
import
_do_create_account
,
get_random_post_override
def
create
(
n
,
course_
id
):
def
create
(
n
,
course_
key
):
"""Create n users, enrolling them in course_
id
if it's not None"""
"""Create n users, enrolling them in course_
key
if it's not None"""
for
i
in
range
(
n
):
for
i
in
range
(
n
):
(
user
,
user_profile
,
_
)
=
_do_create_account
(
get_random_post_override
())
(
user
,
user_profile
,
_
)
=
_do_create_account
(
get_random_post_override
())
if
course_
id
is
not
None
:
if
course_
key
is
not
None
:
CourseEnrollment
.
enroll
(
user
,
course_
id
)
CourseEnrollment
.
enroll
(
user
,
course_
key
)
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
...
@@ -32,5 +32,13 @@ Examples:
...
@@ -32,5 +32,13 @@ Examples:
return
return
n
=
int
(
args
[
0
])
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
)
create
(
n
,
course_id
)
common/djangoapps/student/management/commands/transfer_students.py
View file @
1f849e44
...
@@ -3,6 +3,7 @@ from django.core.management.base import BaseCommand
...
@@ -3,6 +3,7 @@ from django.core.management.base import BaseCommand
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
student.models
import
CourseEnrollment
from
student.models
import
CourseEnrollment
from
shoppingcart.models
import
CertificateItem
from
shoppingcart.models
import
CertificateItem
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
...
@@ -30,32 +31,35 @@ class Command(BaseCommand):
...
@@ -30,32 +31,35 @@ class Command(BaseCommand):
)
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
source
=
options
[
'source_course'
]
source
_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
options
[
'source_course'
])
dest
=
options
[
'dest_course'
]
dest
_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
options
[
'dest_course'
])
source_students
=
User
.
objects
.
filter
(
source_students
=
User
.
objects
.
filter
(
courseenrollment__course_id
=
source
)
courseenrollment__course_id
=
source_key
)
for
user
in
source_students
:
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
# Un Enroll from source course but don't mess
# with the enrollment in the destination course.
# with the enrollment in the destination course.
CourseEnrollment
.
unenroll
(
user
,
source
)
CourseEnrollment
.
unenroll
(
user
,
source_key
)
print
(
"Unenrolled {} from {}"
.
format
(
user
.
username
,
source
))
print
(
"Unenrolled {} from {}"
.
format
(
user
.
username
,
source
_key
.
to_deprecated_string
()
))
msg
=
"Skipping {}, already enrolled in destination course {}"
msg
=
"Skipping {}, already enrolled in destination course {}"
print
(
msg
.
format
(
user
.
username
,
dest
))
print
(
msg
.
format
(
user
.
username
,
dest
_key
.
to_deprecated_string
()
))
continue
continue
print
(
"Moving {}."
.
format
(
user
.
username
))
print
(
"Moving {}."
.
format
(
user
.
username
))
# Find the old enrollment.
# Find the old enrollment.
enrollment
=
CourseEnrollment
.
objects
.
get
(
user
=
user
,
enrollment
=
CourseEnrollment
.
objects
.
get
(
course_id
=
source
)
user
=
user
,
course_id
=
source_key
)
# Move the Student between the classes.
# Move the Student between the classes.
mode
=
enrollment
.
mode
mode
=
enrollment
.
mode
old_is_active
=
enrollment
.
is_active
old_is_active
=
enrollment
.
is_active
CourseEnrollment
.
unenroll
(
user
,
source
)
CourseEnrollment
.
unenroll
(
user
,
source_key
)
new_enrollment
=
CourseEnrollment
.
enroll
(
user
,
dest
,
mode
=
mode
)
new_enrollment
=
CourseEnrollment
.
enroll
(
user
,
dest
_key
,
mode
=
mode
)
# Unenroll from the new coures if the user had unenrolled
# Unenroll from the new coures if the user had unenrolled
# form the old course.
# form the old course.
...
@@ -65,12 +69,13 @@ class Command(BaseCommand):
...
@@ -65,12 +69,13 @@ class Command(BaseCommand):
if
mode
==
'verified'
:
if
mode
==
'verified'
:
try
:
try
:
certificate_item
=
CertificateItem
.
objects
.
get
(
certificate_item
=
CertificateItem
.
objects
.
get
(
course_id
=
source
,
course_id
=
source_key
,
course_enrollment
=
enrollment
)
course_enrollment
=
enrollment
)
except
CertificateItem
.
DoesNotExist
:
except
CertificateItem
.
DoesNotExist
:
print
(
"No certificate for {}"
.
format
(
user
))
print
(
"No certificate for {}"
.
format
(
user
))
continue
continue
certificate_item
.
course_id
=
dest
certificate_item
.
course_id
=
dest
_key
certificate_item
.
course_enrollment
=
new_enrollment
certificate_item
.
course_enrollment
=
new_enrollment
certificate_item
.
save
()
certificate_item
.
save
()
lms/djangoapps/instructor/management/commands/openended_stats.py
View file @
1f849e44
...
@@ -40,7 +40,7 @@ class Command(BaseCommand):
...
@@ -40,7 +40,7 @@ class Command(BaseCommand):
if
len
(
args
)
==
2
:
if
len
(
args
)
==
2
:
course_id
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
0
])
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
:
else
:
print
self
.
help
print
self
.
help
return
return
...
...
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