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
a86086b7
Commit
a86086b7
authored
Jan 13, 2014
by
Feanil Patel
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2041 from edx/feanil/transfer_students
Add a command to transfer students from one course to another.
parents
6c49e0db
16d6d23f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
common/djangoapps/student/management/commands/transfer_students.py
+67
-0
No files found.
common/djangoapps/student/management/commands/transfer_students.py
0 → 100644
View file @
a86086b7
from
optparse
import
make_option
from
django.core.management.base
import
BaseCommand
from
django.contrib.auth.models
import
User
from
student.models
import
CourseEnrollment
from
shoppingcart.models
import
CertificateItem
class
Command
(
BaseCommand
):
help
=
"""
This command takes two course ids as input and transfers
all students enrolled in one course into the other. This will
remove them from the first class and enroll them in the second
class in the same mode as the first one. eg. honor, verified,
audit.
example:
# Transfer students from the old demoX class to a new one.
manage.py ... transfer_students -f edX/Open_DemoX/edx_demo_course -t edX/Open_DemoX/new_demoX
"""
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'-f'
,
'--from'
,
metavar
=
'SOURCE_COURSE'
,
dest
=
'source_course'
,
help
=
'The course to transfer students from.'
),
make_option
(
'-t'
,
'--to'
,
metavar
=
'DEST_COURSE'
,
dest
=
'dest_course'
,
help
=
'The new course to enroll the student into.'
),
)
def
handle
(
self
,
*
args
,
**
options
):
source
=
options
[
'source_course'
]
dest
=
options
[
'dest_course'
]
source_students
=
User
.
objects
.
filter
(
courseenrollment__course_id
=
source
)
for
user
in
source_students
:
print
(
"Moving {}."
.
format
(
user
.
username
))
# Find the old enrollment.
enrollment
=
CourseEnrollment
.
objects
.
get
(
user
=
user
,
course_id
=
source
)
# 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
)
# Unenroll from the new coures if the user had unenrolled
# form the old course.
if
not
old_is_active
:
new_enrollment
.
update_enrollment
(
is_active
=
False
)
if
mode
==
'verified'
:
try
:
certificate_item
=
CertificateItem
.
objects
.
get
(
course_id
=
source
,
course_enrollment
=
enrollment
)
except
CertificateItem
.
DoesNotExist
:
print
(
"No certificate for {}"
.
format
(
user
))
continue
certificate_item
.
course_id
=
dest
certificate_item
.
course_enrollment
=
new_enrollment
certificate_item
.
save
()
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