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
24cae0be
Kaydet (Commit)
24cae0be
authored
Eki 17, 2018
tarafından
buzzi
Kaydeden (comit)
Tim Graham
Eki 22, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29860 -- Allowed BaseValidator to accept a callable limit_value.
üst
5e3463f6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
7 deletions
+34
-7
validators.py
django/core/validators.py
+3
-2
validators.txt
docs/ref/validators.txt
+24
-4
2.2.txt
docs/releases/2.2.txt
+3
-1
tests.py
tests/validators/tests.py
+4
-0
No files found.
django/core/validators.py
Dosyayı görüntüle @
24cae0be
...
@@ -317,8 +317,9 @@ class BaseValidator:
...
@@ -317,8 +317,9 @@ class BaseValidator:
def
__call__
(
self
,
value
):
def
__call__
(
self
,
value
):
cleaned
=
self
.
clean
(
value
)
cleaned
=
self
.
clean
(
value
)
params
=
{
'limit_value'
:
self
.
limit_value
,
'show_value'
:
cleaned
,
'value'
:
value
}
limit_value
=
self
.
limit_value
()
if
callable
(
self
.
limit_value
)
else
self
.
limit_value
if
self
.
compare
(
cleaned
,
self
.
limit_value
):
params
=
{
'limit_value'
:
limit_value
,
'show_value'
:
cleaned
,
'value'
:
value
}
if
self
.
compare
(
cleaned
,
limit_value
):
raise
ValidationError
(
self
.
message
,
code
=
self
.
code
,
params
=
params
)
raise
ValidationError
(
self
.
message
,
code
=
self
.
code
,
params
=
params
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
...
...
docs/ref/validators.txt
Dosyayı görüntüle @
24cae0be
...
@@ -236,7 +236,12 @@ to, or in lieu of custom ``field.clean()`` methods.
...
@@ -236,7 +236,12 @@ to, or in lieu of custom ``field.clean()`` methods.
.. class:: MaxValueValidator(limit_value, message=None)
.. class:: MaxValueValidator(limit_value, message=None)
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
``'max_value'`` if ``value`` is greater than ``limit_value``.
``'max_value'`` if ``value`` is greater than ``limit_value``, which may be
a callable.
.. versionchanged:: 2.2
``limit_value`` can now be a callable.
``MinValueValidator``
``MinValueValidator``
---------------------
---------------------
...
@@ -244,7 +249,12 @@ to, or in lieu of custom ``field.clean()`` methods.
...
@@ -244,7 +249,12 @@ to, or in lieu of custom ``field.clean()`` methods.
.. class:: MinValueValidator(limit_value, message=None)
.. class:: MinValueValidator(limit_value, message=None)
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
``'min_value'`` if ``value`` is less than ``limit_value``.
``'min_value'`` if ``value`` is less than ``limit_value``, which may be a
callable.
.. versionchanged:: 2.2
``limit_value`` can now be a callable.
``MaxLengthValidator``
``MaxLengthValidator``
----------------------
----------------------
...
@@ -252,7 +262,12 @@ to, or in lieu of custom ``field.clean()`` methods.
...
@@ -252,7 +262,12 @@ to, or in lieu of custom ``field.clean()`` methods.
.. class:: MaxLengthValidator(limit_value, message=None)
.. class:: MaxLengthValidator(limit_value, message=None)
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
``'max_length'`` if the length of ``value`` is greater than ``limit_value``.
``'max_length'`` if the length of ``value`` is greater than
``limit_value``, which may be a callable.
.. versionchanged:: 2.2
``limit_value`` can now be a callable.
``MinLengthValidator``
``MinLengthValidator``
----------------------
----------------------
...
@@ -260,7 +275,12 @@ to, or in lieu of custom ``field.clean()`` methods.
...
@@ -260,7 +275,12 @@ to, or in lieu of custom ``field.clean()`` methods.
.. class:: MinLengthValidator(limit_value, message=None)
.. class:: MinLengthValidator(limit_value, message=None)
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
Raises a :exc:`~django.core.exceptions.ValidationError` with a code of
``'min_length'`` if the length of ``value`` is less than ``limit_value``.
``'min_length'`` if the length of ``value`` is less than ``limit_value``,
which may be a callable.
.. versionchanged:: 2.2
``limit_value`` can now be a callable.
``DecimalValidator``
``DecimalValidator``
--------------------
--------------------
...
...
docs/releases/2.2.txt
Dosyayı görüntüle @
24cae0be
...
@@ -259,7 +259,9 @@ URLs
...
@@ -259,7 +259,9 @@ URLs
Validators
Validators
~~~~~~~~~~
~~~~~~~~~~
* ...
* :class:`.MaxValueValidator`, :class:`.MinValueValidator`,
:class:`.MinLengthValidator`, and :class:`.MaxLengthValidator` now accept
a callable ``limit_value``.
.. _backwards-incompatible-2.2:
.. _backwards-incompatible-2.2:
...
...
tests/validators/tests.py
Dosyayı görüntüle @
24cae0be
...
@@ -203,6 +203,10 @@ TEST_DATA = [
...
@@ -203,6 +203,10 @@ TEST_DATA = [
(
MinValueValidator
(
0
),
-
1
,
ValidationError
),
(
MinValueValidator
(
0
),
-
1
,
ValidationError
),
(
MinValueValidator
(
NOW
),
NOW
-
timedelta
(
days
=
1
),
ValidationError
),
(
MinValueValidator
(
NOW
),
NOW
-
timedelta
(
days
=
1
),
ValidationError
),
# limit_value may be a callable.
(
MinValueValidator
(
lambda
:
1
),
0
,
ValidationError
),
(
MinValueValidator
(
lambda
:
1
),
1
,
None
),
(
MaxLengthValidator
(
10
),
''
,
None
),
(
MaxLengthValidator
(
10
),
''
,
None
),
(
MaxLengthValidator
(
10
),
10
*
'x'
,
None
),
(
MaxLengthValidator
(
10
),
10
*
'x'
,
None
),
...
...
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