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