本文整理汇总了Python中pyramid.i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ipaddresses_landing
def ipaddresses_landing(self):
# sort_keys are passed to sorting drop-down
# Handle Allocate IP addresses form
if self.request.method == 'POST':
if self.allocate_form.validate():
new_ips = []
ipcount = int(self.request.params.get('ipcount', 0))
with boto_error_handler(self.request, self.location):
self.log_request(_(u"Allocating {0} ElasticIPs").format(ipcount))
for i in xrange(ipcount):
new_ip = self.conn.allocate_address()
new_ips.append(new_ip.public_ip)
prefix = _(u'Successfully allocated IPs')
ips = ', '.join(new_ips)
msg = u'{prefix} {ips}'.format(prefix=prefix, ips=ips)
self.request.session.flash(msg, queue=Notification.SUCCESS)
return HTTPFound(location=self.location)
self.render_dict.update(
initial_sort_key='public_ip',
json_items_endpoint=self.get_json_endpoint('ipaddresses_json'),
filter_fields=True,
filters_form=IPAddressesFiltersForm(self.request, conn=self.conn, formdata=self.request.params or None),
filter_keys=['public_ip', 'instance_id'],
sort_keys=self.get_sort_keys(),
)
return self.render_dict
示例2: notify_new_order_to_admin_by_email
def notify_new_order_to_admin_by_email(order_state, request):
admin_email = Config.get_string_value('config.admin_email')
if admin_email != None and admin_email != '':
localizer = get_localizer(request)
# Create the body of the message (a plain-text and an HTML version).
text_ts = _('plain_new_order_admin_mail',
mapping={'name': order_state.order.user.name,
'login': order_state.order.user.login,
'units': order_state.order.units,
'address': order_state.order.address,
'url': request.route_url('orders'),
'state': _('order_state_0',
domain='Ondestán')},
domain='Ondestan')
html_ts = _('html_new_order_admin_mail',
mapping={'name': order_state.order.user.name,
'login': order_state.order.user.login,
'units': order_state.order.units,
'address': order_state.order.address,
'url': request.route_url('orders'),
'state': _('order_state_0',
domain='Ondestán')},
domain='Ondestan')
subject_ts = _('subject_new_order_admin_mail', domain='Ondestan')
text = localizer.translate(text_ts)
html = localizer.translate(html_ts)
subject = localizer.translate(subject_ts)
send_mail(html, text, subject, admin_email)
示例3: scalinggroup_create
def scalinggroup_create(self):
"""Handles the POST from the Create Scaling Group wizard"""
if self.create_form.validate():
with boto_error_handler(self.request, self.request.route_path('scalinggroups')):
scaling_group_name = self.request.params.get('name')
self.log_request(_(u"Creating scaling group {0}").format(scaling_group_name))
scaling_group = AutoScalingGroup(
name=scaling_group_name,
launch_config=self.request.params.get('launch_config'),
availability_zones=self.request.params.getall('availability_zones'),
# load_balancers=self.request.params.getall('load_balancers'),
health_check_type=self.request.params.get('health_check_type'),
health_check_period=self.request.params.get('health_check_period'),
desired_capacity=self.request.params.get('desired_capacity'),
min_size=self.request.params.get('min_size'),
max_size=self.request.params.get('max_size'),
tags=self.parse_tags_param(scaling_group_name=scaling_group_name),
)
self.autoscale_conn.create_auto_scaling_group(scaling_group)
msg = _(u'Successfully created scaling group')
msg += ' {0}'.format(scaling_group.name)
self.request.session.flash(msg, queue=Notification.SUCCESS)
location = self.request.route_path('scalinggroup_view', id=scaling_group.name)
return HTTPFound(location=location)
else:
self.request.error_messages = self.create_form.get_errors_list()
return self.render_dict
示例4: notify_order_update_to_user_by_email
def notify_order_update_to_user_by_email(order_state, request):
localizer = get_localizer(request)
# Create the body of the message (a plain-text and an HTML version).
text_ts = _('plain_order_update_user_mail',
mapping={'name': order_state.order.user.name,
'login': order_state.order.user.login,
'units': order_state.order.units,
'address': order_state.order.address,
'url': request.route_url('orders'),
'state': localizer.translate(_('order_state_' + str(order_state.state),
domain='Ondestan'))},
domain='Ondestan')
html_ts = _('html_order_update_user_mail',
mapping={'name': order_state.order.user.name,
'login': order_state.order.user.login,
'units': order_state.order.units,
'address': order_state.order.address,
'url': request.route_url('orders'),
'state': localizer.translate(_('order_state_' + str(order_state.state),
domain='Ondestan'))},
domain='Ondestan')
subject_ts = _('subject_order_update_user_mail', domain='Ondestan')
text = localizer.translate(text_ts)
html = localizer.translate(html_ts)
subject = localizer.translate(subject_ts)
send_mail(html, text, subject, order_state.order.user.email)
示例5: update_user
def update_user(request):
localizer = get_localizer(request)
user_id = int(request.params['id'])
login = request.params['login']
name = request.params['name']
email = request.params['email']
user = User().queryObject().filter(User.login == login).scalar()
if ((user != None) and (user.id != user_id)):
msg = _('login_already_use', domain='Ondestan')
return localizer.translate(msg)
user = User().queryObject().filter(User.email == email).scalar()
if ((user != None) and (user.id != user_id)):
msg = _('email_already_use', domain='Ondestan')
return localizer.translate(msg)
user = User().queryObject().filter(User.id == user_id).scalar()
user.login = login
user.name = name
user.email = email
user.phone = request.params['phone']
user.password = sha512(request.params['password']).hexdigest()
user.update()
msg = _('user_profile_updated', domain='Ondestan')
return localizer.translate(msg)
示例6: securitygroup_create
def securitygroup_create(self):
if self.securitygroup_form.validate():
name = self.request.params.get('name')
description = self.request.params.get('description')
tags_json = self.request.params.get('tags')
with boto_error_handler(self.request, self.request.route_path('securitygroups')):
self.log_request(_(u"Creating security group {0}").format(name))
new_security_group = self.conn.create_security_group(name, description)
self.add_rules(security_group=new_security_group)
if tags_json:
tags = json.loads(tags_json)
for tagname, tagvalue in tags.items():
new_security_group.add_tag(tagname, tagvalue)
msg = _(u'Successfully created security group')
location = self.request.route_path('securitygroup_view', id=new_security_group.id)
if self.request.is_xhr:
return JSONResponse(status=200, message=msg)
else:
self.request.session.flash(msg, queue=Notification.SUCCESS)
return HTTPFound(location=location)
if self.request.is_xhr:
form_errors = ', '.join(self.securitygroup_form.get_errors_list())
return JSONResponse(status=400, message=form_errors) # Validation failure = bad request
else:
self.request.error_messages = self.securitygroup_form.get_errors_list()
return self.render_dict
示例7: __init__
def __init__(self, request):
super(UserView, self).__init__(request)
self.conn = self.get_connection(conn_type="iam")
with boto_error_handler(request, request.current_route_url()):
self.user = self.get_user()
if self.user is None:
self.location = self.request.route_path('users')
else:
self.location = self.request.route_path('user_view', name=self.user.user_name)
self.prefix = '/users'
self.user_form = None
self.change_password_form = ChangePasswordForm(self.request)
self.generate_form = GeneratePasswordForm(self.request)
self.delete_form = DeleteUserForm(self.request)
self.already_member_text = _(u"User already a member of all groups")
self.no_groups_defined_text = _(u"There are no groups defined")
self.render_dict = dict(
user=self.user,
prefix=self.prefix,
user_create_date=getattr(self.user, 'create_date', None),
change_password_form=self.change_password_form,
generate_form=self.generate_form,
delete_form=self.delete_form,
disable_form=DisableUserForm(self.request),
enable_form=EnableUserForm(self.request),
quota_err=_(u"Requires non-negative integer (or may be empty)"),
)
示例8: reset_password
def reset_password(request):
loginhash = request.matchdict['loginhash']
users = User().queryObject().all()
for user in users:
if sha512(user.login).hexdigest() == loginhash:
new_password = rand_string(10)
logger.info('Password of user ' + user.login +
' has been reset to ' + new_password)
user.password = sha512(new_password).hexdigest()
user.save()
localizer = get_localizer(request)
# Create the body of the message (a plain-text and an HTML version)
url = request.route_url('login')
text_ts = _('plain_password_reset_mail', mapping={
'name': user.name, 'password': new_password,
'url': url}, domain='Ondestan')
html_ts = _('html_password_reset_mail', mapping={'name': user.name,
'password': new_password, 'url': url},
domain='Ondestan')
subject_ts = _('subject_password_reset_mail', domain='Ondestan')
text = localizer.translate(text_ts)
html = localizer.translate(html_ts)
subject = localizer.translate(subject_ts)
send_mail(html, text, subject, user.email)
break
示例9: get_device_config_fancy_description
def get_device_config_fancy_description(config, request=None, locale=None):
if request != None:
localizer = get_localizer(request)
else:
localizer = get_custom_localizer(locale)
datatime = get_device_config_fancy_description_unit_value(config.datatime)
sampletime = get_device_config_fancy_description_unit_value(config.sampletime)
readtime = get_device_config_fancy_description_unit_value(config.readtime)
parameters = {
'datatime_val': datatime[0],
'datatime_unit': localizer.translate(_(datatime[1],
domain='Ondestan')),
'sampletime_val': sampletime[0],
'sampletime_unit': localizer.translate(_(sampletime[1],
domain='Ondestan')),
'readtime_val': readtime[0],
'readtime_unit': localizer.translate(_(readtime[1],
domain='Ondestan'))
}
return localizer.translate(_("fancy_config_description",
domain='Ondestan',
mapping=parameters))
示例10: volume_create
def volume_create(self):
if self.volume_form.validate():
name = self.request.params.get('name', '')
tags_json = self.request.params.get('tags')
size = int(self.request.params.get('size', 1))
zone = self.request.params.get('zone')
snapshot_id = self.request.params.get('snapshot_id')
kwargs = dict(size=size, zone=zone)
if snapshot_id:
snapshot = self.get_snapshot(snapshot_id)
kwargs['snapshot'] = snapshot
with boto_error_handler(self.request, self.request.route_path('volumes')):
self.log_request(_(u"Creating volume (size={0}, zone={1}, snapshot_id={2})").format(size, zone, snapshot_id))
volume = self.conn.create_volume(**kwargs)
# Add name tag
if name:
volume.add_tag('Name', name)
if tags_json:
tags = json.loads(tags_json)
for tagname, tagvalue in tags.items():
volume.add_tag(tagname, tagvalue)
msg = _(u'Successfully sent create volume request. It may take a moment to create the volume.')
self.request.session.flash(msg, queue=Notification.SUCCESS)
location = self.request.route_path('volume_view', id=volume.id)
return HTTPFound(location=location)
else:
self.request.error_messages = self.volume_form.get_errors_list()
return self.render_dict
示例11: snapshots_delete
def snapshots_delete(self):
snapshot_id = self.request.params.get('snapshot_id')
volume_id = self.request.params.get('volume_id')
snapshot = self.get_snapshot(snapshot_id)
# NOTE: could optimize by requiring snapshot name as param and avoid above CLC fetch
snapshot_name = TaggedItemView.get_display_name(snapshot)
location = self.get_redirect_location('snapshots')
if volume_id:
location = self.request.route_path('volume_snapshots', id=volume_id)
if snapshot and self.delete_form.validate():
with boto_error_handler(self.request, location):
images_registered = self.get_images_registered(snapshot_id)
if images_registered is not None:
for img in images_registered:
self.log_request(_(u"Deregistering image {0}").format(img.id))
img.deregister()
# Clear images cache
#ImagesView.invalidate_images_cache()
self.log_request(_(u"Deleting snapshot {0}").format(snapshot_id))
snapshot.delete()
prefix = _(u'Successfully deleted snapshot')
msg = '{prefix} {name}'.format(prefix=prefix, name=snapshot_name)
self.request.session.flash(msg, queue=Notification.SUCCESS)
return HTTPFound(location=location)
else:
msg = _(u'Unable to delete snapshot')
self.request.session.flash(msg, queue=Notification.ERROR)
return HTTPFound(location=location)
示例12: snapshot_register
def snapshot_register(self):
snapshot_id = self.snapshot.id
name = self.request.params.get('name')
description = self.request.params.get('description')
dot = self.request.params.get('dot')
reg_as_windows = self.request.params.get('reg_as_windows')
root_vol = BlockDeviceType(snapshot_id=snapshot_id)
root_vol.delete_on_termination = dot
bdm = BlockDeviceMapping()
root_device_name = '/dev/sda' if self.cloud_type == 'euca' else '/dev/sda1'
bdm[root_device_name] = root_vol
location = self.request.route_path('snapshot_view', id=snapshot_id)
if self.snapshot and self.register_form.validate():
with boto_error_handler(self.request, location):
self.log_request(_(u"Registering snapshot {0} as image {1}").format(snapshot_id, name))
self.snapshot.connection.register_image(
name=name, description=description,
root_device_name=root_device_name,
kernel_id=('windows' if reg_as_windows else None),
block_device_map=bdm)
prefix = _(u'Successfully registered snapshot')
msg = '{prefix} {id}'.format(prefix=prefix, id=snapshot_id)
# Clear images cache
#ImagesView.invalidate_images_cache()
self.request.session.flash(msg, queue=Notification.SUCCESS)
return HTTPFound(location=location)
return self.render_dict
示例13: keypair_create
def keypair_create(self):
if self.keypair_form.validate():
name = self.request.params.get('name')
session = self.request.session
new_keypair = None
location = self.request.route_path('keypair_view', id=name)
with boto_error_handler(self.request, location):
self.log_request(_(u"Creating keypair ")+name)
new_keypair = self.conn.create_key_pair(name)
# Store the new keypair material information in the session
self._store_file_(new_keypair.name+".pem",
'application/x-pem-file;charset=ISO-8859-1',
new_keypair.material)
msg_template = _(u'Successfully created key pair {keypair}')
msg = msg_template.format(keypair=name)
self.request.session.flash(msg, queue=Notification.SUCCESS)
if self.request.is_xhr:
import logging; logging.info(">>>>>>>>> using create keypair xhr... fix this")
keypair_material = new_keypair.material if new_keypair else None
resp_body = json.dumps(dict(message=msg, payload=keypair_material))
return Response(status=200, body=resp_body, content_type='application/x-pem-file;charset=ISO-8859-1')
else:
location = self.request.route_path('keypair_view', id=name)
return HTTPFound(location=location)
if self.request.is_xhr:
form_errors = ', '.join(self.keypair_form.get_errors_list())
return JSONResponse(status=400, message=form_errors) # Validation failure = bad request
else:
self.request.error_messages = self.keypair_form.get_errors_list()
return self.render_dict
示例14: __init__
def __init__(self, context, request):
self.context = context
self.request = request
self.version = __version__
self.home_url = request.application_url
self.help_url = request.registry.settings.get('help.url')
self.support_url = request.registry.settings.get('support.url') or "http://support.eucalyptus.com"
self.aws_enabled = asbool(request.registry.settings.get('aws.enabled'))
self.aws_regions = AWS_REGIONS
self.default_region = request.registry.settings.get('aws.default.region')
self.browser_password_save = 'true' if asbool(request.registry.settings.get('browser.password.save')) else 'false'
self.cloud_type = request.session.get('cloud_type')
self.selected_region = self.request.session.get('region', self.default_region)
self.selected_region_label = self.get_selected_region_label(self.selected_region)
self.username = self.request.session.get('username')
self.account = self.request.session.get('account')
self.username_label = self.request.session.get('username_label')
self.euca_logout_form = EucaLogoutForm(request=self.request)
self.date_format = _(u'%I:%M:%S %p %b %d %Y')
self.angular_date_format = _(u'hh:mm:ss a MMM d yyyy')
self.tag_pattern_key = '^(?!aws:).{0,128}$'
self.tag_pattern_value = '^(?!aws:).{0,256}$'
self.integer_gt_zero_pattern = '^[1-9]\d*$'
self.non_negative_pattern = '^[0-9]\d*$'
self.cidr_pattern = '{0}{1}'.format(
'^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}',
'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\/\d+)$'
)
self.querystring = self.get_query_string()
self.help_html_dir = 'eucaconsole:static/html/help/'
示例15: user_random_password
def user_random_password(self):
""" calls iam:UpdateLoginProfile """
if not(self.is_csrf_valid()):
return JSONResponse(status=400, message="missing CSRF token")
with boto_error_handler(self.request):
new_pass = PasswordGeneration.generate_password()
self.log_request(_(u"Generating password for user {0}").format(self.user.user_name))
try:
# try to fetch login profile.
self.conn.get_login_profiles(user_name=self.user.user_name)
# if that worked, update the profile
result = self.conn.update_login_profile(user_name=self.user.user_name, password=new_pass)
except BotoServerError:
# if that failed, create the profile
result = self.conn.create_login_profile(user_name=self.user.user_name, password=new_pass)
# assemble file response
account = self.request.session['account']
string_output = StringIO.StringIO()
csv_w = csv.writer(string_output)
header = [_(u'Account'), _(u'User Name'), _(u'Password')]
csv_w.writerow(header)
row = [account, self.user.user_name, new_pass]
csv_w.writerow(row)
self._store_file_(
"{acct}-{user}-login.csv".format(acct=account, user=self.user.user_name),
'text/csv', string_output.getvalue())
return dict(message=_(u"Successfully generated user password"), results="true")