本文整理汇总了Python中babel.dates.format_date函数的典型用法代码示例。如果您正苦于以下问题:Python format_date函数的具体用法?Python format_date怎么用?Python format_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format_date函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_format_date
def test_format_date():
d = date(2007, 4, 1)
assert dates.format_date(d, locale='en_US') == u'Apr 1, 2007'
assert (dates.format_date(d, format='full', locale='de_DE') ==
u'Sonntag, 1. April 2007')
assert (dates.format_date(d, "EEE, MMM d, ''yy", locale='en') ==
u"Sun, Apr 1, '07")
开发者ID:python-babel,项目名称:babel,代码行数:7,代码来源:test_dates.py
示例2: get_dates
def get_dates(cls, context):
start_date, end_date = context.build_dates
if not start_date or not end_date:
return ''
start_date_str = format_date(start_date, 'd MMMM YYYY', locale='ru')
end_date_str = format_date(end_date, 'd MMMM YYYY', locale='ru')
return u'%s - %s' % (start_date_str, end_date_str)
开发者ID:nextgis,项目名称:nextgisweb_compulink,代码行数:7,代码来源:splash_generator.py
示例3: statistics
def statistics(self):
c.locations = meta.Session.query(Region, func.count(User.id)).filter(LocationTag.region_id == Region.id).filter(User.location_id == LocationTag.id).group_by(Region).all()
c.geo_locations = meta.Session.query(User.location_city, func.count(User.id)).group_by(User.location_city).order_by(desc(func.count(User.id))).all()
# Getting last week date range
locale = c.locale
from_time_str = format_date(date.today() - timedelta(7),
format="short",
locale=locale)
to_time_str = format_date(date.today() + timedelta(1),
format="short",
locale=locale)
from_time = parse_date(from_time_str, locale=locale)
to_time = parse_date(to_time_str, locale=locale)
uploads_stmt = meta.Session.query(
Event.author_id,
func.count(Event.created).label('uploads_count'))\
.filter(Event.event_type == 'file_uploaded')\
.filter(Event.created < to_time)\
.filter(Event.created >= from_time)\
.group_by(Event.author_id).order_by(desc('uploads_count')).limit(10).subquery()
c.active_users = meta.Session.query(User,
uploads_stmt.c.uploads_count.label('uploads'))\
.join((uploads_stmt, uploads_stmt.c.author_id == User.id)).all()
return render('/statistics.mako')
开发者ID:nous-consulting,项目名称:ututi,代码行数:28,代码来源:home.py
示例4: get_dashboard_blocks
def get_dashboard_blocks(self, request):
if not self.check_demo_optin(request):
return
locale = get_current_babel_locale()
n = now()
weekday = format_date(n, "EEEE", locale=locale)
today = format_date(n, locale=locale)
yield DashboardValueBlock(
id="test-x", color="blue", title="Happy %s!" % weekday, value=today, icon="fa fa-calendar"
)
yield DashboardNumberBlock(
id="test-x", color="red", title="Visitors Yesterday", value=random.randint(2200, 10000), icon="fa fa-globe"
)
yield DashboardNumberBlock(id="test-x", color="gray", title="Registered Users", value=1240, icon="fa fa-user")
yield DashboardNumberBlock(id="test-x", color="orange", title="Orders", value=32, icon="fa fa-inbox")
yield DashboardMoneyBlock(
id="test-x", color="green", title="Open Orders Value", value=32000, currency="USD", icon="fa fa-line-chart"
)
yield DashboardNumberBlock(id="test-x", color="yellow", title="Current Visitors", value=6, icon="fa fa-users")
yield DashboardMoneyBlock(
id="test-x", color="none", title="Sales this week", value=430.30, currency="USD", icon="fa fa-dollar"
)
yield DashboardValueBlock(
id="test-1", value="\u03C0", title="The most delicious number", color="purple", icon="fa fa-smile-o"
)
开发者ID:taedori81,项目名称:shoop,代码行数:25,代码来源:__init__.py
示例5: date
def date(datetime, lang):
"""Format a date depending on current locale"""
if lang is None:
lang = settings.LANGUAGE
try:
r = format_date(datetime, locale=lang)
except UnknownLocaleError:
r = format_date(datetime, locale=settings.LANGUAGE)
return r
开发者ID:Boldewyn,项目名称:website,代码行数:9,代码来源:templatedefs.py
示例6: get_bar_graph_datas
def get_bar_graph_datas(self):
data = []
today = datetime.strptime(fields.Date.context_today(self), DF)
data.append({'label': _('Past'), 'value': 0.0, 'type': 'past'})
day_of_week = int(format_datetime(today, 'e', locale=self._context.get(
'lang') or 'en_US'))
first_day_of_week = today + timedelta(days=-day_of_week + 1)
for i in range(-1, 4):
if i == 0:
label = _('This Week')
elif i == 3:
label = _('Future')
else:
start_week = first_day_of_week + timedelta(days=i * 7)
end_week = start_week + timedelta(days=6)
if start_week.month == end_week.month:
label = \
str(start_week.day) + '-' + str(end_week.day) + ' ' + \
format_date(end_week, 'MMM',
locale=self._context.get(
'lang') or 'en_US')
else:
label = \
format_date(start_week, 'd MMM',
locale=self._context.get('lang') or 'en_US'
) + '-' + format_date(
end_week, 'd MMM',
locale=self._context.get('lang') or 'en_US')
data.append({
'label': label,
'value': 0.0,
'type': 'past' if i < 0 else 'future'})
select_sql_clause = 'SELECT count(*) FROM helpdesk_ticket AS h ' \
'WHERE issue_type_id = %(issue_type_id)s'
query_args = {'issue_type_id': self.id}
query = ''
start_date = (first_day_of_week + timedelta(days=-7))
for i in range(0, 6):
if i == 0:
query += "(" + select_sql_clause + " and start_date < '" + \
start_date.strftime(DF) + "')"
elif i == 5:
query += " UNION ALL (" + select_sql_clause + \
" and start_date >= '" + \
start_date.strftime(DF) + "')"
else:
next_date = start_date + timedelta(days=7)
query += " UNION ALL (" + select_sql_clause + \
" and start_date >= '" + start_date.strftime(DF) + \
"' and end_date < '" + next_date.strftime(DF) + \
"')"
start_date = next_date
self.env.cr.execute(query, query_args)
query_results = self.env.cr.dictfetchall()
for index in range(0, len(query_results)):
if query_results[index]:
data[index]['value'] = query_results[index].get('count')
return [{'values': data}]
开发者ID:niceboat000,项目名称:Odoo11,代码行数:60,代码来源:issue_type.py
示例7: POST_update_pay
def POST_update_pay(self, form, jquery, link, campaign, customer_id, pay_id,
edit, address, creditcard):
if not g.authorizenetapi:
return
if not link or not campaign or link._id != campaign.link_id:
return abort(404, 'not found')
# Check inventory
if campaign_has_oversold_error(form, campaign):
return
# check that start is not so late that authorization hold will expire
max_start = promote.get_max_startdate()
if campaign.start_date > max_start:
msg = _("please change campaign start date to %(date)s or earlier")
date = format_date(max_start, format="short", locale=c.locale)
msg %= {'date': date}
form.set_html(".status", msg)
return
# check the campaign start date is still valid (user may have created
# the campaign a few days ago)
now = promote.promo_datetime_now()
min_start = now + timedelta(days=g.min_promote_future)
if campaign.start_date.date() < min_start.date():
msg = _("please change campaign start date to %(date)s or later")
date = format_date(min_start, format="short", locale=c.locale)
msg %= {'date': date}
form.set_html(".status", msg)
return
address_modified = not pay_id or edit
if address_modified:
address_fields = ["firstName", "lastName", "company", "address",
"city", "state", "zip", "country", "phoneNumber"]
card_fields = ["cardNumber", "expirationDate", "cardCode"]
if (form.has_errors(address_fields, errors.BAD_ADDRESS) or
form.has_errors(card_fields, errors.BAD_CARD)):
return
pay_id = edit_profile(c.user, address, creditcard, pay_id)
reason = None
if pay_id:
success, reason = promote.auth_campaign(link, campaign, c.user,
pay_id)
if success:
form.redirect(promote.promo_edit_url(link))
return
msg = reason or _("failed to authenticate card. sorry.")
form.set_html(".status", msg)
开发者ID:6r3nt,项目名称:reddit,代码行数:55,代码来源:promotecontroller.py
示例8: test_format_date
def test_format_date(self):
import datetime
from babel.dates import format_date
from babel.core import UnknownLocaleError
api = self.make()
first = datetime.date(2012, 1, 1)
self.assertEqual(api.format_date(first), format_date(first, format="medium", locale="en"))
self.assertEqual(api.format_date(first, format="short"), format_date(first, format="short", locale="en"))
api.locale_name = "unknown"
self.assertRaises(UnknownLocaleError, api.format_date, first)
开发者ID:mujinjun,项目名称:Kotti,代码行数:11,代码来源:test_util_views.py
示例9: get_week_name
def get_week_name(start_date, locale):
""" Generates a week name (string) from a datetime according to the locale:
E.g.: locale start_date (datetime) return string
"en_US" November 16th "16-22 Nov"
"en_US" December 28th "28 Dec-3 Jan"
"""
if (start_date + relativedelta(days=6)).month == start_date.month:
short_name_from = format_date(start_date, 'd', locale=locale)
else:
short_name_from = format_date(start_date, 'd MMM', locale=locale)
short_name_to = format_date(start_date + relativedelta(days=6), 'd MMM', locale=locale)
return short_name_from + '-' + short_name_to
开发者ID:1806933,项目名称:odoo,代码行数:12,代码来源:crm_team.py
示例10: get_bar_graph_datas
def get_bar_graph_datas(self):
data = []
today = fields.Datetime.now(self)
data.append({'label': _('Past'), 'value':0.0, 'type': 'past'})
day_of_week = int(format_datetime(today, 'e', locale=self._context.get('lang') or 'en_US'))
first_day_of_week = today + timedelta(days=-day_of_week+1)
for i in range(-1,4):
if i==0:
label = _('This Week')
elif i==3:
label = _('Future')
else:
start_week = first_day_of_week + timedelta(days=i*7)
end_week = start_week + timedelta(days=6)
if start_week.month == end_week.month:
label = str(start_week.day) + '-' +str(end_week.day)+ ' ' + format_date(end_week, 'MMM', locale=self._context.get('lang') or 'en_US')
else:
label = format_date(start_week, 'd MMM', locale=self._context.get('lang') or 'en_US')+'-'+format_date(end_week, 'd MMM', locale=self._context.get('lang') or 'en_US')
data.append({'label':label,'value':0.0, 'type': 'past' if i<0 else 'future'})
# Build SQL query to find amount aggregated by week
(select_sql_clause, query_args) = self._get_bar_graph_select_query()
query = ''
start_date = (first_day_of_week + timedelta(days=-7))
for i in range(0,6):
if i == 0:
query += "("+select_sql_clause+" and date_due < '"+start_date.strftime(DF)+"')"
elif i == 5:
query += " UNION ALL ("+select_sql_clause+" and date_due >= '"+start_date.strftime(DF)+"')"
else:
next_date = start_date + timedelta(days=7)
query += " UNION ALL ("+select_sql_clause+" and date_due >= '"+start_date.strftime(DF)+"' and date_due < '"+next_date.strftime(DF)+"')"
start_date = next_date
self.env.cr.execute(query, query_args)
query_results = self.env.cr.dictfetchall()
is_sample_data = True
for index in range(0, len(query_results)):
if query_results[index].get('aggr_date') != None:
is_sample_data = False
data[index]['value'] = query_results[index].get('total')
[graph_title, graph_key] = self._graph_title_and_key()
if is_sample_data:
for index in range(0, len(query_results)):
data[index]['type'] = 'o_sample_data'
# we use unrealistic values for the sample data
data[index]['value'] = random.randint(0, 20)
graph_key = _('Sample data')
return [{'values': data, 'title': graph_title, 'key': graph_key, 'is_sample_data': is_sample_data}]
开发者ID:Vauxoo,项目名称:odoo,代码行数:52,代码来源:account_journal_dashboard.py
示例11: _render_report
def _render_report(self, report):
if not report.rendered:
report_data = report.get_data()
self.write_heading(
"{title} {start} - {end}".format(
title=report.title,
start=format_date(report_data["start"], format="short", locale=get_current_babel_locale()),
end=format_date(report_data["end"], format="short", locale=get_current_babel_locale()))
)
report.ensure_texts()
self.write_data_table(report, report_data["data"], has_totals=report_data["has_totals"])
return self.get_rendered_output()
开发者ID:suutari,项目名称:shoop,代码行数:13,代码来源:writer.py
示例12: _parse_file
def _parse_file(self, data_file):
locale = self._context.get("lang", "en_US")
ofx = self.validate_ofx(StringIO.StringIO(data_file))
transactions = []
total_amt = 0.00
for transaction in ofx.account.statement.transactions:
bank_account_id = partner_id = False
partner_bank = self.env["res.partner.bank"].search([("partner_id.name", "=", transaction.payee)], limit=1)
if partner_bank:
bank_account_id = partner_bank.id
partner_id = partner_bank.partner_id.id
vals_line = {
"date": transaction.date,
"name": transaction.payee + (transaction.memo and ": " + transaction.memo or ""),
"ref": u"{}: {}".format(
int(transaction.id) - 1, format_date(transaction.date, "EEEE d", locale=locale)
),
"amount": transaction.amount,
"unique_import_id": "{}-{}".format(
transaction.id, transaction.date.strftime(DEFAULT_SERVER_DATE_FORMAT)
),
"bank_account_id": bank_account_id,
"partner_id": partner_id,
}
total_amt += float(transaction.amount)
transactions.append(vals_line)
dates = [st.date for st in ofx.account.statement.transactions]
min_date = min(dates)
max_date = max(dates)
vals_bank_statement = {
"name": "Del {} al {} de {}".format(
min_date.strftime("%d"), max_date.strftime("%d"), format_date(max_date, "MMMM", locale=locale)
),
"transactions": transactions,
"balance_start": float(ofx.account.statement.balance) - total_amt,
"balance_end_real": ofx.account.statement.balance,
"date": max_date.strftime(DEFAULT_SERVER_DATE_FORMAT),
}
bank_journal_id = self.env["account.journal"].search([("bank_acc_number", "=", ofx.account.number)])
if not bank_journal_id:
raise UserError(u"Debe espesificar el número de la cuenta del banco en el diario!")
bank_import_type = bank_journal_id.bank_id.statement_import_type
currency = ofx.account.statement.currency
if bank_import_type == "bpdofx":
currency = "DOP"
return currency, ofx.account.number, [vals_bank_statement]
开发者ID:MarcosCommunity,项目名称:marcos_community_addons,代码行数:51,代码来源:bank_statement_import.py
示例13: date_picker
def date_picker(start_date, end_date,
in_format='%Y-%m-%d',
out_format='d MMMM yyyy',
locale='en_US'):
dstart = datetime.strptime(start_date, in_format)
if not end_date:
return format_date(dstart, out_format, locale=locale)
else:
dend = datetime.strptime(end_date, in_format)
if dstart.year != dend.year:
# full dates for different years
return '%s-%s' % (format_date(dstart, out_format, locale=locale),
format_date(dend, out_format, locale=locale))
else:
if dstart.month != dend.month:
# same years, different months
return '%s-%s' % (format_date(dstart, 'd MMMM', locale=locale),
format_date(dend, out_format, locale=locale))
else:
if dstart.day != dend.day:
# same year, same month, different days
return '%s-%s' % (format_date(dstart, 'd', locale=locale),
format_date(dend, out_format, locale=locale))
else:
# same date
return format_date(dstart, out_format, locale=locale)
开发者ID:eaudeweb,项目名称:cites-meetings,代码行数:27,代码来源:util.py
示例14: date_processor
def date_processor(date_start, date_end, in_format='%Y-%m-%d',
out_format='d MMMM yyyy', locale='en_US'):
if not date_end:
return format_date(date_start, out_format, locale=locale)
else:
if date_start.year != date_end.year:
# full dates for different years
return '%s-%s' % (
format_date(date_start, out_format, locale=locale),
format_date(date_end, out_format, locale=locale))
else:
if date_start.month != date_end.month:
# same years, different months
return '%s-%s' % (
format_date(date_start, out_format.replace(' yyyy', ''),
locale=locale),
format_date(date_end, out_format, locale=locale))
else:
if date_start.day != date_end.day:
# same year, same month, different days
return '%s-%s' % (
format_date(date_start, 'd', locale=locale),
format_date(date_end, out_format, locale=locale))
else:
# same date
return format_date(date_start, out_format, locale=locale)
开发者ID:razvanch,项目名称:meetings-registration-tool,代码行数:27,代码来源:template.py
示例15: test_format_date
def test_format_date(self, db_session):
import datetime
from babel.dates import format_date
from babel.core import UnknownLocaleError
api = self.make()
first = datetime.date(2012, 1, 1)
assert (
api.format_date(first) ==
format_date(first, format='medium', locale='en'))
assert (
api.format_date(first, fmt='short') ==
format_date(first, format='short', locale='en'))
api.locale_name = 'unknown'
with raises(UnknownLocaleError):
api.format_date(first)
开发者ID:disko,项目名称:Kotti,代码行数:15,代码来源:test_util_views.py
示例16: babel_date
def babel_date(date, format='long'):
"""
Format a date properly for the current locale. Format can be one of
'short', 'medium', 'long', or 'full'.
"""
locale = current_locale()
return format_date(date, format, locale)
开发者ID:Hugochazz,项目名称:affiliates,代码行数:7,代码来源:helpers.py
示例17: l10n_format_date
def l10n_format_date(date, format='long'):
"""
Formats a date according to the current locale. Wraps around
babel.dates.format_date.
"""
locale = current_locale()
return format_date(date, locale=locale, format=format)
开发者ID:Akuaksh,项目名称:bedrock,代码行数:7,代码来源:helpers.py
示例18: format_date_by_locale
def format_date_by_locale(date, locale_string):
# strftime works only on dates after 1900
if date.year <= 1900:
return date.isoformat().split('T')[0]
if locale_string == 'all':
locale_string = settings['ui']['default_locale'] or 'en_US'
# to avoid crashing if locale is not supported by babel
try:
formatted_date = format_date(date, locale=locale_string)
except:
formatted_date = format_date(date, "YYYY-MM-dd")
return formatted_date
开发者ID:mmuman,项目名称:searx,代码行数:16,代码来源:utils.py
示例19: l10n_format_date
def l10n_format_date(ctx, date, format='long'):
"""
Formats a date according to the current locale. Wraps around
babel.dates.format_date.
"""
lang = get_locale(ctx['LANG'])
return format_date(date, locale=lang, format=format)
开发者ID:1234-,项目名称:bedrock,代码行数:7,代码来源:helpers.py
示例20: dates_line
def dates_line(self, date, changed):
""" Adds the given date and timespamp. """
self.table(
[[
format_date(date, format='long', locale=self.locale),
'{}: {} {}'.format(
self.translate(_('Last change')),
format_date(changed, format='long', locale=self.locale),
format_time(changed, format='short', locale=self.locale)
)
]],
'even',
style=self.style.table_dates
)
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:16,代码来源:pdf.py
注:本文中的babel.dates.format_date函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论