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

Python parser.get_object_fallback函数代码示例

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

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



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

示例1: _data

def _data(docs, locale):
    """Add the documents and showfor data to the context data."""
    data = {}
    for side, title in docs.iteritems():
        data[side] = get_object_fallback(Document, title, locale)
    data.update(SHOWFOR_DATA)
    return data
开发者ID:bowmasters,项目名称:kitsune,代码行数:7,代码来源:views.py


示例2: test_english

 def test_english(self):
     # Create the English document
     d = document(title='A doc')
     d.save()
     # Now it exists
     obj = get_object_fallback(Document, 'A doc', 'en-US', '!')
     eq_(d, obj)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:7,代码来源:test_parser.py


示例3: _hook_template

    def _hook_template(self, parser, space, title):
        """Handles Template:Template name, formatting the content using given
        args"""
        params = title.split('|')
        short_title = params.pop(0)
        template_title = 'Template:' + short_title

        message = _('The template "%s" does not exist or has no approved '
                    'revision.') % short_title
        template = get_object_fallback(Document, template_title,
                                       locale=self.locale, is_template=True)

        if not template or not template.current_revision:
            return message

        if template.id in parser.inclusions:
            return RECURSION_MESSAGE % template_title
        else:
            parser.inclusions.append(template.id)
        c = template.current_revision.content.rstrip()
        # Note: this completely ignores the allowed attributes passed to the
        # WikiParser.parse() method and defaults to ALLOWED_ATTRIBUTES.
        parsed = parser.parse(c, show_toc=False, attributes=ALLOWED_ATTRIBUTES,
                              locale=self.locale)
        parser.inclusions.pop()

        # Special case for inline templates
        if '\n' not in c:
            parsed = parsed.replace('<p>', '')
            parsed = parsed.replace('</p>', '')
        # Do some string formatting to replace parameters
        return _format_template_content(parsed, _build_template_params(params))
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:32,代码来源:parser.py


示例4: test_from_french

 def test_from_french(self):
     # Create the English document
     d = document(title='A doc')
     d.save()
     # Returns English document for French
     obj = get_object_fallback(Document, 'A doc', 'fr', '!')
     eq_(d, obj)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:7,代码来源:test_parser.py


示例5: mobile

def mobile(request):
    data = {}
    for side, title in MOBILE_DOCS.iteritems():
        message = _lazy(u'The template "%s" does not exist.') % title
        data[side] = get_object_fallback(Document, title, request.locale, message)

    data.update(SHOWFOR_DATA)
    return render(request, "dashboards/mobile.html", data)
开发者ID:Edinunzio,项目名称:kuma,代码行数:8,代码来源:views.py


示例6: _data

def _data(docs, locale, product):
    """Add the documents and showfor data to the context data."""
    data = {}
    for side, title in docs.iteritems():
        data[side] = get_object_fallback(Document, title, locale)
    data.update(SHOWFOR_DATA)
    data.update(search_params={'q_tags': product, 'product': product})
    return data
开发者ID:fox2mike,项目名称:kitsune,代码行数:8,代码来源:views.py


示例7: home

def home(request):
    data = {}
    for side, title in HOME_DOCS.iteritems():
        message = _lazy(u'The template "%s" does not exist.') % title
        data[side] = get_object_fallback(
            Document, title, request.locale, message)

    data.update(SHOWFOR_DATA)
    return jingo.render(request, 'dashboards/home.html', data)
开发者ID:HarshaJagadish,项目名称:kuma,代码行数:9,代码来源:views.py


示例8: test_french

    def test_french(self):
        # Create English parent document
        en_d = document()
        en_d.save()
        en_r = revision(document=en_d, is_approved=True)
        en_r.save()

        # Create the French document
        fr_d = document(parent=en_d, title='A doc', locale='fr')
        fr_d.save()
        obj = get_object_fallback(Document, 'A doc', 'fr', '!')
        eq_(fr_d, obj)

        # Also works when English exists
        d = document(title='A doc')
        d.save()
        obj = get_object_fallback(Document, 'A doc', 'fr', '!')
        eq_(fr_d, obj)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:18,代码来源:test_parser.py


示例9: _hook_include

    def _hook_include(self, parser, space, name):
        """Record an include link between documents, and then call super()."""
        include = get_object_fallback(Document, name, locale=self.locale)

        if include:
            self.current_doc.add_link_to(include, 'include')

        return (super(WhatLinksHereParser, self)
                ._hook_include(parser, space, name))
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:9,代码来源:parser.py


示例10: mobile

def mobile(request, template=None):
    data = {}
    docs = MOBILE_DOCS_FOR_MOBILE if request.MOBILE else MOBILE_DOCS
    for side, title in docs.iteritems():
        message = _lazy(u'The template "%s" does not exist.') % title
        data[side] = get_object_fallback(
            Document, title, request.locale, message)

    data.update(SHOWFOR_DATA)
    return jingo.render(request, template, data)
开发者ID:fwenzel,项目名称:kitsune,代码行数:10,代码来源:views.py


示例11: test_translated

    def test_translated(self):
        """If a localization of the English fallback exists, use it."""

        en_d = document(title='A doc')
        en_d.save()
        en_r = revision(document=en_d, is_approved=True)
        en_r.save()

        fr_d = document(parent=en_d, title='Une doc', locale='fr')
        fr_d.save()

        # Without an approved revision, the en-US doc should be returned.
        obj = get_object_fallback(Document, 'A doc', 'fr')
        eq_(en_d, obj)

        # Approve a revision, then fr doc should be returned.
        fr_r = revision(document=fr_d, is_approved=True)
        fr_r.save()
        obj = get_object_fallback(Document, 'A doc', 'fr')
        eq_(fr_d, obj)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:20,代码来源:test_parser.py


示例12: _hook_video

    def _hook_video(self, parser, space, title):
        """Handles [[Video:video title]] with locale from parser."""
        message = _lazy(u'The video "%s" does not exist.') % title

        # params, only modal supported for now
        title, params = build_hook_params(title, self.locale, VIDEO_PARAMS)

        v = get_object_fallback(Video, title, self.locale, message)
        if isinstance(v, basestring):
            return v

        return generate_video(v, params)
开发者ID:Akamad007,项目名称:kitsune,代码行数:12,代码来源:parser.py


示例13: _hook_internal_link

    def _hook_internal_link(self, parser, space, name):
        """Records links between documents, and then calls super()."""

        title = name.split('|')[0]
        locale = self.current_doc.locale

        linked_doc = get_object_fallback(Document, title, locale)
        if linked_doc is not None:
            self.current_doc.add_link_to(linked_doc, 'link')

        return (super(WhatLinksHereParser, self)
                ._hook_internal_link(parser, space, name))
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:12,代码来源:parser.py


示例14: _data

def _data(docs, locale, product, only_kb=False):
    """Add the documents and showfor data to the context data."""
    data = {}
    for side, title in docs.iteritems():
        data[side] = get_object_fallback(Document, title, locale)

    data.update(SHOWFOR_DATA)
    data.update(search_params={'product': product})

    if only_kb:
        data['search_params'].update(w=1)
    else:
        data['search_params'].update(q_tags=product)

    return data
开发者ID:erikrose,项目名称:kitsune,代码行数:15,代码来源:views.py


示例15: _data

def _data(docs, locale, product=None, q_tags=None, only_kb=False):
    """Add the documents and showfor data to the context data."""
    data = {}
    for side, title in docs.iteritems():
        data[side] = get_object_fallback(Document, title, locale)

    data.update(showfor_data())

    if product:
        data.update(search_params={'product': product})

    if only_kb:
        data.setdefault('search_params', {}).update({'w': 1})
    elif q_tags:
        data['search_params'].update(q_tags=q_tags)

    return data
开发者ID:MiChrFri,项目名称:kitsune,代码行数:17,代码来源:views.py


示例16: test_redirect

    def test_redirect(self):
        """Assert get_object_fallback follows wiki redirects."""
        target_rev = revision(
            document=document(title='target', save=True),
            is_approved=True,
            save=True)
        translated_target_rev = revision(
            document=document(parent=target_rev.document, locale='de',
                              save=True),
            is_approved=True,
            save=True)
        revision(
            document=document(title='redirect', save=True),
            content='REDIRECT [[target]]',
            is_approved=True).save()

        eq_(translated_target_rev.document,
            get_object_fallback(Document, 'redirect', 'de'))
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:18,代码来源:test_parser.py


示例17: test_redirect_translations_only

    def test_redirect_translations_only(self):
        """Make sure get_object_fallback doesn't follow redirects when working
        purely in the default language.

        That would make it hard to navigate to redirects (to edit them, for
        example).

        """
        revision(document=document(title='target', save=True),
                              content='O hai.',
                              is_approved=True).save()
        redirect_rev = revision(document=document(title='redirect', save=True),
                                content='REDIRECT [[target]]',
                                is_approved=True,
                                save=True)
        eq_(redirect_rev.document,
            get_object_fallback(Document, 'redirect',
                                redirect_rev.document.locale))
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:18,代码来源:test_parser.py


示例18: home

def home(request):
    """The home page."""
    if not show_new_sumo(request):
        return old_home(request)

    products = Product.objects.filter(visible=True)
    topics = Topic.objects.filter(visible=True)
    moz_news = get_object_fallback(
        Document, MOZILLA_NEWS_DOC, request.locale)

    try:
        hot_docs = documents_for(
            locale=request.locale,
            topics=[Topic.objects.get(slug=HOT_TOPIC_SLUG)])
    except Topic.DoesNotExist:
        # "hot" topic doesn't exist, move on.
        hot_docs = None

    return jingo.render(request, 'landings/home.html', {
        'products': products,
        'topics': topics,
        'hot_docs': hot_docs,
        'moz_news': moz_news})
开发者ID:Hugh-McCurdy,项目名称:kitsune,代码行数:23,代码来源:views.py


示例19: home

def home(request):
    """The home page."""
    if request.MOBILE:
        return redirect_to(request, 'products', permanent=False)

    products = Product.objects.filter(visible=True)
    topics = Topic.objects.filter(visible=True)
    moz_news = get_object_fallback(
        Document, MOZILLA_NEWS_DOC, request.LANGUAGE_CODE)

    try:
        hot_docs, fallback_hot_docs = documents_for(
            locale=request.LANGUAGE_CODE,
            topics=[Topic.objects.get(slug=HOT_TOPIC_SLUG)])
    except Topic.DoesNotExist:
        # "hot" topic doesn't exist, move on.
        hot_docs = fallback_hot_docs = None

    return jingo.render(request, 'landings/home.html', {
        'products': products,
        'topics': topics,
        'hot_docs': hot_docs,
        'fallback_hot_docs': fallback_hot_docs,
        'moz_news': moz_news})
开发者ID:bajubullet,项目名称:kitsune,代码行数:24,代码来源:views.py


示例20: test_empty

 def test_empty(self):
     """get_object_fallback returns message when no objects."""
     # English does not exist
     obj = get_object_fallback(Document, 'A doc', 'en-US', '!')
     eq_('!', obj)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:5,代码来源:test_parser.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python redis_utils.redis_client函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.urlparams函数代码示例发布时间: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