当前位置: 首页>>代码示例>>Python>>正文


Python dateformat.format方法代码示例

本文整理汇总了Python中django.utils.dateformat.format方法的典型用法代码示例。如果您正苦于以下问题:Python dateformat.format方法的具体用法?Python dateformat.format怎么用?Python dateformat.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.dateformat的用法示例。


在下文中一共展示了dateformat.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: localize

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def localize(value, use_l10n=None):
    """
    Checks if value is a localizable type (date, number...) and returns it
    formatted as a string using current locale format.

    If use_l10n is provided and is not None, that will force the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    if isinstance(value, bool):
        return mark_safe(six.text_type(value))
    elif isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.datetime):
        return date_format(value, 'DATETIME_FORMAT', use_l10n=use_l10n)
    elif isinstance(value, datetime.date):
        return date_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.time):
        return time_format(value, 'TIME_FORMAT', use_l10n=use_l10n)
    else:
        return value 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:formats.py

示例2: localize_input

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def localize_input(value, default=None):
    """
    Checks if an input value is a localizable type and returns it
    formatted with the appropriate formatting string of the current locale.
    """
    if isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value)
    elif isinstance(value, datetime.datetime):
        value = datetime_safe.new_datetime(value)
        format = force_str(default or get_format('DATETIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.date):
        value = datetime_safe.new_date(value)
        format = force_str(default or get_format('DATE_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.time):
        format = force_str(default or get_format('TIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    return value 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:21,代码来源:formats.py

示例3: iter_format_modules

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def iter_format_modules(lang, format_module_path=None):
    """Find format modules."""
    if not check_for_language(lang):
        return

    if format_module_path is None:
        format_module_path = settings.FORMAT_MODULE_PATH

    format_locations = []
    if format_module_path:
        if isinstance(format_module_path, str):
            format_module_path = [format_module_path]
        for path in format_module_path:
            format_locations.append(path + '.%s')
    format_locations.append('django.conf.locale.%s')
    locale = to_locale(lang)
    locales = [locale]
    if '_' in locale:
        locales.append(locale.split('_')[0])
    for location in format_locations:
        for loc in locales:
            try:
                yield import_module('%s.formats' % (location % loc))
            except ImportError:
                pass 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:27,代码来源:formats.py

示例4: localize

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def localize(value, use_l10n=None):
    """
    Check if value is a localizable type (date, number...) and return it
    formatted as a string using current locale format.

    If use_l10n is provided and is not None, it forces the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    if isinstance(value, str):  # Handle strings first for performance reasons.
        return value
    elif isinstance(value, bool):  # Make sure booleans don't get treated as numbers
        return str(value)
    elif isinstance(value, (decimal.Decimal, float, int)):
        return number_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.datetime):
        return date_format(value, 'DATETIME_FORMAT', use_l10n=use_l10n)
    elif isinstance(value, datetime.date):
        return date_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.time):
        return time_format(value, 'TIME_FORMAT', use_l10n=use_l10n)
    return value 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:23,代码来源:formats.py

示例5: localize_input

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def localize_input(value, default=None):
    """
    Check if an input value is a localizable type and return it
    formatted with the appropriate formatting string of the current locale.
    """
    if isinstance(value, str):  # Handle strings first for performance reasons.
        return value
    elif isinstance(value, bool):  # Don't treat booleans as numbers.
        return str(value)
    elif isinstance(value, (decimal.Decimal, float, int)):
        return number_format(value)
    elif isinstance(value, datetime.datetime):
        value = datetime_safe.new_datetime(value)
        format = default or get_format('DATETIME_INPUT_FORMATS')[0]
        return value.strftime(format)
    elif isinstance(value, datetime.date):
        value = datetime_safe.new_date(value)
        format = default or get_format('DATE_INPUT_FORMATS')[0]
        return value.strftime(format)
    elif isinstance(value, datetime.time):
        format = default or get_format('TIME_INPUT_FORMATS')[0]
        return value.strftime(format)
    return value 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:25,代码来源:formats.py

