本文整理汇总了Python中django.utils.formats.get_format_modules方法的典型用法代码示例。如果您正苦于以下问题:Python formats.get_format_modules方法的具体用法?Python formats.get_format_modules怎么用?Python formats.get_format_modules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.formats
的用法示例。
在下文中一共展示了formats.get_format_modules方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_formats
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import get_format_modules [as 别名]
def get_formats():
"""
Returns all formats strings required for i18n to work
"""
FORMAT_SETTINGS = (
'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
'THOUSAND_SEPARATOR', 'NUMBER_GROUPING',
'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'
)
result = {}
for module in [settings] + get_format_modules(reverse=True):
for attr in FORMAT_SETTINGS:
result[attr] = get_format(attr)
formats = {}
for k, v in result.items():
if isinstance(v, (six.string_types, int)):
formats[k] = smart_text(v)
elif isinstance(v, (tuple, list)):
formats[k] = [smart_text(value) for value in v]
return formats
示例2: get_formats
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import get_format_modules [as 别名]
def get_formats():
"""
Returns all formats strings required for i18n to work
"""
FORMAT_SETTINGS = (
'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
'THOUSAND_SEPARATOR', 'NUMBER_GROUPING',
'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'
)
result = {}
for module in [settings] + get_format_modules(reverse=True):
for attr in FORMAT_SETTINGS:
result[attr] = get_format(attr)
src = []
for k, v in result.items():
if isinstance(v, (six.string_types, int)):
src.append("formats['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(smart_text(v))))
elif isinstance(v, (tuple, list)):
v = [javascript_quote(smart_text(value)) for value in v]
src.append("formats['%s'] = ['%s'];\n" % (javascript_quote(k), "', '".join(v)))
return ''.join(src)
示例3: get_formats
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import get_format_modules [as 别名]
def get_formats():
"""
Returns all formats strings required for i18n to work
"""
FORMAT_SETTINGS = (
"DATE_FORMAT",
"DATETIME_FORMAT",
"TIME_FORMAT",
"YEAR_MONTH_FORMAT",
"MONTH_DAY_FORMAT",
"SHORT_DATE_FORMAT",
"SHORT_DATETIME_FORMAT",
"FIRST_DAY_OF_WEEK",
"DECIMAL_SEPARATOR",
"THOUSAND_SEPARATOR",
"NUMBER_GROUPING",
"DATE_INPUT_FORMATS",
"TIME_INPUT_FORMATS",
"DATETIME_INPUT_FORMATS",
)
result = {}
for module in [settings] + get_format_modules(reverse=True):
for attr in FORMAT_SETTINGS:
result[attr] = get_format(attr)
formats = {}
for k, v in list(result.items()):
if isinstance(v, (six.string_types, int)):
formats[k] = smart_text(v)
elif isinstance(v, (tuple, list)):
formats[k] = [smart_text(value) for value in v]
return formats
示例4: _add12hrFormats
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import get_format_modules [as 别名]
def _add12hrFormats():
# Time12hrInput will not work unless django.forms.fields.TimeField
# can process 12hr times, so sneak them into the default and all the
# selectable locales that define TIME_INPUT_FORMATS.
# strptime does not accept %P, %p is for both cases here.
_12hrFormats = ['%I:%M%p', # 2:30pm
'%I%p'] # 7am
# TIME_INPUT_FORMATS is defined in django.conf.global_settings if not
# by the user's local settings.
if (_12hrFormats[0] not in settings.TIME_INPUT_FORMATS or
_12hrFormats[1] not in settings.TIME_INPUT_FORMATS):
settings.TIME_INPUT_FORMATS += _12hrFormats
# Many of the built-in locales define TIME_INPUT_FORMATS
langCodes = [language[0] for language in get_available_admin_languages()]
langCodes.append(settings.LANGUAGE_CODE)
for lang in langCodes:
for module in get_format_modules(lang):
inputFormats = getattr(module, 'TIME_INPUT_FORMATS', None)
if (inputFormats is not None and
(_12hrFormats[0] not in inputFormats or
_12hrFormats[1] not in inputFormats)):
inputFormats += _12hrFormats
# ------------------------------------------------------------------------------