本文整理汇总了Python中pyramid.i18n.get_localizer函数的典型用法代码示例。如果您正苦于以下问题:Python get_localizer函数的具体用法?Python get_localizer怎么用?Python get_localizer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_localizer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
def render(self):
model = self.model
title = model.metadata.get('title', model.name)
if not model.properties.action_delete:
ts = _('object_not_deletable',
default='Object "${title}" not deletable',
mapping={'title': title})
localizer = get_localizer(self.request)
message = localizer.translate(ts)
ajax_message(self.request, message, 'error')
return u''
content_tile = model.properties.action_delete_tile
if not content_tile:
content_tile = 'content'
parent = model.parent
del parent[model.name]
if hasattr(parent, '__call__'):
parent()
query = make_query(contenttile=content_tile)
url = make_url(self.request, node=parent, query=query)
ajax_continue(self.request, self.continuation(url))
if self.show_confirm_deleted:
ts = _('deleted_object',
default='Deleted: ${title}',
mapping={'title': title})
localizer = get_localizer(self.request)
message = localizer.translate(ts)
ajax_message(self.request, message, 'info')
return u''
示例2: add_success
def add_success(self, emailform):
newemail = self.schema.serialize(emailform)
# We need to add the new email to the emails list
emails = self.user.get_mail_aliases()
mailsubdoc = {
'email': newemail['mail'],
'verified': False,
'added_timestamp': datetime.utcnow()
}
emails.append(mailsubdoc)
self.user.set_mail_aliases(emails)
try:
self.user.save(self.request)
except UserOutOfSync:
self.sync_user()
else:
message = _('Changes saved')
self.request.session.flash(get_localizer(self.request).translate(message), queue='forms')
send_verification_mail(self.request, newemail['mail'])
second_msg = _('A confirmation email has been sent to your email '
'address. Please enter your confirmation code '
'<a href="#" class="verifycode" '
'data-identifier="${id}">here</a>.', mapping={'id': len(emails)})
self.request.session.flash(get_localizer(self.request).translate(second_msg), queue='forms')
示例3: setprimary_action
def setprimary_action(self, index, post_data):
self.user = get_session_user(self.request)
try:
mail = self.user.mail_addresses.to_list()[index]
except IndexError:
return self.sync_user()
if not mail.is_verified:
message = _('You need to confirm your email address '
'before it can become primary')
return {
'result': 'bad',
'message': get_localizer(self.request).translate(message),
}
self.user.mail_addresses.primary = mail.email
try:
self.context.save_dashboard_user(self.user)
except UserOutOfSync:
return self.sync_user()
self.request.stats.count('dashboard/email_set_primary', 1)
message = _('Your primary email address was '
'successfully changed')
return {'result': 'success',
'message': get_localizer(self.request).translate(message)}
示例4: add_success
def add_success(self, emailform):
newemail = self.schema.serialize(emailform)
new_email = MailAddress(email=newemail['mail'],
application='dashboard',
verified=False, primary=False)
self.user = get_session_user(self.request)
self.user.mail_addresses.add(new_email)
try:
self.context.save_dashboard_user(self.user)
except UserOutOfSync:
self.sync_user()
else:
message = _('Changes saved')
self.request.session.flash(get_localizer(self.request).translate(message), queue='forms')
send_verification_mail(self.request, newemail['mail'])
second_msg = _('A confirmation email has been sent to your email '
'address. Please enter your confirmation code '
'<a href="#" class="verifycode" '
'data-identifier="${id}">here</a>.', mapping={'id': self.user.mail_addresses.count})
self.request.session.flash(get_localizer(self.request).translate(second_msg), queue='forms')
示例5: remove_action
def remove_action(self, index, post_data):
self.user = get_session_user(self.request)
emails = self.user.mail_addresses.to_list()
if len(emails) == 1:
message = _('Error: You only have one email address and it '
'can not be removed')
return {
'result': 'error',
'message': get_localizer(self.request).translate(message),
}
try:
remove_email = emails[index].email
except IndexError:
return self.sync_user()
try:
self.user.mail_addresses.remove(remove_email)
except PrimaryElementViolation:
new_index = 0 if index != 0 else 1
self.user.mail_addresses.primary = emails[new_index].email
self.user.mail_addresses.remove(remove_email)
try:
self.context.save_dashboard_user(self.user)
except UserOutOfSync:
return self.sync_user()
self.request.stats.count('dashboard/email_removed', 1)
message = _('Email address was successfully removed')
return {
'result': 'success',
'message': get_localizer(self.request).translate(message),
}
示例6: remove_action
def remove_action(self, index, post_data):
emails = self.user.get_mail_aliases()
if len(emails) == 1:
message = _('Error: You only have one email address and it '
'can not be removed')
return {
'result': 'error',
'message': get_localizer(self.request).translate(message),
}
remove_email = emails[index]['email']
emails.remove(emails[index])
self.user.set_mail_aliases(emails)
primary_email = self.user.get_mail()
if not primary_email or primary_email == remove_email:
self.user.set_mail(emails[0]['email'])
try:
self.user.save(self.request)
except UserOutOfSync:
return self.sync_user()
self.request.stats.count('dashboard/email_removed', 1)
message = _('Email address was successfully removed')
return {
'result': 'success',
'message': get_localizer(self.request).translate(message),
}
示例7: __call__
def __call__(self, node, value):
"""
Validator which makes sure that:
1. the NiN has not already been added by the user
2. the user does not already have a confirmed NiN.
"""
from eduiddashboard.models import normalize_nin
value = normalize_nin(copy(value))
request = node.bindings.get('request')
user = get_session_user(request)
user_nins = user.nins
unverified_user_nins = request.db.verifications.find({
'obj_id': value,
'model_name': 'norEduPersonNIN',
'user_oid': user.user_id,
'verified': False
})
# Search the request.POST for any post that starts with "add".
for post_value in request.POST:
if post_value.startswith('add') and (user_nins.find(value) or
unverified_user_nins.count() > 0):
err = _('National identity number already added')
raise colander.Invalid(node, get_localizer(request).translate(err))
elif post_value.startswith('add') and user_nins.count > 0:
err = _('You already have a confirmed national identity number')
raise colander.Invalid(node, get_localizer(request).translate(err))
示例8: account
def account(request):
change_password_form = forms.ChangePasswordForm(
csrf_context=request
)
if request.method == 'POST':
change_password_form.process(request.POST)
if change_password_form.validate():
try:
user = DBSession.query(User).filter(
User.id == authenticated_userid(request)
).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPNotFound()
user.set_password(change_password_form.password.data)
DBSession.add(user)
request.session.flash(
get_localizer(request).translate(_(
"Your password has been successfuly changed."
)),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url('alpaca.users.account')
)
else:
request.session.flash(
get_localizer(request).translate(_(
"There were some problems with your request."
" Please check the form for error messages."
)),
queue='error'
)
return {
'change_password_form': change_password_form,
}
示例9: setprimary_action
def setprimary_action(self, index, post_data):
self.user = get_session_user(self.request)
mobiles = self.user.phone_numbers.to_list()
try:
mobile = mobiles[index]
except IndexError:
return self.sync_user()
if not mobile.is_verified:
message = _('You need to confirm your mobile number '
'before it can become primary')
return {
'result': 'bad',
'message': get_localizer(self.request).translate(message),
}
self.user.phone_numbers.primary = mobile.number
try:
self.context.save_dashboard_user(self.user)
except UserOutOfSync:
return self.sync_user()
self.request.stats.count('mobile_number_set_primary')
message = _('Mobile phone number was successfully made primary')
return {
'result': 'success',
'message': get_localizer(self.request).translate(message),
}
示例10: user_add_to_group_action
def user_add_to_group_action(model, request):
"""Add user to group.
"""
group_id = request.params.get('id')
if not group_id:
group_ids = request.params.getall('id[]')
else:
group_ids = [group_id]
try:
user = model.model
validate_add_users_to_groups(model, [user.id], group_ids)
groups = user.root.groups
for group_id in group_ids:
groups[group_id].add(user.name)
groups()
model.parent.invalidate(user.name)
localizer = get_localizer(request)
message = localizer.translate(_(
'added_user_to_group',
default="Added user '${uid}' to group '${gid}'.",
mapping={
'uid': user.id,
'gid': ', '.join(group_ids)
}
))
return {
'success': True,
'message': message
}
except ManageMembershipError as e:
if e.reason is not LM_TARGET_GID_NOT_ALLOWED:
raise Exception(u"Unknown ManageMembershipError reason.")
localizer = get_localizer(request)
message = localizer.translate(_(
'lm_add_target_gid_not_allowed',
default=(
"Failed adding user '${uid}' to group '${gid}'. "
"Manage membership denied for target group."
),
mapping={
'uid': user.id,
'gid': e.data
}
))
return {
'success': False,
'message': message
}
except Exception as e:
return {
'success': False,
'message': str(e)
}
示例11: __init__
def __init__(self, context, request):
self.request = request
self.context = context
self.user = context.user
self.verify_messages = {}
for msgid, msg in self.default_verify_messages.items():
if msgid not in self.special_verify_messages:
self.verify_messages[msgid] = get_localizer(
request).translate(msg)
else:
self.verify_messages[msgid] = get_localizer(
request).translate(self.special_verify_messages[msgid])
示例12: user_remove_from_group_action
def user_remove_from_group_action(model, request):
"""Remove user from group.
"""
group_id = request.params.get("id")
if not group_id:
group_ids = request.params.getall("id[]")
else:
group_ids = [group_id]
try:
user = model.model
validate_remove_users_from_groups(model, [user.id], group_ids)
groups = user.root.groups
for group_id in group_ids:
del groups[group_id][user.name]
groups()
model.parent.invalidate(user.name)
localizer = get_localizer(request)
message = localizer.translate(
_(
"removed_user_from_group",
default="Removed user '${uid}' from group '${gid}'.",
mapping={"uid": user.id, "gid": ", ".join(group_ids)},
)
)
return {"success": True, "message": message}
except ManageMembershipError, e:
localizer = get_localizer(request)
if e.reason is LM_TARGET_GID_NOT_ALLOWED:
message = localizer.translate(
_(
"lm_remove_target_gid_not_allowed",
default="Failed removing user '${uid}' from group '${gid}'. "
"Manage membership denied for target group.",
mapping={"uid": user.id, "gid": e.data},
)
)
elif e.reason is LM_TARGET_GID_IS_DEFAULT:
message = localizer.translate(
_(
"lm_remove_target_gid_is_default",
default="Failed removing user '${uid}' from group '${gid}'. "
"Target group is default group of user.",
mapping={"uid": user.id, "gid": e.data},
)
)
else:
raise Exception(u"Unknown ManageMembershipError reason.")
return {"success": False, "message": message}
示例13: translate
def translate(*args, **kwargs):
request = get_current_request()
if request is None:
localizer = get_localizer_for_locale_name('en')
else:
localizer = get_localizer(request)
return localizer.translate(*args, **kwargs)
示例14: validate_python
def validate_python(self, value, state):
super(CSRFTokenValidator, self).validate_python(value, state)
request = state.request
token = request.session.get_csrf_token()
if token != value:
localizer = get_localizer(request)
raise formencode.Invalid(localizer.translate(_('Invalid CSRF token.')), value, state)
示例15: get_tab
def get_tab(request):
label = _('Postal address')
return {
'status': get_status,
'label': get_localizer(request).translate(label),
'id': 'postaladdress',
}