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
b102c27f
Kaydet (Commit)
b102c27f
authored
Tem 22, 2013
tarafından
Si Feng
Kaydeden (comit)
Tim Graham
Şub 10, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #20784 -- Added inverse_match parameter to RegexValidator.
üst
0d98422b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
6 deletions
+29
-6
validators.py
django/core/validators.py
+8
-3
validators.txt
docs/ref/validators.txt
+11
-3
1.7.txt
docs/releases/1.7.txt
+6
-0
tests.py
tests/validators/tests.py
+4
-0
No files found.
django/core/validators.py
Dosyayı görüntüle @
b102c27f
...
...
@@ -20,14 +20,17 @@ class RegexValidator(object):
regex
=
''
message
=
_
(
'Enter a valid value.'
)
code
=
'invalid'
inverse_match
=
False
def
__init__
(
self
,
regex
=
None
,
message
=
None
,
code
=
None
):
def
__init__
(
self
,
regex
=
None
,
message
=
None
,
code
=
None
,
inverse_match
=
None
):
if
regex
is
not
None
:
self
.
regex
=
regex
if
message
is
not
None
:
self
.
message
=
message
if
code
is
not
None
:
self
.
code
=
code
if
inverse_match
is
not
None
:
self
.
inverse_match
=
inverse_match
# Compile the regex if it was not passed pre-compiled.
if
isinstance
(
self
.
regex
,
six
.
string_types
):
...
...
@@ -35,9 +38,11 @@ class RegexValidator(object):
def
__call__
(
self
,
value
):
"""
Validates that the input matches the regular expression.
Validates that the input matches the regular expression
if inverse_match is False, otherwise raises ValidationError.
"""
if
not
self
.
regex
.
search
(
force_text
(
value
)):
if
not
(
self
.
inverse_match
is
not
bool
(
self
.
regex
.
search
(
force_text
(
value
)))):
raise
ValidationError
(
self
.
message
,
code
=
self
.
code
)
def
__eq__
(
self
,
other
):
...
...
docs/ref/validators.txt
Dosyayı görüntüle @
b102c27f
...
...
@@ -59,20 +59,22 @@ to, or in lieu of custom ``field.clean()`` methods.
``RegexValidator``
------------------
.. class:: RegexValidator([regex=None, message=None, code=None])
.. class:: RegexValidator([regex=None, message=None, code=None
, inverse_match=None
])
:param regex: If not ``None``, overrides :attr:`regex`. Can be a regular
expression string or a pre-compiled regular expression.
:param message: If not ``None``, overrides :attr:`.message`.
:param code: If not ``None``, overrides :attr:`code`.
:param inverse_match: If not ``None``, overrides :attr:`inverse_match`.
.. attribute:: regex
The regular expression pattern to search for the provided ``value``,
or a pre-compiled regular expression. Raises a
:exc:`~django.core.exceptions.ValidationError` with :attr:`message`
and :attr:`code` if no match is found. By default, matches any string
(including an empty string).
and :attr:`code` if :attr:`inverse_match` is ``False`` and a match is
found, or if :attr:`inverse_match` is ``True`` and a match is not found.
By default, matches any string (including an empty string).
.. attribute:: message
...
...
@@ -85,6 +87,12 @@ to, or in lieu of custom ``field.clean()`` methods.
The error code used by :exc:`~django.core.exceptions.ValidationError`
if validation fails. Defaults to ``"invalid"``.
.. attribute:: inverse_match
.. versionadded:: 1.7
The match mode for :attr:`regex`. Defaults to ``False``.
``URLValidator``
----------------
.. class:: URLValidator([schemes=None, regex=None, message=None, code=None])
...
...
docs/releases/1.7.txt
Dosyayı görüntüle @
b102c27f
...
...
@@ -697,6 +697,12 @@ Tests
Validators
^^^^^^^^^^
* :class:`~django.core.validators.RegexValidator` now accepts an optional
Boolean :attr:`~django.core.validators.RegexValidator.inverse_match` argument
which determines if the :exc:`~django.core.exceptions.ValidationError` should
be raised when the regular expression pattern matches (``True``) or does not
match (``False``, by default) the provided ``value``.
* :class:`~django.core.validators.URLValidator` now accepts an optional
``schemes`` argument which allows customization of the accepted URI schemes
(instead of the defaults ``http(s)`` and ``ftp(s)``).
...
...
tests/validators/tests.py
Dosyayı görüntüle @
b102c27f
...
...
@@ -187,6 +187,10 @@ TEST_DATA = (
(
RegexValidator
(
'x'
),
'y'
,
ValidationError
),
(
RegexValidator
(
re
.
compile
(
'x'
)),
'y'
,
ValidationError
),
(
RegexValidator
(
'x'
,
inverse_match
=
True
),
'y'
,
None
),
(
RegexValidator
(
re
.
compile
(
'x'
),
inverse_match
=
True
),
'y'
,
None
),
(
RegexValidator
(
'x'
,
inverse_match
=
True
),
'x'
,
ValidationError
),
(
RegexValidator
(
re
.
compile
(
'x'
),
inverse_match
=
True
),
'x'
,
ValidationError
),
)
...
...
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