class TimeField

from django.forms import TimeField

Ancestors (MRO)

  1. TimeField
  2. BaseTemporalField
  3. Field

Attributes

  Defined in
creation_counter = 0 Field
default_error_messages = {'invalid': <django.utils.functional.lazy.<locals>.__proxy__ object at 0x10cfe08d0>} TimeField
default_error_messages = {'required': <django.utils.functional.lazy.<locals>.__proxy__ object at 0x10cf3ceb8>} Field
default_validators = [] Field
empty_values = [None, '', [], (), {}] Field
input_formats = <django.utils.functional.lazy.<locals>.__proxy__ object at 0x10cfe0828> TimeField
Expand Collapse

Methods

def _has_changed(*args, **kwargs): Field

        def wrapped(*args, **kwargs):
            warnings.warn(
                "`%s.%s` is deprecated, use `%s` instead." %
                (self.class_name, self.old_method_name, self.new_method_name),
                self.deprecation_warning, 2)
            return f(*args, **kwargs)

def bound_data(self, data, initial): Field

        Return the value that should be shown for this field on render of a
        bound form, given the submitted POST data for the field and the initial
        data, if any.

        For most fields, this will simply be data; FileFields need to handle it
        a bit differently.
        
    def bound_data(self, data, initial):
        """
        Return the value that should be shown for this field on render of a
        bound form, given the submitted POST data for the field and the initial
        data, if any.

        For most fields, this will simply be data; FileFields need to handle it
        a bit differently.
        """
        return data

def clean(self, value): Field

        Validates the given value and returns its "cleaned" value as an
        appropriate Python object.

        Raises ValidationError for any errors.
        
    def clean(self, value):
        """
        Validates the given value and returns its "cleaned" value as an
        appropriate Python object.

        Raises ValidationError for any errors.
        """
        value = self.to_python(value)
        self.validate(value)
        self.run_validators(value)
        return value

def has_changed(self, initial, data): Field

        Return True if data differs from initial.
        
    def has_changed(self, initial, data):
        """
        Return True if data differs from initial.
        """
        # For purposes of seeing whether something has changed, None is
        # the same as an empty string, if the data or initial value we get
        # is None, replace it w/ ''.
        initial_value = initial if initial is not None else ''
        try:
            data = self.to_python(data)
            if hasattr(self, '_coerce'):
                data = self._coerce(data)
        except ValidationError:
            return True
        data_value = data if data is not None else ''
        return initial_value != data_value

def prepare_value(self, value): Field

    def prepare_value(self, value):
        return value

def run_validators(self, value): Field

    def run_validators(self, value):
        if value in self.empty_values:
            return
        errors = []
        for v in self.validators:
            try:
                v(value)
            except ValidationError as e:
                if hasattr(e, 'code') and e.code in self.error_messages:
                    e.message = self.error_messages[e.code]
                errors.extend(e.error_list)
        if errors:
            raise ValidationError(errors)

def strptime(self, value, format):

TimeField

    def strptime(self, value, format):
        return datetime.datetime.strptime(force_str(value), format).time()

BaseTemporalField

    def strptime(self, value, format):
        raise NotImplementedError('Subclasses must define this method.')

def to_python(self, value):

TimeField

        Validates that the input can be converted to a time. Returns a Python
        datetime.time object.
        
    def to_python(self, value):
        """
        Validates that the input can be converted to a time. Returns a Python
        datetime.time object.
        """
        if value in self.empty_values:
            return None
        if isinstance(value, datetime.time):
            return value
        return super(TimeField, self).to_python(value)

BaseTemporalField

    def to_python(self, value):
        # Try to coerce the value to unicode.
        unicode_value = force_text(value, strings_only=True)
        if isinstance(unicode_value, six.text_type):
            value = unicode_value.strip()
        # If unicode, try to strptime against each input format.
        if isinstance(value, six.text_type):
            for format in self.input_formats:
                try:
                    return self.strptime(value, format)
                except (ValueError, TypeError):
                    continue
        raise ValidationError(self.error_messages['invalid'], code='invalid')

Field

    def to_python(self, value):
        return value

def validate(self, value): Field

    def validate(self, value):
        if value in self.empty_values and self.required:
            raise ValidationError(self.error_messages['required'], code='required')

def widget_attrs(self, widget): Field

        Given a Widget instance (*not* a Widget class), returns a dictionary of
        any HTML attributes that should be added to the Widget, based on this
        Field.
        
    def widget_attrs(self, widget):
        """
        Given a Widget instance (*not* a Widget class), returns a dictionary of
        any HTML attributes that should be added to the Widget, based on this
        Field.
        """
        return {}