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
27104c93
Commit
27104c93
authored
Apr 18, 2014
by
John Jarvis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding django admin command to change enrollment
parent
19b6718c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
common/djangoapps/student/management/commands/change_enrollment.py
+78
-0
No files found.
common/djangoapps/student/management/commands/change_enrollment.py
0 → 100644
View file @
27104c93
from
django.core.management.base
import
BaseCommand
,
CommandError
from
optparse
import
make_option
from
student.models
import
CourseEnrollment
,
User
class
Command
(
BaseCommand
):
help
=
"""
Changes the enrollment status for students that meet
the criteria specified by the parameters to this command.
Example:
Change enrollment for user joe from audit to honor:
$ ... change_enrollment -u joe -c some/course/id --from audit --to honor
Change enrollment for all users in some/course/id from audit to honor
$ ... change_enrollment -u joe -c some/course/id --from audit --to honor
"""
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'-f'
,
'--from'
,
metavar
=
'FROM_MODE'
,
dest
=
'from_mode'
,
default
=
False
,
help
=
'move from this enrollment mode'
),
make_option
(
'-t'
,
'--to'
,
metavar
=
'TO_MODE'
,
dest
=
'to_mode'
,
default
=
False
,
help
=
'move to this enrollment mode'
),
make_option
(
'-u'
,
'--user'
,
metavar
=
'USER'
,
dest
=
'user'
,
default
=
False
,
help
=
"User to move, if not specified will move all users in the course"
),
make_option
(
'-c'
,
'--course'
,
metavar
=
'COURSE_ID'
,
dest
=
'course_id'
,
default
=
False
,
help
=
"course id to for transfer"
),
make_option
(
'-n'
,
'--noop'
,
action
=
'store_true'
,
dest
=
'noop'
,
default
=
False
,
help
=
"display what will be done but don't actually do anything"
)
)
def
handle
(
self
,
*
args
,
**
options
):
if
not
options
[
'course_id'
]:
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'
)
filter_args
=
dict
(
course_id
=
options
[
'course_id'
],
mode
=
options
[
'from_mode'
]
)
if
options
[
'user'
]:
if
'@'
in
options
[
'user'
]:
user
=
User
.
objects
.
get
(
email
=
options
[
'user'
])
else
:
user
=
User
.
objects
.
get
(
user
=
options
[
'user'
])
filter_args
[
'user'
]
=
user
enrollments
=
CourseEnrollment
.
objects
.
filter
(
**
filter_args
)
if
options
[
'noop'
]:
print
"Would have changed {num_enrollments} students from {from_mode} to {to_mode}"
.
format
(
num_enrollments
=
enrollments
.
count
(),
from_mode
=
options
[
'from_mode'
],
to_mode
=
options
[
'to_mode'
]
)
else
:
for
enrollment
in
enrollments
:
enrollment
.
update_enrollment
(
mode
=
options
[
'to_mode'
])
enrollment
.
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