Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
55b5393b
Kaydet (Commit)
55b5393b
authored
Agu 08, 2017
tarafından
Srinivas Reddy Thatiparthy
Kaydeden (comit)
Tim Graham
Eki 25, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28474 -- Made DurationField raise ValidationError for inputs that raised OverflowError.
üst
81e357a7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
3 deletions
+26
-3
AUTHORS
AUTHORS
+1
-0
fields.py
django/forms/fields.py
+10
-1
fields.txt
docs/ref/forms/fields.txt
+3
-2
test_durationfield.py
tests/forms_tests/field_tests/test_durationfield.py
+12
-0
No files found.
AUTHORS
Dosyayı görüntüle @
55b5393b
...
...
@@ -740,6 +740,7 @@ answer newbie questions, and generally made Django that much better:
sloonz <simon.lipp@insa-lyon.fr>
smurf@smurf.noris.de
sopel
Srinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com>
Stanislas Guerra <stan@slashdev.me>
Stanislaus Madueke
starrynight <cmorgh@gmail.com>
...
...
django/forms/fields.py
Dosyayı görüntüle @
55b5393b
...
...
@@ -469,6 +469,12 @@ class DateTimeField(BaseTemporalField):
class
DurationField
(
Field
):
default_error_messages
=
{
'invalid'
:
_
(
'Enter a valid duration.'
),
'overflow'
:
_
(
'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
,
)
)
}
def
prepare_value
(
self
,
value
):
...
...
@@ -481,7 +487,10 @@ class DurationField(Field):
return
None
if
isinstance
(
value
,
datetime
.
timedelta
):
return
value
value
=
parse_duration
(
str
(
value
))
try
:
value
=
parse_duration
(
str
(
value
))
except
OverflowError
:
raise
ValidationError
(
self
.
error_messages
[
'overflow'
],
code
=
'overflow'
)
if
value
is
None
:
raise
ValidationError
(
self
.
error_messages
[
'invalid'
],
code
=
'invalid'
)
return
value
...
...
docs/ref/forms/fields.txt
Dosyayı görüntüle @
55b5393b
...
...
@@ -566,8 +566,9 @@ For each field, we describe the default widget used if you don't specify
* Empty value: ``None``
* Normalizes to: A Python :class:`~python:datetime.timedelta`.
* Validates that the given value is a string which can be converted into a
``timedelta``.
* Error message keys: ``required``, ``invalid``.
``timedelta``. The value must be between :attr:`datetime.timedelta.min`
and :attr:`datetime.timedelta.max`.
* Error message keys: ``required``, ``invalid``, ``overflow``.
Accepts any format understood by
:func:`~django.utils.dateparse.parse_duration`.
...
...
tests/forms_tests/field_tests/test_durationfield.py
Dosyayı görüntüle @
55b5393b
import
datetime
from
django.core.exceptions
import
ValidationError
from
django.forms
import
DurationField
from
django.test
import
SimpleTestCase
from
django.utils.duration
import
duration_string
...
...
@@ -19,6 +20,17 @@ class DurationFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f
.
clean
(
'1 1:15:30.3'
)
)
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'
)
def
test_durationfield_render
(
self
):
self
.
assertWidgetRendersTo
(
DurationField
(
initial
=
datetime
.
timedelta
(
hours
=
1
)),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment