当前位置: 首页>>代码示例>>Python>>正文


Python i18n._函数代码示例

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


在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: restore_post

def restore_post(request, id):
    post, revision = _load_post_and_revision(request, id)

    # sanity checks
    if revision is None:
        if not request.user.is_moderator:
            raise Forbidden()
        elif not post.is_deleted:
            return redirect(url_for(post))
    elif not request.user.can_edit(post):
        raise Forbidden()

    form = EmptyForm()
    if request.method == 'POST' and form.validate():
        if 'yes' in request.form:
            if revision is None:
                request.flash(_(u'The post was restored'))
                post.restore()
            else:
                request.flash(_(u'The revision was restored'))
                revision.restore()
            session.commit()
        return form.redirect(post)

    return render_template('kb/restore_post.html', form=form.as_widget(),
                           post=post, revision=revision)
开发者ID:Plurk,项目名称:Solace,代码行数:26,代码来源:kb.py

示例2: edit_post

def edit_post(request, id):
    post, revision = _load_post_and_revision(request, id)
    if not request.user.can_edit(post):
        raise Forbidden()

    if post.is_question:
        form = QuestionForm(post.topic, revision=revision)
    else:
        form = ReplyForm(post=post, revision=revision)

    if request.method == 'POST' and form.validate():
        form.save_changes()
        session.commit()
        request.flash(_('The post was edited.'))
        return redirect(url_for(post))

    def _format_entry(author, date, extra=u''):
        return _(u'%s (%s)') % (author, format_datetime(date)) + extra
    post_revisions = [(revision is None, '', _format_entry(
            (post.editor or post.author).display_name, post.updated,
            u' [%s]' % _(u'Current revision')))] + \
        [(revision == entry, entry.id, _format_entry(
            entry.editor.display_name, entry.date))
         for entry in post.revisions.order_by(PostRevision.date.desc())]

    return render_template('kb/edit_post.html', form=form.as_widget(),
                           post=post, all_revisions=post_revisions)
开发者ID:Plurk,项目名称:Solace,代码行数:27,代码来源:kb.py

示例3: get_serializer

def get_serializer(request):
    """Returns the serializer for the given API request."""
    format = request.args.get('format')
    if format is not None:
        rv = _serializer_map.get(format)
        if rv is None:
            raise BadRequest(_(u'Unknown format "%s"') % escape(format))
        return rv

    # webkit sends useless accept headers. They accept XML over
    # HTML or have no preference at all. We spotted them, so they
    # are obviously not regular API users, just ignore the accept
    # header and return the debug serializer.
    if request.user_agent.browser in ('chrome', 'safari'):
        return _serializer_map['debug']

    best_match = (None, 0)
    for mimetype, serializer in _serializer_for_mimetypes.iteritems():
        quality = request.accept_mimetypes[mimetype]
        if quality > best_match[1]:
            best_match = (serializer, quality)

    if best_match[0] is None:
        raise BadRequest(_(u'Could not detect format.  You have to specify '
                           u'the format as query argument or in the accept '
                           u'HTTP header.'))

    # special case.  If the best match is not html and the quality of
    # text/html is the same as the best match, we prefer HTML.
    if best_match[0] != 'text/html' and \
       best_match[1] == request.accept_mimetypes['text/html']:
        return _serializer_map['debug']

    return _serializer_map[best_match[0]]
开发者ID:sfermigier,项目名称:solace,代码行数:34,代码来源:api.py

示例4: vote

def vote(request, post):
    """Votes on a post."""
    # TODO: this is currently also fired as GET if JavaScript is
    # not available.  Not very nice.
    post = Post.query.get(post)
    if post is None:
        raise NotFound()

    # you cannot cast votes on deleted shit
    if post.is_deleted:
        message = _(u"You cannot vote on deleted posts.")
        if request.is_xhr:
            return json_response(message=message, error=True)
        request.flash(message, error=True)
        return redirect(url_for(post))

    # otherwise
    val = request.args.get("val", 0, type=int)
    if val == 0:
        request.user.unvote(post)
    elif val == 1:
        # users cannot upvote on their own stuff
        if post.author == request.user:
            message = _(u"You cannot upvote your own post.")
            if request.is_xhr:
                return json_response(message=message, error=True)
            request.flash(message, error=True)
            return redirect(url_for(post))
        # also some reputation is needed
        if not request.user.is_admin and request.user.reputation < settings.REPUTATION_MAP["UPVOTE"]:
            message = _(u"In order to upvote you " u"need at least %d reputation") % settings.REPUTATION_MAP["UPVOTE"]
            if request.is_xhr:
                return json_response(message=message, error=True)
            request.flash(message, error=True)
            return redirect(url_for(post))
        request.user.upvote(post)
    elif val == -1:
        # users need some reputation to downvote.  Keep in mind that
        # you *can* downvote yourself.
        if not request.user.is_admin and request.user.reputation < settings.REPUTATION_MAP["DOWNVOTE"]:
            message = (
                _(u"In order to downvote you " u"need at least %d reputation") % settings.REPUTATION_MAP["DOWNVOTE"]
            )
            if request.is_xhr:
                return json_response(message=message, error=True)
            request.flash(message, error=True)
            return redirect(url_for(post))
        request.user.downvote(post)
    else:
        raise BadRequest()
    session.commit()

    # standard requests are answered with a redirect back
    if not request.is_xhr:
        return redirect(url_for(post))

    # others get a re-rendered vote box
    box = get_macro("kb/_boxes.html", "render_vote_box")
    return json_response(html=box(post, request.user))
