Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
4a910f87
Commit
4a910f87
authored
11 years ago
by
John Jarvis
Browse files
Options
Downloads
Patches
Plain Diff
adding create_user script
parent
b4895140
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/djangoapps/student/management/commands/create_user.py
+88
-0
88 additions, 0 deletions
common/djangoapps/student/management/commands/create_user.py
with
88 additions
and
0 deletions
common/djangoapps/student/management/commands/create_user.py
0 → 100644
+
88
−
0
View file @
4a910f87
from
optparse
import
make_option
from
django.core.management.base
import
BaseCommand
from
student.models
import
CourseEnrollment
,
Registration
from
student.views
import
_do_create_account
from
django.contrib.auth.models
import
User
class
Command
(
BaseCommand
):
help
=
"""
This command creates and registers a user in a given course
as
"
audit
"
,
"
verified_id
"
or
"
honor
"
.
example:
# Enroll a user test@example.com into the demo course
# The username and name will default to
"
test
"
manage.py ... create_user -e test@example.com -p insecure -c edX/Open_DemoX/edx_demo_course -m verified_id
"""
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'
-m
'
,
'
--mode
'
,
metavar
=
'
ENROLLMENT_TYPE
'
,
dest
=
'
mode
'
,
default
=
'
honor
'
,
choices
=
(
'
audit
'
,
'
verified_id
'
,
'
honor
'
),
help
=
'
Enrollment type for user for a specific course
'
),
make_option
(
'
-u
'
,
'
--username
'
,
metavar
=
'
USERNAME
'
,
dest
=
'
username
'
,
default
=
None
,
help
=
'
Username, defaults to
"
user
"
in the email
'
),
make_option
(
'
-n
'
,
'
--name
'
,
metavar
=
'
NAME
'
,
dest
=
'
name
'
,
default
=
None
,
help
=
'
Name, defaults to
"
user
"
in the email
'
),
make_option
(
'
-p
'
,
'
--password
'
,
metavar
=
'
NAME
'
,
dest
=
'
password
'
,
default
=
None
,
help
=
'
Password for user
'
),
make_option
(
'
-e
'
,
'
--email
'
,
metavar
=
'
EMAIL
'
,
dest
=
'
email
'
,
default
=
None
,
help
=
'
Email for user
'
),
make_option
(
'
-c
'
,
'
--course
'
,
metavar
=
'
COURSE_ID
'
,
dest
=
'
course
'
,
default
=
None
,
help
=
'
course to enroll the user in (optiona)
'
),
make_option
(
'
-s
'
,
'
--staff
'
,
metavar
=
'
COURSE_ID
'
,
dest
=
'
staff
'
,
default
=
False
,
action
=
'
store_true
'
,
help
=
'
give user the staff bit
'
),
)
def
handle
(
self
,
*
args
,
**
options
):
username
=
options
[
'
username
'
]
name
=
options
[
'
name
'
]
if
not
username
:
username
=
options
[
'
email
'
].
split
(
'
@
'
)[
0
]
if
not
name
:
name
=
options
[
'
email
'
].
split
(
'
@
'
)[
0
]
post_data
=
{
'
username
'
:
username
,
'
email
'
:
options
[
'
email
'
],
'
password
'
:
options
[
'
password
'
],
'
name
'
:
name
,
'
honor_code
'
:
u
'
true
'
,
'
terms_of_service
'
:
u
'
true
'
,
}
create_account
=
_do_create_account
(
post_data
)
if
isinstance
(
create_account
,
tuple
):
user
=
create_account
[
0
]
if
options
[
'
staff
'
]:
user
.
is_staff
=
True
user
.
save
()
reg
=
Registration
.
objects
.
get
(
user
=
user
)
reg
.
activate
()
reg
.
save
()
else
:
print
create_account
user
=
User
.
objects
.
get
(
email
=
options
[
'
email
'
])
if
options
[
'
course
'
]:
CourseEnrollment
.
enroll
(
user
,
options
[
'
course
'
],
mode
=
options
[
'
mode
'
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment