本文整理汇总了Python中babel.numbers.format_number函数的典型用法代码示例。如果您正苦于以下问题:Python format_number函数的具体用法?Python format_number怎么用?Python format_number使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format_number函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: plaintext_post_handler
def plaintext_post_handler(bot, message):
if bot.settings['content_status']['text'] is False:
yield bot.bot.send_message(pgettext('User send text message for verification while texts is disabled',
'Accepting text messages are disabled'),
reply_to_message=message)
return
mes = message['text']
if mes.strip() != '':
if bot.settings['text_min'] <= len(mes) <= bot.settings['text_max']:
yield _request_message_confirmation(bot, message)
report_botan(message, 'slave_message')
return {
'sent_message': message
}
else:
report_botan(message, 'slave_message_invalid')
yield bot.send_message(pgettext('Incorrect text message received', 'Sorry, but we can proceed only '
'messages with length between '
'{min_msg_length} and {max_msg_length} '
'symbols.')
.format(min_msg_length=format_number(bot.settings['text_min'], bot.language),
max_msg_length=format_number(bot.settings['text_max'], bot.language)),
reply_to_message=message)
else:
report_botan(message, 'slave_message_empty')
yield bot.send_message(pgettext('User sent empty message', 'Seriously??? 8===3'),
reply_to_message=message)
开发者ID:andrey-yantsen,项目名称:boterator,代码行数:28,代码来源:post.py
示例2: landing
def landing(request):
"""Customer Care Landing page."""
twitter = request.twitter
# Stats. See customercare.cron.get_customercare_stats.
activity = cache.get(settings.CC_TWEET_ACTIVITY_CACHE_KEY)
if activity and 'resultset' in activity:
statsd.incr('customercare.stats.activity.hit')
activity_stats = []
for act in activity['resultset']:
if act is None: # Sometimes we get bad data here.
continue
activity_stats.append((act[0], {
'requests': format_number(act[1], locale='en_US'),
'replies': format_number(act[2], locale='en_US'),
'perc': act[3] * 100,
}))
else:
statsd.incr('customercare.stats.activity.miss')
activity_stats = []
contributors = cache.get(settings.CC_TOP_CONTRIB_CACHE_KEY)
if contributors and 'resultset' in contributors:
statsd.incr('customercare.stats.contributors.hit')
contributor_stats = {}
for contrib in contributors['resultset']:
# Create one list per time period
period = contrib[1]
if not contributor_stats.get(period):
contributor_stats[period] = []
elif len(contributor_stats[period]) == 16:
# Show a max. of 16 people.
continue
contributor_stats[period].append({
'name': contrib[2],
'username': contrib[3],
'count': contrib[4],
'avatar': contributors['avatars'].get(contrib[3]),
})
else:
statsd.incr('customercare.stats.contributors.miss')
contributor_stats = {}
return jingo.render(request, 'customercare/landing.html', {
'activity_stats': activity_stats,
'contributor_stats': contributor_stats,
'canned_responses': CANNED_RESPONSES,
'tweets': _get_tweets(locale=request.locale,
https=request.is_secure()),
'authed': twitter.authed,
'twitter_user': (twitter.api.auth.get_username() if
twitter.authed else None),
'filters': FILTERS,
})
开发者ID:Curlified,项目名称:kitsune,代码行数:56,代码来源:views.py
示例3: month_stats_ajax
def month_stats_ajax(request):
user_total = ClickStats.objects.total_for_user_period(
request.user, request.POST['month'], request.POST['year'])
site_avg = ClickStats.objects.average_for_period(
request.POST['month'], request.POST['year'])
locale = current_locale()
results = {'user_total': format_number(user_total, locale=locale),
'site_avg': format_number(site_avg, locale=locale)}
return HttpResponse(json.dumps(results), mimetype='application/json')
开发者ID:davedash,项目名称:affiliates,代码行数:10,代码来源:views.py
示例4: month_stats_ajax
def month_stats_ajax(request):
user_total = ClickStats.objects.total(badge_instance__user=request.user,
month=request.POST['month'],
year=request.POST['year'])
site_avg = ClickStats.objects.average_for_period(month=request.POST['month'],
year=request.POST['year'])
locale = Locale.parse(get_language(), sep='-')
results = {'user_total': format_number(user_total, locale=locale),
'site_avg': format_number(site_avg, locale=locale)}
return HttpResponse(json.dumps(results), mimetype='application/json')
开发者ID:stephendonner,项目名称:affiliates,代码行数:11,代码来源:views.py
示例5: landing
def landing(request):
"""Customer Care Landing page."""
twitter = request.twitter
canned_responses = CannedCategory.objects.filter(locale=request.locale)
# Stats. See customercare.cron.get_customercare_stats.
activity = cache.get(settings.CC_TWEET_ACTIVITY_CACHE_KEY)
if activity:
activity_stats = []
for act in activity['resultset']:
activity_stats.append((act[0], {
'requests': format_number(act[1], locale='en_US'),
'replies': format_number(act[2], locale='en_US'),
'perc': act[3] * 100,
}))
else:
activity_stats = []
contributors = cache.get(settings.CC_TOP_CONTRIB_CACHE_KEY)
if contributors:
contributor_stats = {}
for contrib in contributors['resultset']:
# Create one list per time period
period = contrib[1]
if not contributor_stats.get(period):
contributor_stats[period] = []
elif len(contributor_stats[period]) == 16:
# Show a max. of 16 people.
continue
contributor_stats[period].append({
'name': contrib[2],
'username': contrib[3],
'count': contrib[4],
'avatar': contributors['avatars'].get(contrib[3]),
})
else:
contributor_stats = []
return jingo.render(request, 'customercare/landing.html', {
'activity_stats': activity_stats,
'contributor_stats': contributor_stats,
'canned_responses': canned_responses,
'tweets': _get_tweets(locale=request.locale),
'authed': twitter.authed,
'twitter_user': (twitter.api.auth.get_username() if
twitter.authed else None),
'filters': FILTERS,
})
开发者ID:AutomatedTester,项目名称:kitsune,代码行数:51,代码来源:views.py
示例6: format_number
def format_number(self, number):
"""Return the given number formatted
>>> Locale('en', 'US').format_number(1099)
u'1,099'
"""
return numbers.format_number(number, self)
开发者ID:nagareproject,项目名称:core,代码行数:7,代码来源:i18n.py
示例7: dashboard
def dashboard(request, template, context=None):
"""
Performs common operations needed by pages using the 'dashboard' template.
"""
if context is None:
context = {}
locale = current_locale()
# Set context variables needed by all dashboard pages
context['newsitem'] = NewsItem.objects.current()
context['user_has_created_badges'] = request.user.has_created_badges()
if context['user_has_created_badges']:
clicks_total = ClickStats.objects.total_for_user(request.user)
# Add Facebook clicks to total
fb_user = request.user.get_linked_account()
if fb_user is not None:
clicks_total += FacebookClickStats.objects.total_for_user(fb_user)
context['user_clicks_total'] = format_number(clicks_total,
locale=locale)
# Leaderboard
try:
context['show_leaderboard'] = True
context['leaderboard'] = (Leaderboard.objects
.top_users(settings.LEADERBOARD_SIZE))
context['user_standing'] = (Leaderboard.objects
.get(user=request.user))
except Leaderboard.DoesNotExist:
context['show_leaderboard'] = False
return jingo.render(request, template, context)
开发者ID:Hugochazz,项目名称:affiliates,代码行数:35,代码来源:views.py
示例8: i_format
def i_format(loc, s, *a, **kw):
if a:
a = list(a)
for c, f in [(a, enumerate), (kw, dict.items)]:
for k, o in f(c):
o, wrapper = (o.value, o.wrapper) if isinstance(o, Wrap) else (o, None)
if isinstance(o, text_type):
pass
elif isinstance(o, Decimal):
c[k] = format_decimal(o, locale=loc)
elif isinstance(o, int):
c[k] = format_number(o, locale=loc)
elif isinstance(o, Money):
c[k] = loc.format_money(o)
elif isinstance(o, MoneyBasket):
c[k] = loc.format_money_basket(o)
elif isinstance(o, Age):
c[k] = format_timedelta(o, locale=loc, **o.format_args)
elif isinstance(o, timedelta):
c[k] = format_timedelta(o, locale=loc)
elif isinstance(o, datetime):
c[k] = format_datetime(o, locale=loc)
elif isinstance(o, date):
c[k] = format_date(o, locale=loc)
elif isinstance(o, Locale):
c[k] = loc.languages.get(o.language) or o.language.upper()
elif isinstance(o, Currency):
c[k] = loc.currencies.get(o, o)
if wrapper:
c[k] = wrapper % (c[k],)
return s.format(*a, **kw)
开发者ID:devmiyax,项目名称:liberapay.com,代码行数:31,代码来源:i18n.py
示例9: l10n_format_number
def l10n_format_number(ctx, number):
"""
Formats a number according to the current locale. Wraps around
babel.numbers.format_number.
"""
lang = get_locale(ctx['LANG'])
return format_number(number, locale=lang)
开发者ID:1234-,项目名称:bedrock,代码行数:7,代码来源:helpers.py
示例10: month_stats_ajax
def month_stats_ajax(request, month, year):
user_total = ClickStats.objects.total_for_user_period(request.user, month,
year)
site_avg = ClickStats.objects.average_for_period(month, year)
locale = current_locale()
results = {'user_total': format_number(user_total, locale=locale),
'site_avg': format_number(site_avg, locale=locale)}
# Get linked Facebook click count if available.
facebook_user = request.user.get_linked_account()
if facebook_user is not None:
fb_total = FacebookClickStats.objects.total_for_month(facebook_user,
year, month)
results['fb_total'] = format_number(fb_total, locale=locale)
return HttpResponse(json.dumps(results), mimetype='application/json')
开发者ID:Hugochazz,项目名称:affiliates,代码行数:17,代码来源:views.py
示例11: number
def number(self, number):
"""Return an integer number formatted for the locale.
>>> fmt = Format('en_US')
>>> fmt.number(1099)
u'1,099'
"""
return format_number(number, locale=self.locale)
开发者ID:AaronJaramillo,项目名称:shopDPM,代码行数:8,代码来源:support.py
示例12: format_number
def format_number(number):
"""Return the given number formatted for the locale in request
:param number: the number to format
:return: the formatted number
:rtype: unicode
"""
locale = get_locale()
return numbers.format_number(number, locale=locale)
开发者ID:dpgaspar,项目名称:flask-babelPkg,代码行数:9,代码来源:__init__.py
示例13: price_format_decimal_to_currency
def price_format_decimal_to_currency(value, currency='EUR'):
if value:
try:
if currency in CURRENCY_PATTERNS.keys():
value = CURRENCY_PATTERNS[currency]['format'] % format_number(value, locale = CURRENCY_PATTERNS[currency]['locale'])
else:
return value
except:
return value
return value
开发者ID:dalou,项目名称:django-extended,代码行数:10,代码来源:price.py
示例14: number
def number(self, number):
"""Return an integer number formatted for the locale.
>>> fmt = Format('en_US')
>>> fmt.number(1099) == u('1,099')
True
:see: `babel.numbers.format_number`
"""
return format_number(number, locale=self.locale)
开发者ID:AtomLaw,项目名称:Ally-Py,代码行数:10,代码来源:support.py
示例15: test_smoke_numbers
def test_smoke_numbers(locale):
locale = Locale.parse(locale)
for number in (
Decimal("-33.76"), # Negative Decimal
Decimal("13.37"), # Positive Decimal
1.2 - 1.0, # Inaccurate float
10, # Plain old integer
0, # Zero
):
assert numbers.format_number(number, locale=locale)
开发者ID:Mabusto,项目名称:babel,代码行数:10,代码来源:test_smoke.py
示例16: format_number
def format_number(number):
"""Return a formatted number.
Note that this function does the same as :func:`format_decimal`,
but without the possibility to specify custom formats.
This function is also available in the template context as filter
named `numberformat`.
"""
locale = get_locale()
return numbers.format_number(number, locale=locale)
开发者ID:lalinsky,项目名称:flask-babel,代码行数:11,代码来源:babel.py
示例17: format_number
def format_number(self, number, locale=None, **kwargs):
"""Return the given number formatted for the locale in the
current request.
:param number: the number to format
:param locale: Overwrite the global locale.
"""
if number in ('', None):
return ''
locale = utils.normalize_locale(locale) or self.get_locale()
return numbers.format_number(number, locale=locale, **kwargs)
开发者ID:jpscaletti,项目名称:allspeak,代码行数:12,代码来源:l10n.py
示例18: month_stats_ajax
def month_stats_ajax(request, month, year):
# Check for placeholder values and return a 400 if they are present.
if month == ':month:' or year == ':year:':
return JSONResponseBadRequest({'error': 'Invalid year/month value.'})
user_total = ClickStats.objects.total_for_user_period(request.user, month,
year)
site_avg = ClickStats.objects.average_for_period(month, year)
locale = current_locale()
results = {'user_total': format_number(user_total, locale=locale),
'site_avg': format_number(site_avg, locale=locale)}
# Get linked Facebook click count if available.
facebook_user = request.user.get_linked_account()
if facebook_user is not None:
fb_total = FacebookClickStats.objects.total_for_month(facebook_user,
year, month)
results['fb_total'] = format_number(fb_total, locale=locale)
return JSONResponse(results)
开发者ID:disegnovitruviano,项目名称:affiliates,代码行数:21,代码来源:views.py
示例19: format_number
def format_number(self, number):
"""Returns the given number formatted for the current locale. Example::
>>> format_number(1099, locale='en_US')
u'1,099'
:param number:
The number to format.
:returns:
The formatted number.
"""
return numbers.format_number(number, locale=self.locale)
开发者ID:404minds,项目名称:quiz-forest,代码行数:12,代码来源:i18n.py
示例20: format_number
def format_number(number):
"""Returns the given number formatted for a specific locale.
>>> format_number(1099, locale='en_US')
u'1,099'
:param number:
The number to format.
:return:
The formatted number.
"""
# Do we really need this one?
return numbers.format_number(number, locale=local.locale)
开发者ID:aristidb,项目名称:cppbash,代码行数:13,代码来源:__init__.py
注:本文中的babel.numbers.format_number函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论