當前位置: 首頁>>代碼示例>>Python>>正文


Python formats.get_format方法代碼示例

本文整理匯總了Python中django.utils.formats.get_format方法的典型用法代碼示例。如果您正苦於以下問題:Python formats.get_format方法的具體用法?Python formats.get_format怎麽用?Python formats.get_format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.utils.formats的用法示例。


在下文中一共展示了formats.get_format方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_formats

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:24,代碼來源:i18n.py

示例2: value_from_datadict

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == "0":
            return None
        if y and m and d:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    return '%s-%s-%s' % (y, m, d)
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            else:
                return '%s-%s-%s' % (y, m, d)
        return data.get(name, None) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:21,代碼來源:widgets.py

示例3: format_value

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def format_value(self, value):
        """
        Return a dict containing the year, month, and day of the current value.
        Use dict instead of a datetime to allow invalid dates such as February
        31 to display correctly.
        """
        year, month, day = None, None, None
        if isinstance(value, (datetime.date, datetime.datetime)):
            year, month, day = value.year, value.month, value.day
        elif isinstance(value, str):
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    d = datetime.datetime.strptime(value, input_format)
                except ValueError:
                    pass
                else:
                    year, month, day = d.year, d.month, d.day
            match = self.date_re.match(value)
            if match:
                year, month, day = [int(val) for val in match.groups()]
        return {'year': year, 'month': month, 'day': day} 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:24,代碼來源:widgets.py

示例4: value_from_datadict

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == "0":
            return None
        if y and m and d:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    return '%s-%s-%s' % (y, m, d)
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            else:
                return '%s-%s-%s' % (y, m, d)
        return data.get(name) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:21,代碼來源:widgets.py

示例5: format_value

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def format_value(self, value):
        """
        Return a dict containing the year, month, and day of the current value.
        Use dict instead of a datetime to allow invalid dates such as February
        31 to display correctly.
        """
        year, month, day = None, None, None
        if isinstance(value, (datetime.date, datetime.datetime)):
            year, month, day = value.year, value.month, value.day
        elif isinstance(value, str):
            match = self.date_re.match(value)
            if match:
                # Convert any zeros in the date to empty strings to match the
                # empty option value.
                year, month, day = [int(val) or '' for val in match.groups()]
            elif settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    d = datetime.datetime.strptime(value, input_format)
                except ValueError:
                    pass
                else:
                    year, month, day = d.year, d.month, d.day
        return {'year': year, 'month': month, 'day': day} 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:26,代碼來源:widgets.py

示例6: value_from_datadict

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == '':
            return None
        if y is not None and m is not None and d is not None:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    pass
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            # Return pseudo-ISO dates with zeros for any unselected values,
            # e.g. '2017-0-23'.
            return '%s-%s-%s' % (y or 0, m or 0, d or 0)
        return data.get(name) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:22,代碼來源:widgets.py

示例7: get_formats

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [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 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] = force_text(v)
        elif isinstance(v, (tuple, list)):
            formats[k] = [force_text(value) for value in v]
    return formats 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:23,代碼來源:i18n.py

示例8: format_value

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def format_value(self, value):
        """
        Return a dict containing the year, month, and day of the current value.
        Use dict instead of a datetime to allow invalid dates such as February
        31 to display correctly.
        """
        year, month, day = None, None, None
        if isinstance(value, (datetime.date, datetime.datetime)):
            year, month, day = value.year, value.month, value.day
        elif isinstance(value, six.string_types):
            if settings.USE_L10N:
                try:
                    input_format = get_format('DATE_INPUT_FORMATS')[0]
                    d = datetime.datetime.strptime(force_str(value), input_format)
                    year, month, day = d.year, d.month, d.day
                except ValueError:
                    pass
            match = self.date_re.match(value)
            if match:
                year, month, day = [int(val) for val in match.groups()]
        return {'year': year, 'month': month, 'day': day} 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:23,代碼來源:widgets.py

示例9: get_formats

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [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) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:25,代碼來源:i18n.py

示例10: _parse_date_fmt

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def _parse_date_fmt():
    fmt = get_format('DATE_FORMAT')
    escaped = False
    output = []
    for char in fmt:
        if escaped:
            escaped = False
        elif char == '\\':
            escaped = True
        elif char in 'Yy':
            output.append('year')
            #if not self.first_select: self.first_select = 'year'
        elif char in 'bEFMmNn':
            output.append('month')
            #if not self.first_select: self.first_select = 'month'
        elif char in 'dj':
            output.append('day')
            #if not self.first_select: self.first_select = 'day'
    return output 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:21,代碼來源:widgets.py

示例11: _format_value

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def _format_value(self, value):
        return formats.localize_input(value,
            self.format or formats.get_format(self.format_key)[0]) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:5,代碼來源:widgets.py

示例12: _parse_date_fmt

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def _parse_date_fmt():
    fmt = get_format('DATE_FORMAT')
    escaped = False
    for char in fmt:
        if escaped:
            escaped = False
        elif char == '\\':
            escaped = True
        elif char in 'Yy':
            yield 'year'
        elif char in 'bEFMmNn':
            yield 'month'
        elif char in 'dj':
            yield 'day' 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:16,代碼來源:widgets.py

示例13: render

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, six.string_types):
                if settings.USE_L10N:
                    try:
                        input_format = get_format('DATE_INPUT_FORMATS')[0]
                        v = datetime.datetime.strptime(force_str(value), input_format)
                        year_val, month_val, day_val = v.year, v.month, v.day
                    except ValueError:
                        pass
                else:
                    match = RE_DATE.match(value)
                    if match:
                        year_val, month_val, day_val = [int(v) for v in match.groups()]
        html = {}
        choices = [(i, i) for i in self.years]
        html['year'] = self.create_select(name, self.year_field, value, year_val, choices, self.year_none_value)
        choices = list(six.iteritems(self.months))
        html['month'] = self.create_select(name, self.month_field, value, month_val, choices, self.month_none_value)
        choices = [(i, i) for i in range(1, 32)]
        html['day'] = self.create_select(name, self.day_field, value, day_val, choices, self.day_none_value)

        output = []
        for field in _parse_date_fmt():
            output.append(html[field])
        return mark_safe('\n'.join(output)) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:31,代碼來源:widgets.py

示例14: get_formats

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def get_formats():
    """Return 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'
    )
    return {attr: get_format(attr) for attr in FORMAT_SETTINGS} 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:12,代碼來源:i18n.py

示例15: _parse_date_fmt

# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import get_format [as 別名]
def _parse_date_fmt():
        fmt = get_format('DATE_FORMAT')
        escaped = False
        for char in fmt:
            if escaped:
                escaped = False
            elif char == '\\':
                escaped = True
            elif char in 'Yy':
                yield 'year'
            elif char in 'bEFMmNn':
                yield 'month'
            elif char in 'dj':
                yield 'day' 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:16,代碼來源:widgets.py


注:本文中的django.utils.formats.get_format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。