开发者ID:jlsandell,项目名称:solace,代码行数:59,代码来源:kb.py

示例5: validate_username

 def validate_username(self, value):
     user = User.query.filter_by(username=value).first()
     if user is None:
         raise forms.ValidationError(_(u'No such user.'))
     if self.request is not None and \
        self.request.user == user:
         raise forms.ValidationError(_(u'You cannot ban yourself.'))
     self.user = user
开发者ID:DasIch,项目名称:solace,代码行数:8,代码来源:forms.py

示例6: context_validate

 def context_validate(self, data):
     has_username = bool(data['username'])
     has_email = bool(data['email'])
     if not has_username and not has_email:
         raise forms.ValidationError(_(u'Either username or e-mail address '
                                       u' is required.'))
     if has_username and has_email:
         raise forms.ValidationError(_(u'You have to provide either a username '
                                       u'or an e-mail address, not both.'))
开发者ID:DasIch,项目名称:solace,代码行数:9,代码来源:forms.py

示例7: complete_login

 def complete_login(self, request):
     consumer = Consumer(request.session, SolaceOpenIDStore())
     openid_response = consumer.complete(request.args.to_dict(),
                                         url_for('core.login', _external=True))
     if openid_response.status == SUCCESS:
         return self.create_or_login(request, openid_response.identity_url)
     elif openid_response.status == CANCEL:
         raise LoginUnsucessful(_(u'The request was cancelled'))
     else:
         raise LoginUnsucessful(_(u'OpenID authentication error'))
开发者ID:DasIch,项目名称:solace,代码行数:10,代码来源:_openid_auth.py

示例8: is_valid_username

def is_valid_username(form, value):
    """Checks if the value is a valid username."""
    if len(value) > 40:
        raise forms.ValidationError(_(u'The username is too long.'))
    if '/' in value:
        raise forms.ValidationError(_(u'The username may not contain '
                                      u'slashes.'))
    if value[:1] == '.' or value[-1:] == '.':
        raise forms.ValidationError(_(u'The username may not begin or '
                                      u'end with a dot.'))
开发者ID:sfermigier,项目名称:solace,代码行数:10,代码来源:forms.py

示例9: get_recaptcha_html

def get_recaptcha_html(error=None):
    """Returns the recaptcha input HTML."""
    server = settings.RECAPTCHA_USE_SSL and API_SERVER or SSL_API_SERVER
    options = dict(k=settings.RECAPTCHA_PUBLIC_KEY)
    if error is not None:
        options["error"] = unicode(error)
    query = url_encode(options)
    return u"""
    <script type="text/javascript">var RecaptchaOptions = %(options)s;</script>
    <script type="text/javascript" src="%(script_url)s"></script>
    <noscript>
      <div><iframe src="%(frame_url)s" height="300" width="500"></iframe></div>
      <div><textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
      <input type="hidden" name="recaptcha_response_field" value="manual_challenge"></div>
    </noscript>
    """ % dict(
        script_url="%schallenge?%s" % (server, query),
        frame_url="%snoscript?%s" % (server, query),
        options=dumps(
            {
                "theme": "clean",
                "custom_translations": {
                    "visual_challenge": _("Get a visual challenge"),
                    "audio_challenge": _("Get an audio challenge"),
                    "refresh_btn": _("Get a new challenge"),
                    "instructions_visual": _("Type the two words:"),
                    "instructions_audio": _("Type what you hear:"),
                    "help_btn": _("Help"),
                    "play_again": _("Play sound again"),
                    "cant_hear_this": _("Download sound as MP3"),
                    "incorrect_try_again": _("Incorrect. Try again."),
                },
            }
        ),
    )
开发者ID:sfermigier,项目名称:solace,代码行数:35,代码来源:recaptcha.py

示例10: perform_login

 def perform_login(self, request, username, password):
     user = User.query.filter_by(username=username).first()
     if user is None:
         raise LoginUnsucessful(_(u'No user named %s') % username)
     if not user.is_active:
         raise LoginUnsucessful(_(u'The user is not yet activated.'))
     if not user.check_password(password):
         raise LoginUnsucessful(_(u'Invalid password'))
     if user.is_banned:
         raise LoginUnsucessful(_(u'The user got banned from the system.'))
     self.set_user(request, user)
开发者ID:sfermigier,项目名称:solace,代码行数:11,代码来源:auth.py

示例11: topic_feed

