Merge "Make error strings translatable"

This commit is contained in:
Jenkins 2014-02-01 17:05:48 +00:00 committed by Gerrit Code Review
commit 1ec7b76f77
5 changed files with 19 additions and 19 deletions

View File

@ -287,7 +287,7 @@ class Application(BaseApplication):
def _require_attribute(self, ref, attr):
"""Ensures the reference contains the specified attribute."""
if ref.get(attr) is None or ref.get(attr) == '':
msg = '%s field is required and cannot be empty' % attr
msg = _('%s field is required and cannot be empty') % attr
raise exception.ValidationError(message=msg)
def _get_trust_id_for_request(self, context):

View File

@ -70,9 +70,9 @@ class Identity(kvs.Base, identity.Driver):
try:
user_ref = self._get_user(user_id)
except exception.UserNotFound:
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
if not utils.check_password(password, user_ref.get('password')):
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
return identity.filter_user(user_ref)
def _get_user(self, user_id):
@ -115,7 +115,7 @@ class Identity(kvs.Base, identity.Driver):
except exception.UserNotFound:
pass
else:
msg = 'Duplicate ID, %s.' % user_id
msg = _('Duplicate ID, %s.') % user_id
raise exception.Conflict(type='user', details=msg)
try:
@ -123,7 +123,7 @@ class Identity(kvs.Base, identity.Driver):
except exception.UserNotFound:
pass
else:
msg = 'Duplicate name, %s.' % user['name']
msg = _('Duplicate name, %s.') % user['name']
raise exception.Conflict(type='user', details=msg)
user = utils.hash_user_password(user)
@ -150,7 +150,7 @@ class Identity(kvs.Base, identity.Driver):
user_key = self._calc_user_name_key(user['name'], domain_id)
existing = self.db.get(user_key, False)
if existing and user_id != existing['id']:
msg = 'Duplicate name, %s.' % user['name']
msg = _('Duplicate name, %s.') % user['name']
raise exception.Conflict(type='user', details=msg)
# get the old name and delete it too
old_user = self.db.get('user-%s' % user_id)

View File

@ -55,17 +55,17 @@ class Identity(identity.Driver):
try:
user_ref = self._get_user(user_id)
except exception.UserNotFound:
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
if not user_id or not password:
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
conn = None
try:
conn = self.user.get_connection(self.user._id_to_dn(user_id),
password)
if not conn:
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
except Exception:
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
finally:
if conn:
conn.unbind_s()
@ -92,10 +92,10 @@ class Identity(identity.Driver):
def update_user(self, user_id, user):
if 'id' in user and user['id'] != user_id:
raise exception.ValidationError('Cannot change user ID')
raise exception.ValidationError(_('Cannot change user ID'))
old_obj = self.user.get(user_id)
if 'name' in user and old_obj.get('name') != user['name']:
raise exception.Conflict('Cannot change user name')
raise exception.Conflict(_('Cannot change user name'))
user = utils.hash_ldap_user_password(user)
if self.user.enabled_mask:

View File

@ -47,7 +47,7 @@ def PAM_authenticate(username, password):
auth.authenticate()
auth.acct_mgmt()
except PAM.error:
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
return True
@ -64,7 +64,7 @@ class PamIdentity(identity.Driver):
def authenticate(self, user_id, password):
auth = pam.authenticate if pam else PAM_authenticate
if not auth(user_id, password):
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
user = {'id': user_id, 'name': user_id}
return user

View File

@ -104,9 +104,9 @@ class Identity(sql.Base, identity.Driver):
try:
user_ref = self._get_user(session, user_id)
except exception.UserNotFound:
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
if not self._check_password(password, user_ref):
raise AssertionError('Invalid user / password')
raise AssertionError(_('Invalid user / password'))
return identity.filter_user(user_ref.to_dict())
# user crud
@ -151,7 +151,7 @@ class Identity(sql.Base, identity.Driver):
def update_user(self, user_id, user):
session = db_session.get_session()
if 'id' in user and user_id != user['id']:
raise exception.ValidationError('Cannot change user ID')
raise exception.ValidationError(_('Cannot change user ID'))
with session.begin():
user_ref = self._get_user(session, user_id)
@ -189,7 +189,7 @@ class Identity(sql.Base, identity.Driver):
query = query.filter_by(user_id=user_id)
query = query.filter_by(group_id=group_id)
if not query.first():
raise exception.NotFound('User not found in group')
raise exception.NotFound(_('User not found in group'))
def remove_user_from_group(self, user_id, group_id):
session = db_session.get_session()
@ -200,7 +200,7 @@ class Identity(sql.Base, identity.Driver):
query = query.filter_by(group_id=group_id)
membership_ref = query.first()
if membership_ref is None:
raise exception.NotFound('User not found in group')
raise exception.NotFound(_('User not found in group'))
with session.begin():
session.delete(membership_ref)