Skip to content

Commit

Permalink
feat: remove gettext call from TurboGears
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Styk <mart.styk@gmail.com>
  • Loading branch information
StykMartin committed Feb 8, 2025
1 parent 6f9d19e commit 8687e9a
Show file tree
Hide file tree
Showing 33 changed files with 364 additions and 366 deletions.
8 changes: 4 additions & 4 deletions Server/bkr/server/CSV_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,22 @@ class CSV(RPCRoot):
'import',
fields = [upload],
action = 'import data',
submit_text = _(u'Import CSV'),
submit_text = u'Import CSV',
)

exportform = HorizontalForm(
'export',
fields = [download],
action = 'export data',
submit_text = _(u'Export CSV'),
submit_text = u'Export CSV',
)

@expose(template='bkr.server.templates.form')
@identity.require(identity.not_anonymous())
def index(self, **kw):
return dict(
form = self.exportform,
title=_(u'CSV Export'),
title=u'CSV Export',
action = './action_export',
options = {},
value = kw,
Expand All @@ -128,7 +128,7 @@ def index(self, **kw):
def csv_import(self, **kw):
return dict(
form = self.importform,
title=_(u'CSV Import'),
title=u'CSV Import',
action = './action_import',
options = {},
value = kw,
Expand Down
2 changes: 1 addition & 1 deletion Server/bkr/server/admin_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self,**kw):
result_name = self.result_name)
self.search_widget_form = InlineForm('Search', fields=[self.search_auto],
method='get', action=self.widget_action,
submit_text=_(u'Search'))
submit_text=u'Search')
if getattr(self,'join',None) is None:
self.join = []
self.add = True
Expand Down
32 changes: 16 additions & 16 deletions Server/bkr/server/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,17 @@ def login_password(self, username, password, proxy_user=None):
"""
user = User.by_user_name(username)
if user is None:
raise LoginException(_(u'Invalid username or password'))
raise LoginException(u'Invalid username or password')
if not user.can_log_in():
raise LoginException(_(u'Invalid username or password'))
raise LoginException(u'Invalid username or password')
if not user.check_password(password):
raise LoginException(_(u'Invalid username or password'))
raise LoginException(u'Invalid username or password')
if proxy_user:
if not user.has_permission(u'proxy_auth'):
raise LoginException(_(u'%s does not have proxy_auth permission') % user.user_name)
raise LoginException(u'%s does not have proxy_auth permission' % user.user_name)
proxied_user = User.by_user_name(proxy_user)
if proxied_user is None:
raise LoginException(_(u'Proxy user %s does not exist') % proxy_user)
raise LoginException(u'Proxy user %s does not exist' % proxy_user)
identity.set_authentication(proxied_user, proxied_by=user)
else:
identity.set_authentication(user)
Expand Down Expand Up @@ -304,26 +304,26 @@ def login_oauth2(self, access_token, proxy_user=None):
token_info = token_info_resp.json()

if not token_info['active']:
raise LoginException(_(u'Invalid token'))
raise LoginException(u'Invalid token')

if not 'https://beaker-project.org/oidc/scope' in token_info.get('scope', '').split(' '):
raise LoginException(_(u'Token missing required scope'))
raise LoginException(u'Token missing required scope')

username = token_info.get('sub')
if not username:
raise LoginException(_(u'Token missing subject'))
raise LoginException(u'Token missing subject')

user = User.by_user_name(username)
if user is None:
raise LoginException(_(u'Invalid username'))
raise LoginException(u'Invalid username')
if not user.can_log_in():
raise LoginException(_(u'Invalid username'))
raise LoginException(u'Invalid username')
if proxy_user:
if not user.has_permission(u'proxy_auth'):
raise LoginException(_(u'%s does not have proxy_auth permission') % user.user_name)
raise LoginException(u'%s does not have proxy_auth permission' % user.user_name)
proxied_user = User.by_user_name(proxy_user)
if proxied_user is None:
raise LoginException(_(u'Proxy user %s does not exist') % proxy_user)
raise LoginException(u'Proxy user %s does not exist' % proxy_user)
identity.set_authentication(proxied_user, proxied_by=user)
else:
identity.set_authentication(user)
Expand Down Expand Up @@ -371,15 +371,15 @@ def login_krbV(self, krb_request, proxy_user=None):
username = cprinc.name.split("@")[0]
user = User.by_user_name(username)
if user is None:
raise LoginException(_(u'Invalid username'))
raise LoginException(u'Invalid username')
if not user.can_log_in():
raise LoginException(_(u'Invalid username'))
raise LoginException(u'Invalid username')
if proxy_user:
if not user.has_permission(u'proxy_auth'):
raise LoginException(_(u'%s does not have proxy_auth permission') % user.user_name)
raise LoginException(u'%s does not have proxy_auth permission' % user.user_name)
proxied_user = User.by_user_name(proxy_user)
if proxied_user is None:
raise LoginException(_(u'Proxy user %s does not exist') % proxy_user)
raise LoginException(u'Proxy user %s does not exist' % proxy_user)
identity.set_authentication(proxied_user, proxied_by=user)
else:
identity.set_authentication(user)
Expand Down
26 changes: 13 additions & 13 deletions Server/bkr/server/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ class Configuration(AdminPage):
exposed = False

id = widgets.HiddenField(name='id')
value_str = widgets.TextArea(name='value', label=_(u'Value'))
value_int = widgets.TextField(name='value', label=_(u'Value'), validator=validators.Int())
value_str = widgets.TextArea(name='value', label=u'Value')
value_int = widgets.TextField(name='value', label=u'Value', validator=validators.Int())
valid_from = widgets.TextField(name='valid_from',
label=_(u'Effective from date'),
label=u'Effective from date',
help_text=u"Enter date and time (YYYY-MM-DD HH:MM) in the future or leave blank for setting to take immediate effect")

string_form = HorizontalForm(
'configitem',
fields = [id, value_str, valid_from],
action = 'save_data',
submit_text = _(u'Save'),
submit_text = u'Save',
)

int_form = HorizontalForm(
'configitem',
fields = [id, value_int, valid_from],
action = 'save_data',
submit_text = _(u'Save'),
submit_text = u'Save',
)

value_grid = BeakerDataGrid(fields=[
Expand Down Expand Up @@ -67,7 +67,7 @@ def edit(self,**kw):
value = item.current_value()
)
else:
flash(_(u"Error: No item ID specified"))
flash(u"Error: No item ID specified")
raise redirect(".")

# Show all future values, and the previous five
Expand Down Expand Up @@ -100,24 +100,24 @@ def save(self, **kw):
if 'id' in kw and kw['id']:
item = ConfigItem.by_id(kw['id'])
else:
flash(_(u"Error: No item ID"))
flash(u"Error: No item ID")
raise redirect(".")
if kw['valid_from']:
try:
valid_from = datetime.strptime(kw['valid_from'], '%Y-%m-%d %H:%M')
except ValueError:
flash(_(u"Invalid date and time specification, use: YYYY-MM-DD HH:MM"))
flash(u"Invalid date and time specification, use: YYYY-MM-DD HH:MM")
raise redirect("/configuration/edit?id=%d" % item.id)
else:
valid_from = None

try:
item.set(kw['value'], valid_from, identity.current.user)
except Exception as msg:
flash(_(u"Failed to save setting: %s" % msg))
flash(u"Failed to save setting: %s" % msg)
raise redirect("/configuration/edit?id=%d" % item.id)

flash(_(u"%s saved" % item.name))
flash(u"%s saved" % item.name)
redirect(".")

@identity.require(identity.in_group("admin"))
Expand Down Expand Up @@ -151,7 +151,7 @@ def remove(self, **kw):
item.set(None, None, identity.current.user)
session.add(item)
session.flush()
flash(_(u"%s cleared") % item.description)
flash(u"%s cleared" % item.description)
raise redirect(".")

@identity.require(identity.in_group("admin"))
Expand All @@ -160,11 +160,11 @@ def delete(self, **kw):
item = ConfigItem.by_id(kw['item'])
val = item.value_class.by_id(kw['id'])
if val.valid_from <= datetime.utcnow():
flash(_(u"Cannot remove past value of %s") % item.name)
flash(u"Cannot remove past value of %s" % item.name)
raise redirect("/configuration/edit?id=%d" % item.id)
session.delete(val)
session.flush()
flash(_(u"Future value of %s cleared") % item.name)
flash(u"Future value of %s cleared" % item.name)
raise redirect(".")

@identity.require(identity.in_group("admin"))
Expand Down
45 changes: 22 additions & 23 deletions Server/bkr/server/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def reserve_system(self, *args, **kw):
try:
distro_tree = DistroTree.by_id(kw['distro_tree_id'])
except NoResultFound:
flash(_(u'Invalid distro tree id %s') % kw['distro_tree_id'])
flash(u'Invalid distro tree id %s' % kw['distro_tree_id'])
redirect(url('/reserveworkflow/', **kw))
else:
distro_tree = None
Expand Down Expand Up @@ -460,7 +460,7 @@ def _systems(self, systems, title, *args, **kw):
extra_hiddens['distro_tree_id'] = kw['distro_tree_id']

search_bar = SearchBar(name='systemsearch',
label=_(u'System Search'),
label=u'System Search',
enable_custom_columns=True,
extra_selects=[{'name': 'keyvalue',
'column': 'key/value',
Expand Down Expand Up @@ -589,10 +589,10 @@ def key_remove(self, system_id=None, key_type=None, key_value_id=None):
try:
system = System.by_id(system_id, identity.current.user)
except NoResultFound:
flash(_(u"Invalid Permission"))
flash(u"Invalid Permission")
redirect("/")
else:
flash(_(u"system_id, key_value_id and key_type must be provided"))
flash(u"system_id, key_value_id and key_type must be provided")
redirect("/")

if system.can_edit(identity.current.user):
Expand All @@ -614,9 +614,9 @@ def key_remove(self, system_id=None, key_type=None, key_value_id=None):

if removed:
system.date_modified = datetime.utcnow()
flash(_(u"removed %s/%s" % (removed.key.key_name, removed.key_value)))
flash(u"removed %s/%s" % (removed.key.key_name, removed.key_value))
else:
flash(_(u"Key_Value_Id not Found"))
flash(u"Key_Value_Id not Found")
redirect("./view/%s" % system.fqdn)

@expose(template="bkr.server.templates.system")
Expand All @@ -625,16 +625,16 @@ def _view_system_as_html(self, fqdn=None, **kw):
try:
system = System.by_fqdn(fqdn, identity.current.user)
except DatabaseLookupError:
flash(_(u"Unable to find %s" % fqdn))
flash(u"Unable to find %s" % fqdn)
redirect("/")
elif kw.get('id'):
try:
system = System.by_id(kw['id'], identity.current.user)
except InvalidRequestError:
flash(_(u"Unable to find system with id of %s" % kw['id']))
flash(u"Unable to find system with id of %s" % kw['id'])
redirect("/")
else:
flash(_(u"No given system to view"))
flash(u"No given system to view")
redirect("/")
our_user = identity.current.user
if our_user:
Expand Down Expand Up @@ -751,7 +751,7 @@ def save_labinfo(self, **kw):
try:
system = System.by_id(kw['id'], identity.current.user)
except InvalidRequestError:
flash(_(u"Unable to save Lab Info for %s" % kw['id']))
flash(u"Unable to save Lab Info for %s" % kw['id'])
redirect("/")
if system.labinfo:
labinfo = system.labinfo
Expand All @@ -773,7 +773,7 @@ def save_labinfo(self, **kw):
setattr(labinfo, field, kw[field])
system.labinfo = labinfo
system.date_modified = datetime.utcnow()
flash(_(u"Saved Lab Info"))
flash(u"Saved Lab Info")
redirect("/view/%s" % system.fqdn)

@expose()
Expand All @@ -782,15 +782,15 @@ def save_keys(self, id, **kw):
try:
system = System.by_id(id, identity.current.user)
except InvalidRequestError:
flash(_(u"Unable to Add Key for %s" % id))
flash(u"Unable to Add Key for %s" % id)
redirect("/")
# Add a Key/Value Pair
if kw.get('key_name') and kw.get('key_value'):
try:
key = Key.by_name(kw['key_name'])
except InvalidRequestError:
# FIXME allow user to create new keys
flash(_(u"Invalid key %s" % kw['key_name']))
flash(u"Invalid key %s" % kw['key_name'])
redirect("/view/%s" % system.fqdn)
if key.numeric:
key_value = Key_Value_Int(key, kw['key_value'])
Expand All @@ -810,7 +810,7 @@ def save_exclude(self, id, **kw):
try:
system = System.by_id(id, identity.current.user)
except InvalidRequestError:
flash(_(u"Unable to save Exclude flags for %s" % id))
flash(u"Unable to save Exclude flags for %s" % id)
redirect("/")
for arch in system.arch:
# Update Excluded Families
Expand Down Expand Up @@ -873,12 +873,12 @@ def remove_install(self, system_id, arch_id, **kw):
try:
system = System.by_id(system_id, identity.current.user)
except InvalidRequestError:
flash(_(u"Unable to remove Install Option for %s" % system_id))
flash(u"Unable to remove Install Option for %s" % system_id)
redirect("/")
try:
arch = Arch.by_id(arch_id)
except InvalidRequestError:
flash(_(u"Unable to lookup arch for %s" % arch_id))
flash(u"Unable to lookup arch for %s" % arch_id)
redirect("/")

if kw.get('osversion_id'):
Expand Down Expand Up @@ -946,7 +946,7 @@ def save_install(self, id, **kw):
try:
system = System.by_id(id, identity.current.user)
except InvalidRequestError:
flash(_(u"Unable to save Install Options for %s" % id))
flash(u"Unable to save Install Options for %s" % id)
redirect("/")
# Add an install option
if kw.get('prov_ksmeta') or kw.get('prov_koptions') or \
Expand Down Expand Up @@ -1060,15 +1060,15 @@ def legacypush(self, fqdn=None, inventory=None):
try:
system = System.query.filter(System.fqdn == fqdn.decode('ascii')).one()
except InvalidRequestError:
raise BX(_('No such system %s') % fqdn)
raise BX('No such system %s' % fqdn)
return system.update_legacy(inventory)

@expose()
def to_xml(self, taskid, to_screen=False, pretty=True, *args, **kw):
try:
task = TaskBase.get_by_t_id(taskid)
except Exception:
flash(_('Invalid Task: %s' % taskid))
flash('Invalid Task: %s' % taskid)
redirect(url('/'))
xml_text = lxml.etree.tostring(task.to_xml(), pretty_print=pretty, encoding='utf8')

Expand All @@ -1091,7 +1091,7 @@ def push(self, fqdn=None, inventory=None):
try:
system = System.query.filter(System.fqdn == fqdn.decode('ascii')).one()
except InvalidRequestError:
raise BX(_('No such system %s') % fqdn)
raise BX('No such system %s' % fqdn)
return system.update(inventory)

@expose(template='bkr.server.templates.forbidden')
Expand All @@ -1116,10 +1116,9 @@ def login(self, forward_url=None, **kwargs):
identity.set_authentication(user)
raise cherrypy.HTTPRedirect(forward_url)
else:
msg = _('The credentials you supplied were not correct or '
'did not grant access to this resource.')
msg = ('The credentials you supplied were not correct or did not grant access to this resource.')
else:
msg = _('Please log in.')
msg = 'Please log in.'
response.status = 403
return dict(message=msg, action='', forward_url=forward_url)

Expand Down
Loading

0 comments on commit 8687e9a

Please sign in to comment.