def topic_feed(request, id, slug=None):
    """A feed for the answers to a question."""
    topic = Topic.query.eagerposts().get(id)

    # if the topic id does not exist or the topic is from a different
    # language, we abort with 404 early
    if topic is None or topic.locale != request.view_lang:
        raise NotFound()

    # make sure the slug is okay, otherwise redirect to the real one
    # to ensure URLs are unique.
    if slug is None or topic.slug != slug:
        return redirect(url_for(topic, action="feed"))

    # deleted posts cannot be seen by people without privilegs
    if topic.is_deleted and not (request.user and request.user.is_moderator):
        raise Forbidden()

    feed = AtomFeed(
        u"%s — %s" % (topic.title, settings.WEBSITE_TITLE),
        subtitle=settings.WEBSITE_TAGLINE,
        feed_url=request.url,
        url=request.url_root,
    )

    feed.add(
        topic.title,
        topic.question.rendered_text,
        content_type="html",
        author=topic.question.author.display_name,
        url=url_for(topic, _external=True),
        id=topic.guid,
        updated=topic.question.updated,
        published=topic.question.created,
    )

    for reply in topic.replies:
        if reply.is_deleted and not (request.user and request.user.is_moderator):
            continue
        title = _(u"Answer by %s") % reply.author.display_name
        if reply.is_deleted:
            title += u" " + _("(deleted)")
        feed.add(
            title,
            reply.rendered_text,
            content_type="html",
            author=reply.author.display_name,
            url=url_for(reply, _external=True),
            id=reply.guid,
            updated=reply.updated,
            created=reply.created,
        )

    return feed.get_response()
开发者ID:jlsandell,项目名称:solace,代码行数:54,代码来源:kb.py

示例12: reset_password

 def reset_password(self, request, user):
     if settings.REGISTRATION_REQUIRES_ACTIVATION:
         user.is_active = False
         confirmation_url = url_for('core.activate_user', email=user.email,
                                    key=user.activation_key, _external=True)
         send_email(_(u'Registration Confirmation'),
                    render_template('mails/activate_user.txt', user=user,
                                    confirmation_url=confirmation_url),
                    user.email)
         request.flash(_(u'A mail was sent to %s with a link to finish the '
                         u'registration.') % user.email)
     else:
         request.flash(_(u'You\'re registered.  You can login now.'))
开发者ID:sfermigier,项目名称:solace,代码行数:13,代码来源:auth.py

示例13: unban_user

def unban_user(request, user):
    """Unbans a given user."""
    user = User.query.filter_by(username=user).first()
    if user is None:
        raise NotFound()
    next = request.next_url or url_for('admin.bans')
    if not user.is_banned:
        request.flash(_(u'The user is not banned.'))
        return redirect(next)
    admin_utils.unban_user(user)
    request.flash(_(u'The user “%s” was successfully unbanned and notified.') %
                  user.username)
    return redirect(next)
开发者ID:sfermigier,项目名称:solace,代码行数:13,代码来源:admin.py

示例14: accept

def accept(request, post):
    """Accept a post as an answer."""
    # TODO: this is currently also fired as GET if JavaScript is
    # not available.  Not very nice.
    post = Post.query.get(post)
    if post is None:
        raise NotFound()

    # just for sanity.  It makes no sense to accept the question
    # as answer.  The UI does not allow that, so the user must have
    # tampered with the data here.
    if post.is_question:
        raise BadRequest()

    # likewise you cannot accept a deleted post as answer
    if post.is_deleted:
        message = _(u'You cannot accept deleted posts as answers')
        if request.is_xhr:
            return json_response(message=message, error=True)
        request.flash(message, error=True)
        return redirect(url_for(post))

    topic = post.topic

    # if the post is already the accepted answer, we unaccept the
    # post as answer.
    if post.is_answer:
        if not request.user.can_unaccept_as_answer(post):
            message = _(u'You cannot unaccept this reply as an answer.')
            if request.is_xhr:
                return json_response(message=message, error=True)
            request.flash(message, error=True)
            return redirect(url_for(post))
        topic.accept_answer(None, request.user)
        session.commit()
        if request.is_xhr:
            return json_response(accepted=False)
        return redirect(url_for(post))

    # otherwise we try to accept the post as answer.
    if not request.user.can_accept_as_answer(post):
        message = _(u'You cannot accept this reply as answer.')
        if request.is_xhr:
            return json_response(message=message, error=True)
        request.flash(message, error=True)
        return redirect(url_for(post))
    topic.accept_answer(post, request.user)
    session.commit()
    if request.is_xhr:
        return json_response(accepted=True)
    return redirect(url_for(post))
开发者ID:Plurk,项目名称:Solace,代码行数:51,代码来源:kb.py

示例15: activate_user

def activate_user(request, email, key):
    """Activates the user."""
    # the email is not unique on the database, we try all matching users.
    # Most likely it's only one, otherwise we activate the first matching.
    user = User.query.filter_by(email=email, activation_key=key).first()
    if user is not None:
        user.is_active = True
        session.commit()
        request.flash(_(u'Your account was activated.  You can '
                        u'log in now.'))
        return redirect(url_for('core.login'))
    request.flash(_(u'User activation failed.  The user is either already '
                    u'activated or you followed a wrong link.'), error=True)
    return redirect(url_for('kb.overview'))
开发者ID:sfermigier,项目名称:solace,代码行数:14,代码来源:core.py


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