Merge pull request #2950 from edx/jsa/create-user-locale
in create_user mgmt command, use settings.LANGUAGE_CODE instead of en-us
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
from optparse import make_option
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import translation
|
||||
|
||||
from student.models import CourseEnrollment, Registration, create_comments_service_user
|
||||
from student.views import _do_create_account, AccountValidationError
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from track.management.tracked_command import TrackedCommand
|
||||
|
||||
|
||||
@@ -36,7 +39,7 @@ class Command(TrackedCommand):
|
||||
default=None,
|
||||
help='Name, defaults to "user" in the email'),
|
||||
make_option('-p', '--password',
|
||||
metavar='NAME',
|
||||
metavar='PASSWORD',
|
||||
dest='password',
|
||||
default=None,
|
||||
help='Password for user'),
|
||||
@@ -51,7 +54,6 @@ class Command(TrackedCommand):
|
||||
default=None,
|
||||
help='course to enroll the user in (optional)'),
|
||||
make_option('-s', '--staff',
|
||||
metavar='COURSE_ID',
|
||||
dest='staff',
|
||||
default=False,
|
||||
action='store_true',
|
||||
@@ -74,6 +76,11 @@ class Command(TrackedCommand):
|
||||
'honor_code': u'true',
|
||||
'terms_of_service': u'true',
|
||||
}
|
||||
# django.utils.translation.get_language() will be used to set the new
|
||||
# user's preferred language. This line ensures that the result will
|
||||
# match this installation's default locale. Otherwise, inside a
|
||||
# management command, it will always return "en-us".
|
||||
translation.activate(settings.LANGUAGE_CODE)
|
||||
try:
|
||||
user, profile, reg = _do_create_account(post_data)
|
||||
if options['staff']:
|
||||
@@ -87,3 +94,4 @@ class Command(TrackedCommand):
|
||||
user = User.objects.get(email=options['email'])
|
||||
if options['course']:
|
||||
CourseEnrollment.enroll(user, options['course'], mode=options['mode'])
|
||||
translation.deactivate()
|
||||
|
||||
Reference in New Issue
Block a user