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


Python utils.from_current_timezone方法代码示例

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


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

示例1: compress

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import from_current_timezone [as 别名]
def compress(self, data_list):
        """
        On the DateTime widget, we don't want the time to be required, only the date:
        - if the time is not set on a form, we set it to 0:00:00,
        - if only the time is set, we ignore the value.
        """
        if data_list:
            if data_list[0] in self.empty_values:
                # If there is no date, we ignore the time and act as if nothing was submitted
                return None
            if data_list[1] in self.empty_values:
                # If there is a date but no time, we take midnight as default time
                data_list[1] = time(0)
            result = datetime.combine(*data_list)
            return from_current_timezone(result)
        return None 
开发者ID:openfun,项目名称:richie,代码行数:18,代码来源:fields.py

示例2: to_python

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import from_current_timezone [as 别名]
def to_python(self, value):
        """
        Validates that the input can be converted to a datetime. Returns a
        Python datetime.datetime object.
        """
        if value in self.empty_values:
            return None
        if isinstance(value, datetime.datetime):
            return from_current_timezone(value)
        if isinstance(value, datetime.date):
            result = datetime.datetime(value.year, value.month, value.day)
            return from_current_timezone(result)
        if isinstance(value, list):
            # Input comes from a SplitDateTimeWidget, for example. So, it's two
            # components: date and time.
            warnings.warn(
                'Using SplitDateTimeWidget with DateTimeField is deprecated. '
                'Use SplitDateTimeField instead.',
                RemovedInDjango19Warning, stacklevel=2)
            if len(value) != 2:
                raise ValidationError(self.error_messages['invalid'], code='invalid')
            if value[0] in self.empty_values and value[1] in self.empty_values:
                return None
            value = '%s %s' % tuple(value)
        result = super(DateTimeField, self).to_python(value)
        return from_current_timezone(result) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:28,代码来源:fields.py

示例3: compress

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import from_current_timezone [as 别名]
def compress(self, data_list):
        if data_list:
            # Raise a validation error if time or date is empty
            # (possible if SplitDateTimeField has required=False).
            if data_list[0] in self.empty_values:
                raise ValidationError(self.error_messages['invalid_date'], code='invalid_date')
            if data_list[1] in self.empty_values:
                raise ValidationError(self.error_messages['invalid_time'], code='invalid_time')
            result = datetime.datetime.combine(*data_list)
            return from_current_timezone(result)
        return None 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:fields.py

示例4: parse_datetime_value

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import from_current_timezone [as 别名]
def parse_datetime_value(value: Any) -> datetime:
    parsed_value = parse_value(value, datetime_input_formats)
    if not parsed_value:
        raise ValueError(_("Enter a valid date/time."))
    return from_current_timezone(parsed_value) 
开发者ID:mirumee,项目名称:ariadne,代码行数:7,代码来源:scalars.py

示例5: to_python

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import from_current_timezone [as 别名]
def to_python(self, value):
        """
        Validate that the input can be converted to a datetime. Return a
        Python datetime.datetime object.
        """
        if value in self.empty_values:
            return None
        if isinstance(value, datetime.datetime):
            return from_current_timezone(value)
        if isinstance(value, datetime.date):
            result = datetime.datetime(value.year, value.month, value.day)
            return from_current_timezone(result)
        result = super().to_python(value)
        return from_current_timezone(result) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:16,代码来源:fields.py

示例6: to_python

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import from_current_timezone [as 别名]
def to_python(self, value):
        """
        Validates that the input can be converted to a datetime. Returns a
        Python datetime.datetime object.
        """
        if value in self.empty_values:
            return None
        if isinstance(value, datetime.datetime):
            return from_current_timezone(value)
        if isinstance(value, datetime.date):
            result = datetime.datetime(value.year, value.month, value.day)
            return from_current_timezone(result)
        result = super(DateTimeField, self).to_python(value)
        return from_current_timezone(result) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:16,代码来源:fields.py


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