本文整理汇总了Python中sumo.parser.get_object_fallback函数的典型用法代码示例。如果您正苦于以下问题:Python get_object_fallback函数的具体用法?Python get_object_fallback怎么用?Python get_object_fallback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_object_fallback函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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))
示例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)
示例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)
示例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
示例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)
示例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)
示例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))
示例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)
示例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)
示例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)
示例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))
示例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
示例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