Commit fb57ffb8 by jsa

in create_user mgmt command, use settings.LANGUAGE_CODE instead of en-us.

Fixes the create_user admin command, which was creating user accounts
with a potentially invalid language preference.

JIRA: FOR-532
parent 58f05f36
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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment