Python django.forms.DurationField() Examples

The following are 30 code examples for showing how to use django.forms.DurationField(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.forms , or try the search function .

Example 1
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_internal_type(self):
        return "DurationField" 
Example 2
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_db_converters(self, connection):
        converters = []
        if not connection.features.has_native_duration_field:
            converters.append(connection.ops.convert_durationfield_value)
        return converters + super(DurationField, self).get_db_converters(connection) 
Example 3
Project: GTDWeb   Author: lanbing510   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.DurationField,
        }
        defaults.update(kwargs)
        return super(DurationField, self).formfield(**defaults) 
Example 4
Project: bioforum   Author: reBiocoder   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "DurationField" 
Example 5
Project: bioforum   Author: reBiocoder   File: __init__.py    License: MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.DurationField,
        }
        defaults.update(kwargs)
        return super().formfield(**defaults) 
Example 6
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "DurationField" 
Example 7
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: __init__.py    License: MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        return super().formfield(**{
            'form_class': forms.DurationField,
            **kwargs,
        }) 
Example 8
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def get_internal_type(self):
        return "DurationField" 
Example 9
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def get_db_converters(self, connection):
        converters = []
        if not connection.features.has_native_duration_field:
            converters.append(connection.ops.convert_durationfield_value)
        return converters + super(DurationField, self).get_db_converters(connection) 
Example 10
Project: python   Author: Yeah-Kun   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.DurationField,
        }
        defaults.update(kwargs)
        return super(DurationField, self).formfield(**defaults) 
Example 11
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def get_internal_type(self):
        return "DurationField" 
Example 12
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def get_db_converters(self, connection):
        converters = []
        if not connection.features.has_native_duration_field:
            converters.append(connection.ops.convert_durationfield_value)
        return converters + super(DurationField, self).get_db_converters(connection) 
Example 13
Project: openhgsenti   Author: drexly   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.DurationField,
        }
        defaults.update(kwargs)
        return super(DurationField, self).formfield(**defaults) 
Example 14
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_internal_type(self):
        return "DurationField" 
Example 15
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def get_db_converters(self, connection):
        converters = []
        if not connection.features.has_native_duration_field:
            converters.append(connection.ops.convert_durationfield_value)
        return converters + super(DurationField, self).get_db_converters(connection) 
Example 16
Project: python2017   Author: bpgc-cte   File: __init__.py    License: MIT License 5 votes vote down vote up
def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.DurationField,
        }
        defaults.update(kwargs)
        return super(DurationField, self).formfield(**defaults) 
Example 17
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_durationfield_clean(self):
        f = DurationField()
        self.assertEqual(datetime.timedelta(seconds=30), f.clean('30'))
        self.assertEqual(datetime.timedelta(minutes=15, seconds=30), f.clean('15:30'))
        self.assertEqual(datetime.timedelta(hours=1, minutes=15, seconds=30), f.clean('1:15:30'))
        self.assertEqual(
            datetime.timedelta(days=1, hours=1, minutes=15, seconds=30, milliseconds=300),
            f.clean('1 1:15:30.3')
        ) 
Example 18
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_overflow(self):
        msg = "The number of days must be between {min_days} and {max_days}.".format(
            min_days=datetime.timedelta.min.days,
            max_days=datetime.timedelta.max.days,
        )
        f = DurationField()
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean('1000000000 00:00:00')
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean('-1000000000 00:00:00') 
Example 19
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_overflow_translation(self):
        msg = "Le nombre de jours doit ĂȘtre entre {min_days} et {max_days}.".format(
            min_days=datetime.timedelta.min.days,
            max_days=datetime.timedelta.max.days,
        )
        with translation.override('fr'):
            with self.assertRaisesMessage(ValidationError, msg):
                DurationField().clean('1000000000 00:00:00') 
Example 20
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_durationfield_render(self):
        self.assertWidgetRendersTo(
            DurationField(initial=datetime.timedelta(hours=1)),
            '<input id="id_f" type="text" name="f" value="01:00:00" required>',
        ) 
Example 21
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_durationfield_integer_value(self):
        f = DurationField()
        self.assertEqual(datetime.timedelta(0, 10800), f.clean(10800)) 
Example 22
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_invalid_string(self):
        field = models.DurationField()
        with self.assertRaises(exceptions.ValidationError) as cm:
            field.clean('not a datetime', None)
        self.assertEqual(cm.exception.code, 'invalid')
        self.assertEqual(
            cm.exception.message % cm.exception.params,
            "'not a datetime' value has an invalid format. "
            "It must be in [DD] [HH:[MM:]]ss[.uuuuuu] format."
        ) 
Example 23
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_formfield(self):
        field = models.DurationField()
        self.assertIsInstance(field.formfield(), forms.DurationField) 
Example 24
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_durationfield_clean(self):
        f = DurationField()
        self.assertEqual(datetime.timedelta(seconds=30), f.clean('30'))
        self.assertEqual(datetime.timedelta(minutes=15, seconds=30), f.clean('15:30'))
        self.assertEqual(datetime.timedelta(hours=1, minutes=15, seconds=30), f.clean('1:15:30'))
        self.assertEqual(
            datetime.timedelta(days=1, hours=1, minutes=15, seconds=30, milliseconds=300),
            f.clean('1 1:15:30.3')
        ) 
Example 25
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_overflow(self):
        msg = "The number of days must be between {min_days} and {max_days}.".format(
            min_days=datetime.timedelta.min.days,
            max_days=datetime.timedelta.max.days,
        )
        f = DurationField()
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean('1000000000 00:00:00')
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean('-1000000000 00:00:00') 
Example 26
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_overflow_translation(self):
        msg = "Le nombre de jours doit ĂȘtre entre {min_days} et {max_days}.".format(
            min_days=datetime.timedelta.min.days,
            max_days=datetime.timedelta.max.days,
        )
        with translation.override('fr'):
            with self.assertRaisesMessage(ValidationError, msg):
                DurationField().clean('1000000000 00:00:00') 
Example 27
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_durationfield_integer_value(self):
        f = DurationField()
        self.assertEqual(datetime.timedelta(0, 10800), f.clean(10800)) 
Example 28
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_durationfield_prepare_value(self):
        field = DurationField()
        td = datetime.timedelta(minutes=15, seconds=30)
        self.assertEqual(field.prepare_value(td), duration_string(td))
        self.assertEqual(field.prepare_value('arbitrary'), 'arbitrary')
        self.assertIsNone(field.prepare_value(None)) 
Example 29
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_invalid_string(self):
        field = models.DurationField()
        with self.assertRaises(exceptions.ValidationError) as cm:
            field.clean('not a datetime', None)
        self.assertEqual(cm.exception.code, 'invalid')
        self.assertEqual(
            cm.exception.message % cm.exception.params,
            "'not a datetime' value has an invalid format. "
            "It must be in [DD] [HH:[MM:]]ss[.uuuuuu] format."
        ) 
Example 30
Project: djongo   Author: nesdis   File: test_durationfield.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_formfield(self):
        field = models.DurationField()
        self.assertIsInstance(field.formfield(), forms.DurationField)