當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。