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
f0a68c25
Kaydet (Commit)
f0a68c25
authored
Kas 14, 2017
tarafından
Mads Jensen
Kaydeden (comit)
Tim Graham
Kas 29, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28702 -- Made query lookups for CIText fields use citext.
üst
78c5e7b9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
3 deletions
+36
-3
citext.py
django/contrib/postgres/fields/citext.py
+4
-0
operations.py
django/db/backends/postgresql/operations.py
+2
-0
schema.py
django/db/backends/postgresql/schema.py
+4
-3
1.11.8.txt
docs/releases/1.11.8.txt
+3
-0
tests.py
tests/backends/postgresql/tests.py
+4
-0
test_citext.py
tests/postgres_tests/test_citext.py
+19
-0
No files found.
django/contrib/postgres/fields/citext.py
Dosyayı görüntüle @
f0a68c25
...
@@ -4,6 +4,10 @@ __all__ = ['CICharField', 'CIEmailField', 'CIText', 'CITextField']
...
@@ -4,6 +4,10 @@ __all__ = ['CICharField', 'CIEmailField', 'CIText', 'CITextField']
class
CIText
:
class
CIText
:
def
get_internal_type
(
self
):
return
'CI'
+
super
()
.
get_internal_type
()
def
db_type
(
self
,
connection
):
def
db_type
(
self
,
connection
):
return
'citext'
return
'citext'
...
...
django/db/backends/postgresql/operations.py
Dosyayı görüntüle @
f0a68c25
...
@@ -77,6 +77,8 @@ class DatabaseOperations(BaseDatabaseOperations):
...
@@ -77,6 +77,8 @@ class DatabaseOperations(BaseDatabaseOperations):
'istartswith'
,
'endswith'
,
'iendswith'
,
'regex'
,
'iregex'
):
'istartswith'
,
'endswith'
,
'iendswith'
,
'regex'
,
'iregex'
):
if
internal_type
in
(
'IPAddressField'
,
'GenericIPAddressField'
):
if
internal_type
in
(
'IPAddressField'
,
'GenericIPAddressField'
):
lookup
=
"HOST(
%
s)"
lookup
=
"HOST(
%
s)"
elif
internal_type
in
(
'CICharField'
,
'CIEmailField'
,
'CITextField'
):
lookup
=
'
%
s::citext'
else
:
else
:
lookup
=
"
%
s::text"
lookup
=
"
%
s::text"
...
...
django/db/backends/postgresql/schema.py
Dosyayı görüntüle @
f0a68c25
...
@@ -107,11 +107,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
...
@@ -107,11 +107,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
def
_alter_field
(
self
,
model
,
old_field
,
new_field
,
old_type
,
new_type
,
def
_alter_field
(
self
,
model
,
old_field
,
new_field
,
old_type
,
new_type
,
old_db_params
,
new_db_params
,
strict
=
False
):
old_db_params
,
new_db_params
,
strict
=
False
):
# Drop indexes on varchar/text
columns that are changing to a different
# Drop indexes on varchar/text
/citext columns that are changing to a
# type.
#
different
type.
if
(
old_field
.
db_index
or
old_field
.
unique
)
and
(
if
(
old_field
.
db_index
or
old_field
.
unique
)
and
(
(
old_type
.
startswith
(
'varchar'
)
and
not
new_type
.
startswith
(
'varchar'
))
or
(
old_type
.
startswith
(
'varchar'
)
and
not
new_type
.
startswith
(
'varchar'
))
or
(
old_type
.
startswith
(
'text'
)
and
not
new_type
.
startswith
(
'text'
))
(
old_type
.
startswith
(
'text'
)
and
not
new_type
.
startswith
(
'text'
))
or
(
old_type
.
startswith
(
'citext'
)
and
not
new_type
.
startswith
(
'citext'
))
):
):
index_name
=
self
.
_create_index_name
(
model
.
_meta
.
db_table
,
[
old_field
.
column
],
suffix
=
'_like'
)
index_name
=
self
.
_create_index_name
(
model
.
_meta
.
db_table
,
[
old_field
.
column
],
suffix
=
'_like'
)
self
.
execute
(
self
.
_delete_constraint_sql
(
self
.
sql_delete_index
,
model
,
index_name
))
self
.
execute
(
self
.
_delete_constraint_sql
(
self
.
sql_delete_index
,
model
,
index_name
))
...
...
docs/releases/1.11.8.txt
Dosyayı görüntüle @
f0a68c25
...
@@ -24,3 +24,6 @@ Bugfixes
...
@@ -24,3 +24,6 @@ Bugfixes
* Fixed crash on SQLite and MySQL when ordering by a filtered subquery that
* Fixed crash on SQLite and MySQL when ordering by a filtered subquery that
uses ``nulls_first`` or ``nulls_last`` (:ticket:`28848`).
uses ``nulls_first`` or ``nulls_last`` (:ticket:`28848`).
* Made query lookups for ``CICharField``, ``CIEmailField``, and ``CITextField``
use a ``citext`` cast (:ticket:`28702`).
tests/backends/postgresql/tests.py
Dosyayı görüntüle @
f0a68c25
...
@@ -138,6 +138,10 @@ class Tests(TestCase):
...
@@ -138,6 +138,10 @@ class Tests(TestCase):
for
lookup
in
lookups
:
for
lookup
in
lookups
:
with
self
.
subTest
(
lookup
=
lookup
):
with
self
.
subTest
(
lookup
=
lookup
):
self
.
assertIn
(
'::text'
,
do
.
lookup_cast
(
lookup
))
self
.
assertIn
(
'::text'
,
do
.
lookup_cast
(
lookup
))
for
lookup
in
lookups
:
for
field_type
in
(
'CICharField'
,
'CIEmailField'
,
'CITextField'
):
with
self
.
subTest
(
lookup
=
lookup
,
field_type
=
field_type
):
self
.
assertIn
(
'::citext'
,
do
.
lookup_cast
(
lookup
,
internal_type
=
field_type
))
def
test_correct_extraction_psycopg2_version
(
self
):
def
test_correct_extraction_psycopg2_version
(
self
):
from
django.db.backends.postgresql.base
import
psycopg2_version
from
django.db.backends.postgresql.base
import
psycopg2_version
...
...
tests/postgres_tests/test_citext.py
Dosyayı görüntüle @
f0a68c25
...
@@ -12,6 +12,7 @@ from .models import CITestModel
...
@@ -12,6 +12,7 @@ from .models import CITestModel
@modify_settings
(
INSTALLED_APPS
=
{
'append'
:
'django.contrib.postgres'
})
@modify_settings
(
INSTALLED_APPS
=
{
'append'
:
'django.contrib.postgres'
})
class
CITextTestCase
(
PostgreSQLTestCase
):
class
CITextTestCase
(
PostgreSQLTestCase
):
case_sensitive_lookups
=
(
'contains'
,
'startswith'
,
'endswith'
,
'regex'
)
@classmethod
@classmethod
def
setUpTestData
(
cls
):
def
setUpTestData
(
cls
):
...
@@ -42,3 +43,21 @@ class CITextTestCase(PostgreSQLTestCase):
...
@@ -42,3 +43,21 @@ class CITextTestCase(PostgreSQLTestCase):
instance
=
CITestModel
.
objects
.
get
()
instance
=
CITestModel
.
objects
.
get
()
self
.
assertEqual
(
instance
.
array_field
,
self
.
john
.
array_field
)
self
.
assertEqual
(
instance
.
array_field
,
self
.
john
.
array_field
)
self
.
assertTrue
(
CITestModel
.
objects
.
filter
(
array_field__contains
=
[
'joe'
])
.
exists
())
self
.
assertTrue
(
CITestModel
.
objects
.
filter
(
array_field__contains
=
[
'joe'
])
.
exists
())
def
test_lookups_name_char
(
self
):
for
lookup
in
self
.
case_sensitive_lookups
:
with
self
.
subTest
(
lookup
=
lookup
):
query
=
{
'name__{}'
.
format
(
lookup
):
'john'
}
self
.
assertSequenceEqual
(
CITestModel
.
objects
.
filter
(
**
query
),
[
self
.
john
])
def
test_lookups_description_text
(
self
):
for
lookup
,
string
in
zip
(
self
.
case_sensitive_lookups
,
(
'average'
,
'average joe'
,
'john'
,
'Joe.named'
)):
with
self
.
subTest
(
lookup
=
lookup
,
string
=
string
):
query
=
{
'description__{}'
.
format
(
lookup
):
string
}
self
.
assertSequenceEqual
(
CITestModel
.
objects
.
filter
(
**
query
),
[
self
.
john
])
def
test_lookups_email
(
self
):
for
lookup
,
string
in
zip
(
self
.
case_sensitive_lookups
,
(
'john'
,
'john'
,
'john.com'
,
'john.com'
)):
with
self
.
subTest
(
lookup
=
lookup
,
string
=
string
):
query
=
{
'email__{}'
.
format
(
lookup
):
string
}
self
.
assertSequenceEqual
(
CITestModel
.
objects
.
filter
(
**
query
),
[
self
.
john
])
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