Ticket #2443: durationfield.2.diff

File durationfield.2.diff, 1.1 KB (added by Marty Alchin <gulopine@…>, 18 years ago)

Updated DurationField location to actually work (I hadn't tested the other one)

  • __init__.py

     
    688688    def get_manipulator_field_objs(self):
    689689        return [curry(oldforms.FloatField, max_digits=self.max_digits, decimal_places=self.decimal_places)]
    690690
     691class DurationField(FloatField):
     692
     693    def __init__(self, *args, **kwargs):
     694        super(DurationField, self).__init__(max_digits=20, decimal_places=6)
     695 
     696    def get_internal_type(self):
     697        return "FloatField"
     698
     699    def to_python(self, value):
     700        print "to_python: %r" % value
     701        try:
     702            return datetime.timedelta(seconds=value)
     703        except TypeError:
     704            raise validators.ValidationError('This value must be a real number.')
     705        except OverflowError:
     706            raise validators.ValidationError('The maximum allowed value is %s' % datetime.timedelta.max)
     707       
     708
    691709class ImageField(FileField):
    692710    def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs):
    693711        self.width_field, self.height_field = width_field, height_field
Back to Top