• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python i18n.get_localizer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyramid.i18n.get_localizer函数的典型用法代码示例。如果您正苦于以下问题:Python get_localizer函数的具体用法?Python get_localizer怎么用?Python get_localizer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_localizer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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''
开发者ID:bluedynamics,项目名称:cone.app,代码行数:29,代码来源:authoring.py


示例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')
开发者ID:enriquepablo,项目名称:eduid-dashboard,代码行数:32,代码来源:emails.py


示例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)}
开发者ID:digideskio,项目名称:eduid-dashboard,代码行数:27,代码来源:emails.py


示例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')
开发者ID:digideskio,项目名称:eduid-dashboard,代码行数:25,代码来源:emails.py


示例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),
        }
开发者ID:digideskio,项目名称:eduid-dashboard,代码行数:34,代码来源:emails.py


示例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),
        }
开发者ID:enriquepablo,项目名称:eduid-dashboard,代码行数:29,代码来源:emails.py


示例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))
开发者ID:digideskio,项目名称:eduid-dashboard,代码行数:31,代码来源:validators.py


示例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,
    }
开发者ID:artfb,项目名称:alpaca,代码行数:35,代码来源:users.py


示例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),
        }
开发者ID:SUNET,项目名称:eduid-dashboard,代码行数:29,代码来源:mobiles.py


示例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)
        }
开发者ID:bluedynamics,项目名称:cone.ugm,代码行数:53,代码来源:actions.py


示例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])
开发者ID:SUNET,项目名称:eduid-dashboard,代码行数:12,代码来源:__init__.py


示例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}
开发者ID:bluedynamics,项目名称:cone.ugm,代码行数:48,代码来源:actions.py


示例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)
开发者ID:igudym,项目名称:Kotti,代码行数:7,代码来源:util.py


示例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)
开发者ID:avanov,项目名称:pyramid_webforms,代码行数:7,代码来源:api.py


示例15: get_tab

def get_tab(request):
    label = _('Postal address')
    return {
        'status': get_status,
        'label': get_localizer(request).translate(label),
        'id': 'postaladdress',
    }
开发者ID:enriquepablo,项目名称:eduid-dashboard,代码行数:7,代码来源:postal_address.py


示例16: save_success

    def save_success(self, addressform):
        address = self.schema.serialize(addressform)
        address['verified'] = False
        address['type'] = 'alternative'

        addresses = self.user.get_addresses()
        if len(addresses) > 0 and addresses[0].get('type') == 'official':
            if len(addresses) == 1:
                addresses.append(address)
            else:
                addresses[1] = address
        else:
            addresses = [address]

        # update the session data
        self.user.set_addresses(addresses)
        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')
            self.request.stats.count('dashboard/postal_address_saved', 1)
开发者ID:enriquepablo,项目名称:eduid-dashboard,代码行数:26,代码来源:postal_address.py


示例17: get_tab

def get_tab(request):
    label = _('Permissions')
    return {
        'status': get_dummy_status,
        'label': get_localizer(request).translate(label),
        'id': 'permissions',
    }
开发者ID:digideskio,项目名称:eduid-dashboard,代码行数:7,代码来源:permissions.py


示例18: get_cfg

	def get_cfg(self, model, req, **kwargs):
		loc = get_localizer(req)
		store = []
		maxlen = 0
		for sym in self.enum:
			store.append({
				'id'    : sym.value,
				'value' : loc.translate(sym.description)
			})
		return {
			'xtype'          : 'combobox',
			'allowBlank'     : self.kw.get('nullable', False),
			'name'           : self.name,
			'fieldLabel'     : loc.translate(self.kw.get('label', self.name)),
			'format'         : 'string',
			'displayField'   : 'value',
			'valueField'     : 'id',
			'queryMode'      : 'local',
			'editable'       : False,
			'forceSelection' : True,
			'store'          : {
				'xtype'  : 'simplestore',
				'fields' : ('id', 'value'),
				'data'   : store
			}
		}
开发者ID:annndrey,项目名称:npui,代码行数:26,代码来源:wizards.py


示例19: add_localizer

def add_localizer(event):
    request = event.request
    localizer = get_localizer(request)
    def auto_translate(string):
        return localizer.translate(tsf2(localizer.translate(tsf1(string))))
    request.localizer = localizer
    request.translate = auto_translate
开发者ID:sbrunner,项目名称:gpmap,代码行数:7,代码来源:subscribers.py


示例20: client_promise

def client_promise(ctx, request):
	loc = get_localizer(request)
	csrf = request.POST.get('csrf', '')
	diff = request.POST.get('diff', '')

	if 'submit' in request.POST:
		sess = DBSession()
		if csrf != request.get_csrf():
			request.session.flash({
				'text' : loc.translate(_('Error submitting form')),
				'class' : 'danger'
			})
			return HTTPSeeOther(location=request.route_url('stashes.cl.accounts', traverse=()))
		fp = FuturePayment()
		fp.stash = ctx
		fp.entity = request.user.parent
		fp.origin = FuturePaymentOrigin.user
		fp.difference = diff
		sess.add(fp)
		request.session.flash({
			'text' : loc.translate(_('Successfully added new promised payment'))
		})
		return HTTPSeeOther(location=request.route_url('stashes.cl.accounts', traverse=()))

	request.session.flash({
		'text' : loc.translate(_('Error submitting form')),
		'class' : 'danger'
	})

	return HTTPSeeOther(location=request.route_url('stashes.cl.accounts', traverse=()))
开发者ID:nikitos,项目名称:npui,代码行数:30,代码来源:views.py



注:本文中的pyramid.i18n.get_localizer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python i18n.make_localizer函数代码示例发布时间:2022-05-27
下一篇:
Python i18n.get_locale_name函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap