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
c490e410
Kaydet (Commit)
c490e410
authored
Şub 20, 2015
tarafından
Marc Tamlyn
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24373 -- Added run_validators to ArrayField.
Thanks to DavidMuller for the report.
üst
32d4db66
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
array.py
django/contrib/postgres/fields/array.py
+12
-0
test_array.py
tests/postgres_tests/test_array.py
+9
-1
No files found.
django/contrib/postgres/fields/array.py
Dosyayı görüntüle @
c490e410
...
@@ -139,6 +139,18 @@ class ArrayField(Field):
...
@@ -139,6 +139,18 @@ class ArrayField(Field):
code
=
'nested_array_mismatch'
,
code
=
'nested_array_mismatch'
,
)
)
def
run_validators
(
self
,
value
):
super
(
ArrayField
,
self
)
.
run_validators
(
value
)
for
i
,
part
in
enumerate
(
value
):
try
:
self
.
base_field
.
run_validators
(
part
)
except
exceptions
.
ValidationError
as
e
:
raise
exceptions
.
ValidationError
(
string_concat
(
self
.
error_messages
[
'item_invalid'
],
' '
.
join
(
e
.
messages
)),
code
=
'item_invalid'
,
params
=
{
'nth'
:
i
},
)
def
formfield
(
self
,
**
kwargs
):
def
formfield
(
self
,
**
kwargs
):
defaults
=
{
defaults
=
{
'form_class'
:
SimpleArrayField
,
'form_class'
:
SimpleArrayField
,
...
...
tests/postgres_tests/test_array.py
Dosyayı görüntüle @
c490e410
...
@@ -6,7 +6,7 @@ import uuid
...
@@ -6,7 +6,7 @@ import uuid
from
django
import
forms
from
django
import
forms
from
django.contrib.postgres.fields
import
ArrayField
from
django.contrib.postgres.fields
import
ArrayField
from
django.contrib.postgres.forms
import
SimpleArrayField
,
SplitArrayField
from
django.contrib.postgres.forms
import
SimpleArrayField
,
SplitArrayField
from
django.core
import
exceptions
,
serializers
from
django.core
import
exceptions
,
serializers
,
validators
from
django.core.management
import
call_command
from
django.core.management
import
call_command
from
django.db
import
IntegrityError
,
connection
,
models
from
django.db
import
IntegrityError
,
connection
,
models
from
django.test
import
TestCase
,
TransactionTestCase
,
override_settings
from
django.test
import
TestCase
,
TransactionTestCase
,
override_settings
...
@@ -330,6 +330,14 @@ class TestValidation(TestCase):
...
@@ -330,6 +330,14 @@ class TestValidation(TestCase):
self
.
assertEqual
(
cm
.
exception
.
code
,
'nested_array_mismatch'
)
self
.
assertEqual
(
cm
.
exception
.
code
,
'nested_array_mismatch'
)
self
.
assertEqual
(
cm
.
exception
.
messages
[
0
],
'Nested arrays must have the same length.'
)
self
.
assertEqual
(
cm
.
exception
.
messages
[
0
],
'Nested arrays must have the same length.'
)
def
test_with_validators
(
self
):
field
=
ArrayField
(
models
.
IntegerField
(
validators
=
[
validators
.
MinValueValidator
(
1
)]))
field
.
clean
([
1
,
2
],
None
)
with
self
.
assertRaises
(
exceptions
.
ValidationError
)
as
cm
:
field
.
clean
([
0
],
None
)
self
.
assertEqual
(
cm
.
exception
.
code
,
'item_invalid'
)
self
.
assertEqual
(
cm
.
exception
.
messages
[
0
],
'Item 0 in the array did not validate: Ensure this value is greater than or equal to 1.'
)
class
TestSimpleFormField
(
TestCase
):
class
TestSimpleFormField
(
TestCase
):
...
...
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