本文整理汇总了Python中translations.helpers.truncate函数的典型用法代码示例。如果您正苦于以下问题:Python truncate函数的具体用法?Python truncate怎么用?Python truncate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了truncate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: impala_breadcrumbs
def impala_breadcrumbs(context, items=list(), add_default=True, crumb_size=40):
"""
show a list of breadcrumbs. If url is None, it won't be a link.
Accepts: [(url, label)]
"""
if add_default:
if context.get('WEBAPPS'):
base_title = _('Apps Marketplace')
else:
base_title = page_name(context['request'].APP)
crumbs = [(urlresolvers.reverse('home'), base_title)]
else:
crumbs = []
# add user-defined breadcrumbs
if items:
try:
crumbs += items
except TypeError:
crumbs.append(items)
crumbs = [(url, truncate(label, crumb_size)) for (url, label) in crumbs]
c = {'breadcrumbs': crumbs, 'has_home': add_default}
t = env.get_template('amo/impala/breadcrumbs.html').render(c)
return jinja2.Markup(t)
开发者ID:aspes,项目名称:zamboni,代码行数:25,代码来源:helpers.py
示例2: get
def get(self, request, *args, **kwargs):
form_data = self.get_search_data(request, ApiSearchForm)
query = form_data.get('q', '')
base_filters = {'type': form_data['type']}
qs = self.get_query(request, base_filters=base_filters,
region=self.get_region(request))
profile = get_feature_profile(request)
qs = self.apply_filters(request, qs, data=form_data, profile=profile)
names = []
descriptions = []
urls = []
icons = []
for obj in qs:
# FIXME: this does a lot of stuff we don't need. When es_app_to_dict
# is replaced by a Serializer, then we should replace this with a
# custom, lean serializer.
base_data = self.serialize(request, obj)
names.append(base_data['name'])
descriptions.append(truncate(base_data['description']))
urls.append(base_data['absolute_url'])
icons.append(base_data['icons'][64])
return Response([query, names, descriptions, urls, icons],
content_type='application/x-suggestions+json')
开发者ID:at-kevinlau,项目名称:zamboni,代码行数:26,代码来源:api.py
示例3: mkt_breadcrumbs
def mkt_breadcrumbs(context, product=None, items=None, crumb_size=40,
add_default=True, cls=None):
"""
Wrapper function for ``breadcrumbs``.
**items**
list of [(url, label)] to be inserted after Add-on.
**product**
Adds the App/Add-on name to the end of the trail. If items are
specified then the App/Add-on will be linked.
**add_default**
Prepends trail back to home when True. Default is True.
"""
if add_default:
crumbs = [(reverse('home'), _('Home'))]
else:
crumbs = []
if product:
if items:
url_ = product.get_detail_url()
else:
# The Product is the end of the trail.
url_ = None
crumbs += [(None, _('Apps')), (url_, product.name)]
if items:
crumbs.extend(items)
if len(crumbs) == 1:
crumbs = []
crumbs = [(u, truncate(label, crumb_size)) for (u, label) in crumbs]
t = env.get_template('site/helpers/breadcrumbs.html').render(
breadcrumbs=crumbs, cls=cls)
return jinja2.Markup(t)
开发者ID:almosteverywhere,项目名称:zamboni,代码行数:35,代码来源:helpers.py
示例4: test_suggestions
def test_suggestions(self):
response = self.client.get(self.url, data={"lang": "en-US"})
parsed = json.loads(response.content)
eq_(parsed[0], "")
self.assertSetEqual(parsed[1], [unicode(self.app1.name), unicode(self.app2.name)])
self.assertSetEqual(parsed[2], [unicode(self.app1.description), unicode(truncate(self.app2.description))])
self.assertSetEqual(parsed[3], [absolutify(self.app1.get_detail_url()), absolutify(self.app2.get_detail_url())])
self.assertSetEqual(parsed[4], [self.app1.get_icon_url(64), self.app2.get_icon_url(64)])
开发者ID:vinu76jsr,项目名称:zamboni,代码行数:8,代码来源:test_api.py
示例5: dehydrate
def dehydrate(self, bundle):
data = super(SuggestionsResource, self).dehydrate(bundle).data
return {
'description': truncate(data['description']),
'name': data['name'],
'absolute_url': data['absolute_url'],
'icon': data['icons'][64],
}
开发者ID:chrisdavidmills,项目名称:zamboni,代码行数:8,代码来源:api.py
示例6: test_redirect_sharing
def test_redirect_sharing(self):
addon = Addon.objects.get(id=3615)
r = self.client.get(reverse('addons.share', args=['a3615']),
{'service': 'delicious'})
url = absolutify(unicode(addon.get_url_path()))
summary = truncate(addon.summary, length=250)
eq_(r.status_code, 302)
assert iri_to_uri(addon.name) in r['Location']
assert iri_to_uri(url) in r['Location']
assert iri_to_uri(summary) in r['Location']
开发者ID:MechanisM,项目名称:zamboni,代码行数:10,代码来源:test_views.py
示例7: test_redirect_sharing
def test_redirect_sharing(self):
r = self.client.get(reverse('apps.share', args=['yeah']),
{'service': 'delicious'})
d = {
'title': page_title({'request': r}, self.webapp.name,
force_webapps=True),
'description': truncate(self.webapp.summary, length=250),
'url': absolutify(self.webapp.get_url_path()),
}
url = iri_to_uri(get_service('delicious').url.format(**d))
self.assertRedirects(r, url, status_code=302, target_status_code=301)
开发者ID:kaiquewdev,项目名称:zamboni,代码行数:11,代码来源:test_views.py
示例8: get
def get(self, request, *args, **kwargs):
results, query = self.search(request)
names = []
descriptions = []
urls = []
icons = []
for base_data in results.data['objects']:
names.append(base_data['name'])
descriptions.append(truncate(base_data['description']))
urls.append(base_data['absolute_url'])
icons.append(base_data['icons'][64])
return Response([query, names, descriptions, urls, icons],
content_type='application/x-suggestions+json')
开发者ID:imclab,项目名称:olympia,代码行数:15,代码来源:api.py
示例9: get
def get(self, request, *args, **kwargs):
results, query = self.search(request)
names = []
descs = []
urls = []
icons = []
for base_data in results.data['objects']:
names.append(base_data['name'])
descs.append(truncate(base_data['description']))
urls.append(base_data['absolute_url'])
icons.append(base_data['icon'])
# This results a list. Usually this is a bad idea, but we don't return
# any user-specific data, it's fully anonymous, so we're fine.
return HttpResponse(json.dumps([query, names, descs, urls, icons]),
content_type='application/x-suggestions+json')
开发者ID:aspes,项目名称:zamboni,代码行数:17,代码来源:views.py
示例10: breadcrumbs
def breadcrumbs(context, items=list(), add_default=True, crumb_size=40):
"""
show a list of breadcrumbs. If url is None, it won't be a link.
Accepts: [(url, label)]
"""
if add_default:
app = context['request'].APP
crumbs = [(urlresolvers.reverse('home'), page_name(app))]
else:
crumbs = []
# add user-defined breadcrumbs
if items:
try:
crumbs += items
except TypeError:
crumbs.append(items)
crumbs = [(url, truncate(label, crumb_size)) for (url, label) in crumbs]
c = {'breadcrumbs': crumbs}
t = env.get_template('amo/breadcrumbs.html').render(**c)
return jinja2.Markup(t)
开发者ID:rajuch,项目名称:zamboni,代码行数:21,代码来源:helpers.py
示例11: impala_breadcrumbs
def impala_breadcrumbs(context, items=list(), add_default=True, crumb_size=40):
"""
show a list of breadcrumbs. If url is None, it won't be a link.
Accepts: [(url, label)]
"""
if add_default:
base_title = page_name(context["request"].APP)
crumbs = [(urlresolvers.reverse("home"), base_title)]
else:
crumbs = []
# add user-defined breadcrumbs
if items:
try:
crumbs += items
except TypeError:
crumbs.append(items)
crumbs = [(url, truncate(label, crumb_size)) for (url, label) in crumbs]
c = {"breadcrumbs": crumbs, "has_home": add_default}
t = env.get_template("amo/impala/breadcrumbs.html").render(c)
return jinja2.Markup(t)
开发者ID:chetanmelkani,项目名称:olympia,代码行数:22,代码来源:helpers.py
示例12: clean_description
def clean_description(self):
return truncate(self.cleaned_data.get('description', ''), 250)
开发者ID:AALEKH,项目名称:zamboni,代码行数:2,代码来源:forms.py
示例13: share
def share(request, addon_id):
"""Add-on sharing"""
addon = get_object_or_404(Addon.objects.valid(), id=addon_id)
return share_redirect(request, addon, name=addon.name,
description=truncate(addon.summary, length=250))
开发者ID:ozten,项目名称:zamboni,代码行数:5,代码来源:views.py
示例14: share
def share(request, addon):
"""Add-on sharing"""
return share_redirect(request, addon, name=addon.name,
description=truncate(addon.summary, length=250))
开发者ID:LittleForker,项目名称:zamboni,代码行数:4,代码来源:views.py
示例15: truncate_response
def truncate_response(obj):
return truncate(obj.response, 50)
开发者ID:AALEKH,项目名称:zamboni,代码行数:2,代码来源:admin.py
注:本文中的translations.helpers.truncate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论