mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Refs #33308 -- Moved psycopg2 imports to the psycopg_any module.
This commit is contained in:
parent
c5ed884eab
commit
2ebfbd894e
@ -1,8 +1,7 @@
|
|||||||
from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange, NumericRange
|
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.core.signals import setting_changed
|
from django.core.signals import setting_changed
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
|
from django.db.backends.postgresql.psycopg_any import RANGE_TYPES
|
||||||
from django.db.backends.signals import connection_created
|
from django.db.backends.signals import connection_created
|
||||||
from django.db.migrations.writer import MigrationWriter
|
from django.db.migrations.writer import MigrationWriter
|
||||||
from django.db.models import CharField, OrderBy, TextField
|
from django.db.models import CharField, OrderBy, TextField
|
||||||
@ -21,8 +20,6 @@ from .lookups import (
|
|||||||
from .serializers import RangeSerializer
|
from .serializers import RangeSerializer
|
||||||
from .signals import register_type_handlers
|
from .signals import register_type_handlers
|
||||||
|
|
||||||
RANGE_TYPES = (DateRange, DateTimeRange, DateTimeTZRange, NumericRange)
|
|
||||||
|
|
||||||
|
|
||||||
def uninstall_if_needed(setting, value, enter, **kwargs):
|
def uninstall_if_needed(setting, value, enter, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange, Range
|
|
||||||
|
|
||||||
from django.contrib.postgres import forms, lookups
|
from django.contrib.postgres import forms, lookups
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.backends.postgresql.psycopg_any import (
|
||||||
|
DateRange,
|
||||||
|
DateTimeTZRange,
|
||||||
|
NumericRange,
|
||||||
|
Range,
|
||||||
|
)
|
||||||
from django.db.models.lookups import PostgresOperatorLookup
|
from django.db.models.lookups import PostgresOperatorLookup
|
||||||
|
|
||||||
from .utils import AttributeSetter
|
from .utils import AttributeSetter
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
|
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core import exceptions
|
from django.core import exceptions
|
||||||
|
from django.db.backends.postgresql.psycopg_any import (
|
||||||
|
DateRange,
|
||||||
|
DateTimeTZRange,
|
||||||
|
NumericRange,
|
||||||
|
)
|
||||||
from django.forms.widgets import HiddenInput, MultiWidget
|
from django.forms.widgets import HiddenInput, MultiWidget
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from psycopg2 import errors
|
|
||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.db.backends.base.creation import BaseDatabaseCreation
|
from django.db.backends.base.creation import BaseDatabaseCreation
|
||||||
|
from django.db.backends.postgresql.psycopg_any import errors
|
||||||
from django.db.backends.utils import strip_quotes
|
from django.db.backends.utils import strip_quotes
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import json
|
import json
|
||||||
from functools import lru_cache, partial
|
from functools import lru_cache, partial
|
||||||
|
|
||||||
from psycopg2.extras import Inet
|
|
||||||
from psycopg2.extras import Json as Jsonb
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.backends.base.operations import BaseDatabaseOperations
|
from django.db.backends.base.operations import BaseDatabaseOperations
|
||||||
|
from django.db.backends.postgresql.psycopg_any import Inet, Jsonb
|
||||||
from django.db.backends.utils import split_tzname_delta
|
from django.db.backends.utils import split_tzname_delta
|
||||||
from django.db.models.constants import OnConflict
|
from django.db.models.constants import OnConflict
|
||||||
|
|
||||||
|
6
django/db/backends/postgresql/psycopg_any.py
Normal file
6
django/db/backends/postgresql/psycopg_any.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from psycopg2 import errors, extensions # NOQA
|
||||||
|
from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange, Inet # NOQA
|
||||||
|
from psycopg2.extras import Json as Jsonb # NOQA
|
||||||
|
from psycopg2.extras import NumericRange, Range # NOQA
|
||||||
|
|
||||||
|
RANGE_TYPES = (DateRange, DateTimeRange, DateTimeTZRange, NumericRange)
|
@ -1,7 +1,6 @@
|
|||||||
import psycopg2
|
|
||||||
|
|
||||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||||
from django.db.backends.ddl_references import IndexColumns
|
from django.db.backends.ddl_references import IndexColumns
|
||||||
|
from django.db.backends.postgresql.psycopg_any import extensions
|
||||||
from django.db.backends.utils import strip_quotes
|
from django.db.backends.utils import strip_quotes
|
||||||
|
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
|||||||
def quote_value(self, value):
|
def quote_value(self, value):
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
value = value.replace("%", "%%")
|
value = value.replace("%", "%%")
|
||||||
adapted = psycopg2.extensions.adapt(value)
|
adapted = extensions.adapt(value)
|
||||||
if hasattr(adapted, "encoding"):
|
if hasattr(adapted, "encoding"):
|
||||||
adapted.encoding = "utf8"
|
adapted.encoding = "utf8"
|
||||||
# getquoted() returns a quoted bytestring of the adapted value.
|
# getquoted() returns a quoted bytestring of the adapted value.
|
||||||
|
@ -9,12 +9,10 @@ from django.db.backends.base.creation import BaseDatabaseCreation
|
|||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import psycopg2 # NOQA
|
from django.db.backends.postgresql.psycopg_any import errors
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
from psycopg2 import errors
|
|
||||||
|
|
||||||
from django.db.backends.postgresql.creation import DatabaseCreation
|
from django.db.backends.postgresql.creation import DatabaseCreation
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,14 +8,18 @@ from django.test import TestCase
|
|||||||
from django.test.utils import modify_settings
|
from django.test.utils import modify_settings
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange, NumericRange
|
|
||||||
|
|
||||||
from django.contrib.postgres.fields import (
|
from django.contrib.postgres.fields import (
|
||||||
DateRangeField,
|
DateRangeField,
|
||||||
DateTimeRangeField,
|
DateTimeRangeField,
|
||||||
DecimalRangeField,
|
DecimalRangeField,
|
||||||
IntegerRangeField,
|
IntegerRangeField,
|
||||||
)
|
)
|
||||||
|
from django.db.backends.postgresql.psycopg_any import (
|
||||||
|
DateRange,
|
||||||
|
DateTimeRange,
|
||||||
|
DateTimeTZRange,
|
||||||
|
NumericRange,
|
||||||
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -31,8 +31,6 @@ from .models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from psycopg2.extras import NumericRange
|
|
||||||
|
|
||||||
from django.contrib.postgres.aggregates import ArrayAgg
|
from django.contrib.postgres.aggregates import ArrayAgg
|
||||||
from django.contrib.postgres.expressions import ArraySubquery
|
from django.contrib.postgres.expressions import ArraySubquery
|
||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
@ -42,6 +40,7 @@ try:
|
|||||||
SplitArrayField,
|
SplitArrayField,
|
||||||
SplitArrayWidget,
|
SplitArrayWidget,
|
||||||
)
|
)
|
||||||
|
from django.db.backends.postgresql.psycopg_any import NumericRange
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@ from .models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from psycopg2.extras import DateRange, NumericRange
|
from django.db.backends.postgresql.psycopg_any import DateRange, NumericRange
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass # psycopg2 isn't installed.
|
pass # psycopg isn't installed.
|
||||||
|
|
||||||
|
|
||||||
class BulkSaveTests(PostgreSQLTestCase):
|
class BulkSaveTests(PostgreSQLTestCase):
|
||||||
|
@ -25,14 +25,13 @@ from . import PostgreSQLTestCase
|
|||||||
from .models import HotelReservation, IntegerArrayModel, RangesModel, Room, Scene
|
from .models import HotelReservation, IntegerArrayModel, RangesModel, Room, Scene
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from psycopg2.extras import DateRange, NumericRange
|
|
||||||
|
|
||||||
from django.contrib.postgres.constraints import ExclusionConstraint
|
from django.contrib.postgres.constraints import ExclusionConstraint
|
||||||
from django.contrib.postgres.fields import (
|
from django.contrib.postgres.fields import (
|
||||||
DateTimeRangeField,
|
DateTimeRangeField,
|
||||||
RangeBoundary,
|
RangeBoundary,
|
||||||
RangeOperators,
|
RangeOperators,
|
||||||
)
|
)
|
||||||
|
from django.db.backends.postgresql.psycopg_any import DateRange, NumericRange
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -20,14 +20,17 @@ from .models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
|
|
||||||
|
|
||||||
from django.contrib.postgres import fields as pg_fields
|
from django.contrib.postgres import fields as pg_fields
|
||||||
from django.contrib.postgres import forms as pg_forms
|
from django.contrib.postgres import forms as pg_forms
|
||||||
from django.contrib.postgres.validators import (
|
from django.contrib.postgres.validators import (
|
||||||
RangeMaxValueValidator,
|
RangeMaxValueValidator,
|
||||||
RangeMinValueValidator,
|
RangeMinValueValidator,
|
||||||
)
|
)
|
||||||
|
from django.db.backends.postgresql.psycopg_any import (
|
||||||
|
DateRange,
|
||||||
|
DateTimeTZRange,
|
||||||
|
NumericRange,
|
||||||
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user