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
b33f10d8
Kaydet (Commit)
b33f10d8
authored
Nis 23, 2018
tarafından
Hasan Ramezani
Kaydeden (comit)
Tim Graham
Nis 23, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #29131 -- Made ArrayField error messages index from 1 instead of 0.
üst
dd68b51e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
22 deletions
+22
-22
array.py
django/contrib/postgres/fields/array.py
+2
-2
array.py
django/contrib/postgres/forms/array.py
+4
-4
test_array.py
tests/postgres_tests/test_array.py
+16
-16
No files found.
django/contrib/postgres/fields/array.py
Dosyayı görüntüle @
b33f10d8
...
...
@@ -160,7 +160,7 @@ class ArrayField(CheckFieldDefaultMixin, Field):
error
,
prefix
=
self
.
error_messages
[
'item_invalid'
],
code
=
'item_invalid'
,
params
=
{
'nth'
:
index
},
params
=
{
'nth'
:
index
+
1
},
)
if
isinstance
(
self
.
base_field
,
ArrayField
):
if
len
({
len
(
i
)
for
i
in
value
})
>
1
:
...
...
@@ -179,7 +179,7 @@ class ArrayField(CheckFieldDefaultMixin, Field):
error
,
prefix
=
self
.
error_messages
[
'item_invalid'
],
code
=
'item_invalid'
,
params
=
{
'nth'
:
index
},
params
=
{
'nth'
:
index
+
1
},
)
def
formfield
(
self
,
**
kwargs
):
...
...
django/contrib/postgres/forms/array.py
Dosyayı görüntüle @
b33f10d8
...
...
@@ -53,7 +53,7 @@ class SimpleArrayField(forms.CharField):
error
,
prefix
=
self
.
error_messages
[
'item_invalid'
],
code
=
'item_invalid'
,
params
=
{
'nth'
:
index
},
params
=
{
'nth'
:
index
+
1
},
))
if
errors
:
raise
ValidationError
(
errors
)
...
...
@@ -70,7 +70,7 @@ class SimpleArrayField(forms.CharField):
error
,
prefix
=
self
.
error_messages
[
'item_invalid'
],
code
=
'item_invalid'
,
params
=
{
'nth'
:
index
},
params
=
{
'nth'
:
index
+
1
},
))
if
errors
:
raise
ValidationError
(
errors
)
...
...
@@ -86,7 +86,7 @@ class SimpleArrayField(forms.CharField):
error
,
prefix
=
self
.
error_messages
[
'item_invalid'
],
code
=
'item_invalid'
,
params
=
{
'nth'
:
index
},
params
=
{
'nth'
:
index
+
1
},
))
if
errors
:
raise
ValidationError
(
errors
)
...
...
@@ -193,7 +193,7 @@ class SplitArrayField(forms.Field):
error
,
self
.
error_messages
[
'item_invalid'
],
code
=
'item_invalid'
,
params
=
{
'nth'
:
index
},
params
=
{
'nth'
:
index
+
1
},
))
cleaned_data
.
append
(
None
)
else
:
...
...
tests/postgres_tests/test_array.py
Dosyayı görüntüle @
b33f10d8
...
...
@@ -600,7 +600,7 @@ class TestValidation(PostgreSQLTestCase):
self
.
assertEqual
(
cm
.
exception
.
code
,
'item_invalid'
)
self
.
assertEqual
(
cm
.
exception
.
message
%
cm
.
exception
.
params
,
'Item
1
in the array did not validate: This field cannot be null.'
'Item
2
in the array did not validate: This field cannot be null.'
)
def
test_blank_true
(
self
):
...
...
@@ -631,10 +631,10 @@ class TestValidation(PostgreSQLTestCase):
exception
=
cm
.
exception
.
error_list
[
0
]
self
.
assertEqual
(
exception
.
message
,
'Item
0
in the array did not validate: Ensure this value has at most 2 characters (it has 3).'
'Item
1
in the array did not validate: Ensure this value has at most 2 characters (it has 3).'
)
self
.
assertEqual
(
exception
.
code
,
'item_invalid'
)
self
.
assertEqual
(
exception
.
params
,
{
'nth'
:
0
,
'value'
:
'abc'
,
'limit_value'
:
2
,
'show_value'
:
3
})
self
.
assertEqual
(
exception
.
params
,
{
'nth'
:
1
,
'value'
:
'abc'
,
'limit_value'
:
2
,
'show_value'
:
3
})
def
test_with_validators
(
self
):
field
=
ArrayField
(
models
.
IntegerField
(
validators
=
[
validators
.
MinValueValidator
(
1
)]))
...
...
@@ -645,10 +645,10 @@ class TestValidation(PostgreSQLTestCase):
exception
=
cm
.
exception
.
error_list
[
0
]
self
.
assertEqual
(
exception
.
message
,
'Item
0
in the array did not validate: Ensure this value is greater than or equal to 1.'
'Item
1
in the array did not validate: Ensure this value is greater than or equal to 1.'
)
self
.
assertEqual
(
exception
.
code
,
'item_invalid'
)
self
.
assertEqual
(
exception
.
params
,
{
'nth'
:
0
,
'value'
:
0
,
'limit_value'
:
1
,
'show_value'
:
0
})
self
.
assertEqual
(
exception
.
params
,
{
'nth'
:
1
,
'value'
:
0
,
'limit_value'
:
1
,
'show_value'
:
0
})
class
TestSimpleFormField
(
PostgreSQLTestCase
):
...
...
@@ -662,13 +662,13 @@ class TestSimpleFormField(PostgreSQLTestCase):
field
=
SimpleArrayField
(
forms
.
IntegerField
())
with
self
.
assertRaises
(
exceptions
.
ValidationError
)
as
cm
:
field
.
clean
(
'a,b,9'
)
self
.
assertEqual
(
cm
.
exception
.
messages
[
0
],
'Item
0
in the array did not validate: Enter a whole number.'
)
self
.
assertEqual
(
cm
.
exception
.
messages
[
0
],
'Item
1
in the array did not validate: Enter a whole number.'
)
def
test_validate_fail
(
self
):
field
=
SimpleArrayField
(
forms
.
CharField
(
required
=
True
))
with
self
.
assertRaises
(
exceptions
.
ValidationError
)
as
cm
:
field
.
clean
(
'a,b,'
)
self
.
assertEqual
(
cm
.
exception
.
messages
[
0
],
'Item
2
in the array did not validate: This field is required.'
)
self
.
assertEqual
(
cm
.
exception
.
messages
[
0
],
'Item
3
in the array did not validate: This field is required.'
)
def
test_validate_fail_base_field_error_params
(
self
):
field
=
SimpleArrayField
(
forms
.
CharField
(
max_length
=
2
))
...
...
@@ -679,23 +679,23 @@ class TestSimpleFormField(PostgreSQLTestCase):
first_error
=
errors
[
0
]
self
.
assertEqual
(
first_error
.
message
,
'Item
0
in the array did not validate: Ensure this value has at most 2 characters (it has 3).'
'Item
1
in the array did not validate: Ensure this value has at most 2 characters (it has 3).'
)
self
.
assertEqual
(
first_error
.
code
,
'item_invalid'
)
self
.
assertEqual
(
first_error
.
params
,
{
'nth'
:
0
,
'value'
:
'abc'
,
'limit_value'
:
2
,
'show_value'
:
3
})
self
.
assertEqual
(
first_error
.
params
,
{
'nth'
:
1
,
'value'
:
'abc'
,
'limit_value'
:
2
,
'show_value'
:
3
})
second_error
=
errors
[
1
]
self
.
assertEqual
(
second_error
.
message
,
'Item
2
in the array did not validate: Ensure this value has at most 2 characters (it has 4).'
'Item
3
in the array did not validate: Ensure this value has at most 2 characters (it has 4).'
)
self
.
assertEqual
(
second_error
.
code
,
'item_invalid'
)
self
.
assertEqual
(
second_error
.
params
,
{
'nth'
:
2
,
'value'
:
'defg'
,
'limit_value'
:
2
,
'show_value'
:
4
})
self
.
assertEqual
(
second_error
.
params
,
{
'nth'
:
3
,
'value'
:
'defg'
,
'limit_value'
:
2
,
'show_value'
:
4
})
def
test_validators_fail
(
self
):
field
=
SimpleArrayField
(
forms
.
RegexField
(
'[a-e]{2}'
))
with
self
.
assertRaises
(
exceptions
.
ValidationError
)
as
cm
:
field
.
clean
(
'a,bc,de'
)
self
.
assertEqual
(
cm
.
exception
.
messages
[
0
],
'Item
0
in the array did not validate: Enter a valid value.'
)
self
.
assertEqual
(
cm
.
exception
.
messages
[
0
],
'Item
1
in the array did not validate: Enter a valid value.'
)
def
test_delimiter
(
self
):
field
=
SimpleArrayField
(
forms
.
CharField
(),
delimiter
=
'|'
)
...
...
@@ -819,10 +819,10 @@ class TestSplitFormField(PostgreSQLTestCase):
data
=
{
'array_0'
:
'a'
,
'array_1'
:
'b'
,
'array_2'
:
''
}
form
=
SplitForm
(
data
)
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertEqual
(
form
.
errors
,
{
'array'
:
[
'Item
2
in the array did not validate: This field is required.'
]})
self
.
assertEqual
(
form
.
errors
,
{
'array'
:
[
'Item
3
in the array did not validate: This field is required.'
]})
def
test_invalid_integer
(
self
):
msg
=
'Item
1
in the array did not validate: Ensure this value is less than or equal to 100.'
msg
=
'Item
2
in the array did not validate: Ensure this value is less than or equal to 100.'
with
self
.
assertRaisesMessage
(
exceptions
.
ValidationError
,
msg
):
SplitArrayField
(
forms
.
IntegerField
(
max_value
=
100
),
size
=
2
)
.
clean
([
0
,
101
])
...
...
@@ -848,8 +848,8 @@ class TestSplitFormField(PostgreSQLTestCase):
with
self
.
assertRaises
(
exceptions
.
ValidationError
)
as
cm
:
field
.
clean
([
'abc'
,
'c'
,
'defg'
])
self
.
assertEqual
(
cm
.
exception
.
messages
,
[
'Item
0
in the array did not validate: Ensure this value has at most 2 characters (it has 3).'
,
'Item
2
in the array did not validate: Ensure this value has at most 2 characters (it has 4).'
,
'Item
1
in the array did not validate: Ensure this value has at most 2 characters (it has 3).'
,
'Item
3
in the array did not validate: Ensure this value has at most 2 characters (it has 4).'
,
])
def
test_splitarraywidget_value_omitted_from_data
(
self
):
...
...
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