From fb57ffb80a6cbccb77e9f72c1abf331116feb4f2 Mon Sep 17 00:00:00 2001 From: jsa Date: Sat, 15 Mar 2014 13:35:21 -0400 Subject: [PATCH] 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 --- .../student/management/commands/create_user.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/djangoapps/student/management/commands/create_user.py b/common/djangoapps/student/management/commands/create_user.py index cacc5dea8e..bf848004ce 100644 --- a/common/djangoapps/student/management/commands/create_user.py +++ b/common/djangoapps/student/management/commands/create_user.py @@ -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()