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
fcb5dbfe
Kaydet (Commit)
fcb5dbfe
authored
Mar 29, 2017
tarafından
Paolo Melchiorre
Kaydeden (comit)
Tim Graham
Nis 26, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27996 -- Added RandomUUID function and CryptoExtension to contrib.postgres.
üst
98ee57e3
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
81 additions
and
5 deletions
+81
-5
functions.py
django/contrib/postgres/functions.py
+10
-1
operations.py
django/contrib/postgres/operations.py
+6
-0
functions.txt
docs/ref/contrib/postgres/functions.txt
+20
-0
operations.txt
docs/ref/contrib/postgres/operations.txt
+9
-0
2.0.txt
docs/releases/2.0.txt
+6
-0
0001_setup_extensions.py
tests/postgres_tests/migrations/0001_setup_extensions.py
+4
-2
0002_create_test_models.py
tests/postgres_tests/migrations/0002_create_test_models.py
+7
-0
models.py
tests/postgres_tests/models.py
+4
-0
test_functions.py
tests/postgres_tests/test_functions.py
+15
-2
No files found.
django/contrib/postgres/functions.py
Dosyayı görüntüle @
fcb5dbfe
from
django.db.models
import
DateTimeField
,
Func
from
django.db.models
import
DateTimeField
,
Func
,
UUIDField
class
RandomUUID
(
Func
):
template
=
'GEN_RANDOM_UUID()'
def
__init__
(
self
,
output_field
=
None
,
**
extra
):
if
output_field
is
None
:
output_field
=
UUIDField
()
super
()
.
__init__
(
output_field
=
output_field
,
**
extra
)
class
TransactionNow
(
Func
):
...
...
django/contrib/postgres/operations.py
Dosyayı görüntüle @
fcb5dbfe
...
...
@@ -35,6 +35,12 @@ class CITextExtension(CreateExtension):
self
.
name
=
'citext'
class
CryptoExtension
(
CreateExtension
):
def
__init__
(
self
):
self
.
name
=
'pgcrypto'
class
HStoreExtension
(
CreateExtension
):
def
__init__
(
self
):
...
...
docs/ref/contrib/postgres/functions.txt
Dosyayı görüntüle @
fcb5dbfe
...
...
@@ -7,6 +7,26 @@ All of these functions are available from the
.. currentmodule:: django.contrib.postgres.functions
``RandomUUID``
==============
.. class:: RandomUUID()
.. versionadded:: 2.0
Returns a version 4 UUID.
The `pgcrypto extension`_ must be installed. You can use the
:class:`~django.contrib.postgres.operations.CryptoExtension` migration
operation to install it.
.. _pgcrypto extension: https://www.postgresql.org/docs/current/static/pgcrypto.html
Usage example::
>>> from django.contrib.postgres.functions import RandomUUID
>>> Article.objects.update(uuid=RandomUUID())
``TransactionNow``
==================
...
...
docs/ref/contrib/postgres/operations.txt
Dosyayı görüntüle @
fcb5dbfe
...
...
@@ -67,6 +67,15 @@ run the query ``CREATE EXTENSION IF NOT EXISTS hstore;``.
Installs the ``citext`` extension.
``CryptoExtension``
===================
.. class:: CryptoExtension()
.. versionadded:: 2.0
Installs the ``pgcrypto`` extension.
``HStoreExtension``
===================
...
...
docs/releases/2.0.txt
Dosyayı görüntüle @
fcb5dbfe
...
...
@@ -87,6 +87,12 @@ Minor features
:class:`~django.contrib.postgres.aggregates.ArrayAgg` determines if
concatenated values will be distinct.
* The new :class:`~django.contrib.postgres.functions.RandomUUID` database
function returns a version 4 UUID. It requires use of PostgreSQL's
``pgcrypto`` extension which can be activated using the new
:class:`~django.contrib.postgres.operations.CryptoExtension` migration
operation.
:mod:`django.contrib.redirects`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
tests/postgres_tests/migrations/0001_setup_extensions.py
Dosyayı görüntüle @
fcb5dbfe
...
...
@@ -4,13 +4,14 @@ from django.db import migrations
try
:
from
django.contrib.postgres.operations
import
(
BtreeGinExtension
,
CITextExtension
,
CreateExtension
,
HStore
Extension
,
TrigramExtension
,
UnaccentExtension
,
BtreeGinExtension
,
CITextExtension
,
CreateExtension
,
Crypto
Extension
,
HStoreExtension
,
TrigramExtension
,
UnaccentExtension
,
)
except
ImportError
:
BtreeGinExtension
=
mock
.
Mock
()
CITextExtension
=
mock
.
Mock
()
CreateExtension
=
mock
.
Mock
()
CryptoExtension
=
mock
.
Mock
()
HStoreExtension
=
mock
.
Mock
()
TrigramExtension
=
mock
.
Mock
()
UnaccentExtension
=
mock
.
Mock
()
...
...
@@ -24,6 +25,7 @@ class Migration(migrations.Migration):
# Ensure CreateExtension quotes extension names by creating one with a
# dash in its name.
CreateExtension
(
'uuid-ossp'
),
CryptoExtension
(),
HStoreExtension
(),
TrigramExtension
(),
UnaccentExtension
(),
...
...
tests/postgres_tests/migrations/0002_create_test_models.py
Dosyayı görüntüle @
fcb5dbfe
...
...
@@ -191,6 +191,13 @@ class Migration(migrations.Migration):
(
'when'
,
models
.
DateTimeField
(
null
=
True
,
default
=
None
)),
]
),
migrations
.
CreateModel
(
name
=
'UUIDTestModel'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
(
'uuid'
,
models
.
UUIDField
(
default
=
None
,
null
=
True
)),
]
),
migrations
.
CreateModel
(
name
=
'RangesModel'
,
fields
=
[
...
...
tests/postgres_tests/models.py
Dosyayı görüntüle @
fcb5dbfe
...
...
@@ -171,3 +171,7 @@ class StatTestModel(models.Model):
class
NowTestModel
(
models
.
Model
):
when
=
models
.
DateTimeField
(
null
=
True
,
default
=
None
)
class
UUIDTestModel
(
models
.
Model
):
uuid
=
models
.
UUIDField
(
default
=
None
,
null
=
True
)
tests/postgres_tests/test_functions.py
Dosyayı görüntüle @
fcb5dbfe
import
uuid
from
datetime
import
datetime
from
time
import
sleep
from
django.contrib.postgres.functions
import
TransactionNow
from
django.contrib.postgres.functions
import
RandomUUID
,
TransactionNow
from
.
import
PostgreSQLTestCase
from
.models
import
NowTestModel
from
.models
import
NowTestModel
,
UUIDTestModel
class
TestTransactionNow
(
PostgreSQLTestCase
):
...
...
@@ -26,3 +27,15 @@ class TestTransactionNow(PostgreSQLTestCase):
self
.
assertIsInstance
(
m1
.
when
,
datetime
)
self
.
assertEqual
(
m1
.
when
,
m2
.
when
)
class
TestRandomUUID
(
PostgreSQLTestCase
):
def
test_random_uuid
(
self
):
m1
=
UUIDTestModel
.
objects
.
create
()
m2
=
UUIDTestModel
.
objects
.
create
()
UUIDTestModel
.
objects
.
update
(
uuid
=
RandomUUID
())
m1
.
refresh_from_db
()
m2
.
refresh_from_db
()
self
.
assertIsInstance
(
m1
.
uuid
,
uuid
.
UUID
)
self
.
assertNotEqual
(
m1
.
uuid
,
m2
.
uuid
)
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