示例6: localize

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def localize(value, use_l10n=None):
    """
    Checks if value is a localizable type (date, number...) and returns it
    formatted as a string using current locale format.

    If use_l10n is provided and is not None, that will force the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    if isinstance(value, six.string_types):  # Handle strings first for performance reasons.
        return value
    elif isinstance(value, bool):  # Make sure booleans don't get treated as numbers
        return mark_safe(six.text_type(value))
    elif isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.datetime):
        return date_format(value, 'DATETIME_FORMAT', use_l10n=use_l10n)
    elif isinstance(value, datetime.date):
        return date_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.time):
        return time_format(value, 'TIME_FORMAT', use_l10n=use_l10n)
    return value 
开发者ID:Yeah-Kun,项目名称:python,代码行数:23,代码来源:formats.py

示例7: localize_input

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def localize_input(value, default=None):
    """
    Checks if an input value is a localizable type and returns it
    formatted with the appropriate formatting string of the current locale.
    """
    if isinstance(value, six.string_types):  # Handle strings first for performance reasons.
        return value
    elif isinstance(value, bool):  # Don't treat booleans as numbers.
        return six.text_type(value)
    elif isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value)
    elif isinstance(value, datetime.datetime):
        value = datetime_safe.new_datetime(value)
        format = force_str(default or get_format('DATETIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.date):
        value = datetime_safe.new_date(value)
        format = force_str(default or get_format('DATE_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.time):
        format = force_str(default or get_format('TIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    return value 
开发者ID:Yeah-Kun,项目名称:python,代码行数:25,代码来源:formats.py

示例8: test_templates_course_detail_organization_main_logo

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def test_templates_course_detail_organization_main_logo(self):
        """The main organization logo should be present on the page with a link."""
        user = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=user.username, password="password")

        organizations = OrganizationFactory.create_batch(
            2, fill_logo=True, should_publish=True
        )
        course = CourseFactory(fill_organizations=organizations)

        response = self.client.get(course.extended_object.get_absolute_url())

        self.assertEqual(response.status_code, 200)
        pattern = (
            r'<a href="{url:s}" title="{title:s}" class="subheader__cartouche">'
            r'<div class="subheader__media">'
            r'<img src="/media/filer_public_thumbnails/filer_public/.*logo\.jpg__200x113'
        ).format(
            url=organizations[0].extended_object.get_absolute_url(),
            title=organizations[0].extended_object.get_title(),
        )
        self.assertIsNotNone(re.search(pattern, str(response.content))) 
开发者ID:openfun,项目名称:richie,代码行数:24,代码来源:test_templates_course_detail.py

示例9: test_templates_course_detail_runs_future_not_yet_open

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def test_templates_course_detail_runs_future_not_yet_open(self):
        """
        Priority 2: a future not yet open course run should show in a separate section.
        """
        course = CourseFactory(page_title="my course", should_publish=True)
        course_run = self.create_run_future_not_yet_open(course)

        url = course.extended_object.get_absolute_url()
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, "No open course runs")
        self.assertContains(
            response, '<h3 class="course-detail__title">Upcoming</h3>', html=True,
        )
        self.assertContains(
            response,
            '<ul class="course-detail__run-list">'
            '<li><a href="/en/my-course/my-course-run/">'
            "My course run, from {:s} to {:s}</a></li></ul>".format(
                dateformat.format(course_run.start, "N j, Y"),
                dateformat.format(course_run.end, "N j, Y"),
            ),
            html=True,
        ) 
开发者ID:openfun,项目名称:richie,代码行数:27,代码来源:test_templates_course_detail.py

示例10: test_templates_course_detail_runs_future_closed

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def test_templates_course_detail_runs_future_closed(self):
        """
        Priority 3: a future and closed course run should show in a separate section.
        """
        course = CourseFactory(page_title="my course", should_publish=True)
        course_run = self.create_run_future_closed(course)

        url = course.extended_object.get_absolute_url()
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, "No open course runs")
        self.assertContains(
            response, '<h3 class="course-detail__title">Ongoing</h3>', html=True,
        )
        self.assertContains(
            response,
            '<ul class="course-detail__run-list">'
            '<li><a href="/en/my-course/my-course-run/">'
            "My course run, from {:s} to {:s}</a></li></ul>".format(
                dateformat.format(course_run.start, "N j, Y"),
                dateformat.format(course_run.end, "N j, Y"),
            ),
            html=True,
        ) 
开发者ID:openfun,项目名称:richie,代码行数:27,代码来源:test_templates_course_detail.py

示例11: test_templates_course_detail_runs_ongoing_closed

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def test_templates_course_detail_runs_ongoing_closed(self):
        """
        Priority 4: an ongoing and closed course run should show in a separate section.
        """
        course = CourseFactory(page_title="my course", should_publish=True)
        course_run = self.create_run_ongoing_closed(course)

        url = course.extended_object.get_absolute_url()
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, "No open course runs")
        self.assertContains(
            response, '<h3 class="course-detail__title">Ongoing</h3>', html=True,
        )
        self.assertContains(
            response,
            '<ul class="course-detail__run-list">'
            '<li><a href="/en/my-course/my-course-run/">'
            "My course run, from {:s} to {:s}</a></li></ul>".format(
                dateformat.format(course_run.start, "N j, Y"),
                dateformat.format(course_run.end, "N j, Y"),
            ),
            html=True,
        ) 
开发者ID:openfun,项目名称:richie,代码行数:27,代码来源:test_templates_course_detail.py

示例12: iter_format_modules

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def iter_format_modules(lang):
    """
    Does the heavy lifting of finding format modules.
    """
    if check_for_language(lang):
        format_locations = ['django.conf.locale.%s']
        if settings.FORMAT_MODULE_PATH:
            format_locations.append(settings.FORMAT_MODULE_PATH + '.%s')
            format_locations.reverse()
        locale = to_locale(lang)
        locales = [locale]
        if '_' in locale:
            locales.append(locale.split('_')[0])
        for location in format_locations:
            for loc in locales:
                try:
                    yield import_module('.formats', location % loc)
                except ImportError:
                    pass 
开发者ID:blackye,项目名称:luscan-devel,代码行数:21,代码来源:formats.py

示例13: is_valid_course

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def is_valid_course(self):

        if settings.LMS_COURSE_VALIDATION_BASE_URL:
            uri = '{0}/{1}/info'.format(settings.LMS_COURSE_VALIDATION_BASE_URL, self.course_id)

            try:
                response = requests.get(uri, timeout=settings.LMS_DEFAULT_TIMEOUT)
            except requests.exceptions.Timeout:
                logger.error('Course validation timed out: %s', uri)
                # consider the course valid if the LMS times out
                return True

            # pylint: disable=no-member
            return response.status_code == requests.codes.ok
        # all courses valid if LMS url isn't specified
        return True 
开发者ID:edx,项目名称:edx-analytics-dashboard,代码行数:18,代码来源:__init__.py

示例14: iter_format_modules

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def iter_format_modules(lang, format_module_path=None):
    """
    Does the heavy lifting of finding format modules.
    """
    if not check_for_language(lang):
        return

    if format_module_path is None:
        format_module_path = settings.FORMAT_MODULE_PATH

    format_locations = []
    if format_module_path:
        if isinstance(format_module_path, six.string_types):
            format_module_path = [format_module_path]
        for path in format_module_path:
            format_locations.append(path + '.%s')
    format_locations.append('django.conf.locale.%s')
    locale = to_locale(lang)
    locales = [locale]
    if '_' in locale:
        locales.append(locale.split('_')[0])
    for location in format_locations:
        for loc in locales:
            try:
                yield import_module('%s.formats' % (location % loc))
            except ImportError:
                pass 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:29,代码来源:formats.py

示例15: get_format_modules

# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import format [as 别名]
def get_format_modules(lang=None, reverse=False):
    """
    Returns a list of the format modules found
    """
    if lang is None:
        lang = get_language()
    modules = _format_modules_cache.setdefault(lang, list(iter_format_modules(lang, settings.FORMAT_MODULE_PATH)))
    if reverse:
        return list(reversed(modules))
    return modules 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:formats.py


注:本文中的django.utils.dateformat.format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。