mirror of
https://github.com/django/django.git
synced 2024-12-22 00:55:44 +00:00
Applied Black's 2024 stable style.
https://github.com/psf/black/releases/tag/24.1.0
This commit is contained in:
parent
3f6d939c62
commit
305757aec1
@ -1,6 +1,6 @@
|
||||
repos:
|
||||
- repo: https://github.com/psf/black-pre-commit-mirror
|
||||
rev: 23.12.1
|
||||
rev: 24.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
exclude: \.py-tpl$
|
||||
@ -9,7 +9,7 @@ repos:
|
||||
hooks:
|
||||
- id: blacken-docs
|
||||
additional_dependencies:
|
||||
- black==23.12.1
|
||||
- black==24.1.0
|
||||
files: 'docs/.*\.txt$'
|
||||
- repo: https://github.com/PyCQA/isort
|
||||
rev: 5.13.2
|
||||
|
@ -3,6 +3,7 @@ Invokes django-admin when the django module is run as a script.
|
||||
|
||||
Example: python -m django check
|
||||
"""
|
||||
|
||||
from django.core import management
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -5,6 +5,7 @@ Filters are specified in models with the "list_filter" option.
|
||||
Each filter subclass knows how to display a filter for a field that passes a
|
||||
certain test -- e.g. being a DateField or ForeignKey.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
from django.contrib.admin.exceptions import NotRegistered
|
||||
|
@ -1759,9 +1759,9 @@ class ModelAdmin(BaseModelAdmin):
|
||||
has_delete_permission = inline.has_delete_permission(request, obj)
|
||||
else:
|
||||
# Disable all edit-permissions, and override formset settings.
|
||||
has_add_permission = (
|
||||
has_change_permission
|
||||
) = has_delete_permission = False
|
||||
has_add_permission = has_change_permission = has_delete_permission = (
|
||||
False
|
||||
)
|
||||
formset.extra = formset.max_num = 0
|
||||
has_view_permission = inline.has_view_permission(request, obj)
|
||||
prepopulated = dict(inline.get_prepopulated_fields(request, obj))
|
||||
@ -1896,9 +1896,11 @@ class ModelAdmin(BaseModelAdmin):
|
||||
form,
|
||||
list(fieldsets),
|
||||
# Clear prepopulated fields on a view-only form to avoid a crash.
|
||||
(
|
||||
self.get_prepopulated_fields(request, obj)
|
||||
if add or self.has_change_permission(request, obj)
|
||||
else {},
|
||||
else {}
|
||||
),
|
||||
readonly_fields,
|
||||
model_admin=self,
|
||||
)
|
||||
|
@ -171,9 +171,9 @@ def result_headers(cl):
|
||||
"url_primary": cl.get_query_string({ORDER_VAR: ".".join(o_list_primary)}),
|
||||
"url_remove": cl.get_query_string({ORDER_VAR: ".".join(o_list_remove)}),
|
||||
"url_toggle": cl.get_query_string({ORDER_VAR: ".".join(o_list_toggle)}),
|
||||
"class_attrib": format_html(' class="{}"', " ".join(th_classes))
|
||||
if th_classes
|
||||
else "",
|
||||
"class_attrib": (
|
||||
format_html(' class="{}"', " ".join(th_classes)) if th_classes else ""
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@ -270,9 +270,11 @@ def items_for_result(cl, result, form):
|
||||
link_or_text = format_html(
|
||||
'<a href="{}"{}>{}</a>',
|
||||
url,
|
||||
(
|
||||
format_html(' data-popup-opener="{}"', value)
|
||||
if cl.is_popup
|
||||
else "",
|
||||
else ""
|
||||
),
|
||||
result_repr,
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Form Widget classes specific to the Django admin site.
|
||||
"""
|
||||
|
||||
import copy
|
||||
import json
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module allows importing AbstractBaseUser even when django.contrib.auth is
|
||||
not in INSTALLED_APPS.
|
||||
"""
|
||||
|
||||
import unicodedata
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Creates permissions for all installed apps that need permissions.
|
||||
"""
|
||||
|
||||
import getpass
|
||||
import unicodedata
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Management utility to create superusers.
|
||||
"""
|
||||
|
||||
import getpass
|
||||
import os
|
||||
import sys
|
||||
@ -271,15 +272,19 @@ class Command(BaseCommand):
|
||||
return "%s%s%s: " % (
|
||||
capfirst(field.verbose_name),
|
||||
" (leave blank to use '%s')" % default if default else "",
|
||||
(
|
||||
" (%s.%s)"
|
||||
% (
|
||||
field.remote_field.model._meta.object_name,
|
||||
(
|
||||
field.m2m_target_field_name()
|
||||
if field.many_to_many
|
||||
else field.remote_field.field_name,
|
||||
else field.remote_field.field_name
|
||||
),
|
||||
)
|
||||
if field.remote_field
|
||||
else "",
|
||||
else ""
|
||||
),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
|
@ -7,6 +7,7 @@
|
||||
For example, the `USER_SDO_GEOM_METADATA` is used for the GeometryColumns
|
||||
model and the `SDO_COORD_REF_SYS` is used for the SpatialRefSys model.
|
||||
"""
|
||||
|
||||
from django.contrib.gis.db import models
|
||||
from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
support for an internal JVM, and Java libraries are required to use
|
||||
the WKT constructors.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from django.contrib.gis.db import models
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
This object provides quoting for GEOS geometries into PostgreSQL/PostGIS.
|
||||
"""
|
||||
|
||||
from django.contrib.gis.db.backends.postgis.pgraster import to_pgraster
|
||||
from django.contrib.gis.geos import GEOSGeometry
|
||||
from django.db.backends.postgresql.psycopg_any import sql
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
PostGIS to GDAL conversion constant definitions
|
||||
"""
|
||||
|
||||
# Lookup to convert pixel type values from GDAL to PostGIS
|
||||
GDAL_TO_POSTGIS = [None, 4, 6, 5, 8, 7, 10, 11, None, None, None, None]
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
The GeometryColumns and SpatialRefSys models for the PostGIS backend.
|
||||
"""
|
||||
|
||||
from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin
|
||||
from django.db import models
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
The GeometryColumns and SpatialRefSys models for the SpatiaLite backend.
|
||||
"""
|
||||
|
||||
from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin
|
||||
from django.db import models
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
SQL functions reference lists:
|
||||
https://www.gaia-gis.it/gaia-sins/spatialite-sql-4.3.0.html
|
||||
"""
|
||||
|
||||
from django.contrib.gis.db import models
|
||||
from django.contrib.gis.db.backends.base.operations import BaseSpatialOperations
|
||||
from django.contrib.gis.db.backends.spatialite.adapter import SpatiaLiteAdapter
|
||||
|
@ -127,9 +127,11 @@ class SQLiteDecimalToFloatMixin:
|
||||
copy = self.copy()
|
||||
copy.set_source_expressions(
|
||||
[
|
||||
(
|
||||
Value(float(expr.value))
|
||||
if hasattr(expr, "value") and isinstance(expr.value, Decimal)
|
||||
else expr
|
||||
)
|
||||
for expr in copy.get_source_expressions()
|
||||
]
|
||||
)
|
||||
@ -349,9 +351,9 @@ class Distance(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
|
||||
def as_sqlite(self, compiler, connection, **extra_context):
|
||||
if self.geo_field.geodetic(connection):
|
||||
# SpatiaLite returns NULL instead of zero on geodetic coordinates
|
||||
extra_context[
|
||||
"template"
|
||||
] = "COALESCE(%(function)s(%(expressions)s, %(spheroid)s), 0)"
|
||||
extra_context["template"] = (
|
||||
"COALESCE(%(function)s(%(expressions)s, %(spheroid)s), 0)"
|
||||
)
|
||||
extra_context["spheroid"] = int(bool(self.spheroid))
|
||||
return super().as_sql(compiler, connection, **extra_context)
|
||||
|
||||
|
@ -5,6 +5,7 @@ objects corresponding to geographic model fields.
|
||||
|
||||
Thanks to Robert Coup for providing this functionality (see #4322).
|
||||
"""
|
||||
|
||||
from django.db.models.query_utils import DeferredAttribute
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module holds simple classes to convert geospatial values from the
|
||||
database.
|
||||
"""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from django.contrib.gis.measure import Area, Distance
|
||||
|
@ -25,6 +25,7 @@
|
||||
by setting `GDAL_LIBRARY_PATH` in your settings with the path to the GDAL C
|
||||
library on your system.
|
||||
"""
|
||||
|
||||
from django.contrib.gis.gdal.datasource import DataSource
|
||||
from django.contrib.gis.gdal.driver import Driver
|
||||
from django.contrib.gis.gdal.envelope import Envelope
|
||||
|
@ -33,6 +33,7 @@
|
||||
# OFTReal returns floats, all else returns string.
|
||||
val = field.value
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from django.contrib.gis.gdal.base import GDALBase
|
||||
|
@ -10,6 +10,7 @@
|
||||
| |
|
||||
Lower left (min_x, min_y) o----------+
|
||||
"""
|
||||
|
||||
from ctypes import Structure, c_double
|
||||
|
||||
from django.contrib.gis.gdal.error import GDALException
|
||||
|
@ -38,6 +38,7 @@
|
||||
>>> print(gt1 == 3, gt1 == 'Polygon') # Equivalence works w/non-OGRGeomType objects
|
||||
True True
|
||||
"""
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
from binascii import b2a_hex
|
||||
|
@ -3,6 +3,7 @@
|
||||
related data structures. OGR_Dr_*, OGR_DS_*, OGR_L_*, OGR_F_*,
|
||||
OGR_Fld_* routines are relevant here.
|
||||
"""
|
||||
|
||||
from ctypes import POINTER, c_char_p, c_double, c_int, c_long, c_uint, c_void_p
|
||||
|
||||
from django.contrib.gis.gdal.envelope import OGREnvelope
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module houses the error-checking routines used by the GDAL
|
||||
ctypes prototypes.
|
||||
"""
|
||||
|
||||
from ctypes import c_void_p, string_at
|
||||
|
||||
from django.contrib.gis.gdal.error import GDALException, SRSException, check_err
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module contains functions that generate ctypes prototypes for the
|
||||
GDAL routines.
|
||||
"""
|
||||
|
||||
from ctypes import POINTER, c_bool, c_char_p, c_double, c_int, c_int64, c_void_p
|
||||
from functools import partial
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module houses the ctypes function prototypes for GDAL DataSource (raster)
|
||||
related data structures.
|
||||
"""
|
||||
|
||||
from ctypes import POINTER, c_bool, c_char_p, c_double, c_int, c_void_p
|
||||
from functools import partial
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
GDAL - Constant definitions
|
||||
"""
|
||||
|
||||
from ctypes import (
|
||||
c_double,
|
||||
c_float,
|
||||
|
@ -26,6 +26,7 @@
|
||||
>>> print(srs.name)
|
||||
NAD83 / Texas South Central
|
||||
"""
|
||||
|
||||
from ctypes import byref, c_char_p, c_int
|
||||
from enum import IntEnum
|
||||
from types import NoneType
|
||||
|
@ -2,6 +2,7 @@
|
||||
The GeoDjango GEOS module. Please consult the GeoDjango documentation
|
||||
for more details: https://docs.djangoproject.com/en/dev/ref/contrib/gis/geos/
|
||||
"""
|
||||
|
||||
from .collections import ( # NOQA
|
||||
GeometryCollection,
|
||||
MultiLineString,
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module houses the Geometry Collection objects:
|
||||
GeometryCollection, MultiPoint, MultiLineString, and MultiPolygon
|
||||
"""
|
||||
|
||||
from django.contrib.gis.geos import prototypes as capi
|
||||
from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
|
||||
from django.contrib.gis.geos.libgeos import GEOM_PTR
|
||||
|
@ -3,6 +3,7 @@
|
||||
by GEOSGeometry to house the actual coordinates of the Point,
|
||||
LineString, and LinearRing geometries.
|
||||
"""
|
||||
|
||||
from ctypes import byref, c_byte, c_double, c_uint
|
||||
|
||||
from django.contrib.gis.geos import prototypes as capi
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module contains the 'base' GEOSGeometry object -- all GEOS Geometries
|
||||
inherit from this object.
|
||||
"""
|
||||
|
||||
import re
|
||||
from ctypes import addressof, byref, c_double
|
||||
|
||||
|
@ -3,6 +3,7 @@ Module that holds classes for performing I/O operations on GEOS geometry
|
||||
objects. Specifically, this has Python implementations of WKB/WKT
|
||||
reader and writer classes.
|
||||
"""
|
||||
|
||||
from django.contrib.gis.geos.geometry import GEOSGeometry
|
||||
from django.contrib.gis.geos.prototypes.io import (
|
||||
WKBWriter,
|
||||
|
@ -6,6 +6,7 @@
|
||||
This module also houses GEOS Pointer utilities, including
|
||||
get_pointer_arr(), and GEOM_PTR.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
from ctypes import CDLL, CFUNCTYPE, POINTER, Structure, c_char_p
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Error checking functions for GEOS ctypes prototype functions.
|
||||
"""
|
||||
|
||||
from ctypes import c_void_p, string_at
|
||||
|
||||
from django.contrib.gis.geos.error import GEOSException
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module is for the miscellaneous GEOS routines, particularly the
|
||||
ones that return the area, distance, and length.
|
||||
"""
|
||||
|
||||
from ctypes import POINTER, c_double, c_int
|
||||
|
||||
from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOSFuncFactory
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module houses the GEOS ctypes prototype functions for the
|
||||
unary and binary predicate operations on geometries.
|
||||
"""
|
||||
|
||||
from ctypes import c_byte, c_char_p, c_double
|
||||
|
||||
from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOSFuncFactory
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module houses the GEOS ctypes prototype functions for the
|
||||
topological operations on geometries.
|
||||
"""
|
||||
|
||||
from ctypes import c_double, c_int
|
||||
|
||||
from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOSFuncFactory
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
This module contains useful utilities for GeoDjango.
|
||||
"""
|
||||
|
||||
from django.contrib.gis.utils.ogrinfo import ogrinfo
|
||||
from django.contrib.gis.utils.ogrinspect import mapping, ogrinspect
|
||||
from django.contrib.gis.utils.srs import add_srs_entry
|
||||
|
@ -3,6 +3,7 @@ This module is for inspecting OGR data sources and generating either
|
||||
models for GeoDjango and/or mapping dictionaries for use with the
|
||||
`LayerMapping` utility.
|
||||
"""
|
||||
|
||||
from django.contrib.gis.gdal import DataSource
|
||||
from django.contrib.gis.gdal.field import (
|
||||
OFTDate,
|
||||
|
@ -116,9 +116,11 @@ class SearchVector(SearchVectorCombinable, Func):
|
||||
clone.set_source_expressions(
|
||||
[
|
||||
Coalesce(
|
||||
(
|
||||
expression
|
||||
if isinstance(expression.output_field, (CharField, TextField))
|
||||
else Cast(expression, TextField()),
|
||||
else Cast(expression, TextField())
|
||||
),
|
||||
Value(""),
|
||||
)
|
||||
for expression in clone.get_source_expressions()
|
||||
|
@ -2,6 +2,7 @@
|
||||
This module allows importing AbstractBaseSession even
|
||||
when django.contrib.sessions is not in INSTALLED_APPS.
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
@ -3,6 +3,7 @@ Views and functions for serving static files. These are only to be used during
|
||||
development, and SHOULD NOT be used in a production setting.
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
import posixpath
|
||||
|
||||
|
1
django/core/cache/__init__.py
vendored
1
django/core/cache/__init__.py
vendored
@ -12,6 +12,7 @@ object.
|
||||
|
||||
See docs/topics/cache.txt for information on the public API.
|
||||
"""
|
||||
|
||||
from django.core import signals
|
||||
from django.core.cache.backends.base import (
|
||||
BaseCache,
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Global Django exception and warning classes.
|
||||
"""
|
||||
|
||||
import operator
|
||||
|
||||
from django.utils.hashable import make_hashable
|
||||
|
@ -3,6 +3,7 @@ Utility functions for handling images.
|
||||
|
||||
Requires Pillow as you might imagine.
|
||||
"""
|
||||
|
||||
import struct
|
||||
import zlib
|
||||
|
||||
|
@ -16,6 +16,7 @@ Example Usage::
|
||||
... locks.lock(f, locks.LOCK_EX)
|
||||
... f.write('Django')
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
__all__ = ("LOCK_EX", "LOCK_SH", "LOCK_NB", "lock", "unlock")
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Base file upload handler classes, and the built-in concrete subclasses
|
||||
"""
|
||||
|
||||
import os
|
||||
from io import BytesIO
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Tools for sending email.
|
||||
"""
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
# Imported for backwards compatibility and for the sake
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Email backend that writes messages to console instead of sending them.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import threading
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Backend for test environment.
|
||||
"""
|
||||
|
||||
import copy
|
||||
|
||||
from django.core import mail
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""SMTP email backend class."""
|
||||
|
||||
import smtplib
|
||||
import ssl
|
||||
import threading
|
||||
|
@ -2,6 +2,7 @@
|
||||
Base classes for writing management commands (named commands which can
|
||||
be executed through ``django-admin`` or ``manage.py``).
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
@ -528,9 +529,11 @@ class BaseCommand:
|
||||
if issues:
|
||||
visible_issue_count += len(issues)
|
||||
formatted = (
|
||||
(
|
||||
self.style.ERROR(str(e))
|
||||
if e.is_serious()
|
||||
else self.style.WARNING(str(e))
|
||||
)
|
||||
for e in issues
|
||||
)
|
||||
formatted = "\n".join(sorted(formatted))
|
||||
@ -543,11 +546,15 @@ class BaseCommand:
|
||||
if visible_issue_count:
|
||||
footer += "\n"
|
||||
footer += "System check identified %s (%s silenced)." % (
|
||||
(
|
||||
"no issues"
|
||||
if visible_issue_count == 0
|
||||
else "1 issue"
|
||||
else (
|
||||
"1 issue"
|
||||
if visible_issue_count == 1
|
||||
else "%s issues" % visible_issue_count,
|
||||
else "%s issues" % visible_issue_count
|
||||
)
|
||||
),
|
||||
len(all_issues) - visible_issue_count,
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Module for abstract serializer/unserializer base classes.
|
||||
"""
|
||||
|
||||
from io import StringIO
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
XML serializer.
|
||||
"""
|
||||
|
||||
import json
|
||||
from xml.dom import pulldom
|
||||
from xml.sax import handler
|
||||
|
@ -724,9 +724,9 @@ class BaseDatabaseSchemaEditor:
|
||||
namespace, _ = split_identifier(model._meta.db_table)
|
||||
definition += " " + self.sql_create_column_inline_fk % {
|
||||
"name": self._fk_constraint_name(model, field, constraint_suffix),
|
||||
"namespace": "%s." % self.quote_name(namespace)
|
||||
if namespace
|
||||
else "",
|
||||
"namespace": (
|
||||
"%s." % self.quote_name(namespace) if namespace else ""
|
||||
),
|
||||
"column": self.quote_name(field.column),
|
||||
"to_table": self.quote_name(to_table),
|
||||
"to_column": self.quote_name(to_column),
|
||||
@ -1919,11 +1919,13 @@ class BaseDatabaseSchemaEditor:
|
||||
"""Return all constraint names matching the columns and conditions."""
|
||||
if column_names is not None:
|
||||
column_names = [
|
||||
(
|
||||
self.connection.introspection.identifier_converter(
|
||||
truncate_name(name, self.connection.ops.max_name_length())
|
||||
)
|
||||
if self.connection.features.truncates_names
|
||||
else self.connection.introspection.identifier_converter(name)
|
||||
)
|
||||
for name in column_names
|
||||
]
|
||||
with self.connection.cursor() as cursor:
|
||||
|
@ -2,6 +2,7 @@
|
||||
Helpers to manipulate deferred DDL statements that might need to be adjusted or
|
||||
discarded within when executing a migration.
|
||||
"""
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@ MySQL database backend for Django.
|
||||
|
||||
Requires mysqlclient: https://pypi.org/project/mysqlclient/
|
||||
"""
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import IntegrityError
|
||||
from django.db.backends import utils as backend_utils
|
||||
|
@ -3,6 +3,7 @@ Oracle database backend for Django.
|
||||
|
||||
Requires oracledb: https://oracle.github.io/python-oracledb/
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
import os
|
||||
|
@ -133,20 +133,20 @@ class DatabaseCreation(BaseDatabaseCreation):
|
||||
credentials in the SAVED_USER/SAVED_PASSWORD key in the settings dict.
|
||||
"""
|
||||
real_settings = settings.DATABASES[self.connection.alias]
|
||||
real_settings["SAVED_USER"] = self.connection.settings_dict[
|
||||
"SAVED_USER"
|
||||
] = self.connection.settings_dict["USER"]
|
||||
real_settings["SAVED_USER"] = self.connection.settings_dict["SAVED_USER"] = (
|
||||
self.connection.settings_dict["USER"]
|
||||
)
|
||||
real_settings["SAVED_PASSWORD"] = self.connection.settings_dict[
|
||||
"SAVED_PASSWORD"
|
||||
] = self.connection.settings_dict["PASSWORD"]
|
||||
real_test_settings = real_settings["TEST"]
|
||||
test_settings = self.connection.settings_dict["TEST"]
|
||||
real_test_settings["USER"] = real_settings["USER"] = test_settings[
|
||||
"USER"
|
||||
] = self.connection.settings_dict["USER"] = parameters["user"]
|
||||
real_settings["PASSWORD"] = self.connection.settings_dict[
|
||||
"PASSWORD"
|
||||
] = parameters["password"]
|
||||
real_test_settings["USER"] = real_settings["USER"] = test_settings["USER"] = (
|
||||
self.connection.settings_dict["USER"]
|
||||
) = parameters["user"]
|
||||
real_settings["PASSWORD"] = self.connection.settings_dict["PASSWORD"] = (
|
||||
parameters["password"]
|
||||
)
|
||||
|
||||
def set_as_test_mirror(self, primary_settings_dict):
|
||||
"""
|
||||
|
@ -226,9 +226,11 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
server_side_binding = conn_params.pop("server_side_binding", None)
|
||||
conn_params.setdefault(
|
||||
"cursor_factory",
|
||||
(
|
||||
ServerBindingCursor
|
||||
if is_psycopg3 and server_side_binding is True
|
||||
else Cursor,
|
||||
else Cursor
|
||||
),
|
||||
)
|
||||
if settings_dict["USER"]:
|
||||
conn_params["user"] = settings_dict["USER"]
|
||||
|
@ -267,9 +267,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
% {
|
||||
"column": self.quote_name(new_field.column),
|
||||
"type": new_type,
|
||||
"collation": " " + self._collate_sql(new_collation)
|
||||
if new_collation
|
||||
else "",
|
||||
"collation": (
|
||||
" " + self._collate_sql(new_collation) if new_collation else ""
|
||||
),
|
||||
},
|
||||
[],
|
||||
)
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Implementations of SQL functions for SQLite.
|
||||
"""
|
||||
|
||||
import functools
|
||||
import random
|
||||
import statistics
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
SQLite backend for the sqlite3 module in the standard library.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
import warnings
|
||||
|
@ -620,12 +620,13 @@ class MigrationAutodetector:
|
||||
rem_model_state.app_label,
|
||||
rem_model_state.name_lower,
|
||||
)
|
||||
self.renamed_models_rel[
|
||||
renamed_models_rel_key
|
||||
] = "%s.%s" % (
|
||||
self.renamed_models_rel[renamed_models_rel_key] = (
|
||||
"%s.%s"
|
||||
% (
|
||||
model_state.app_label,
|
||||
model_state.name_lower,
|
||||
)
|
||||
)
|
||||
self.old_model_keys.remove((rem_app_label, rem_model_name))
|
||||
self.old_model_keys.add((app_label, model_name))
|
||||
break
|
||||
@ -1058,9 +1059,9 @@ class MigrationAutodetector:
|
||||
(rem_app_label, rem_model_name, rem_field_name)
|
||||
)
|
||||
old_field_keys.add((app_label, model_name, field_name))
|
||||
self.renamed_fields[
|
||||
app_label, model_name, field_name
|
||||
] = rem_field_name
|
||||
self.renamed_fields[app_label, model_name, field_name] = (
|
||||
rem_field_name
|
||||
)
|
||||
break
|
||||
|
||||
def generate_renamed_fields(self):
|
||||
|
@ -131,12 +131,12 @@ class MigrationLoader:
|
||||
"Migration %s in app %s has no Migration class"
|
||||
% (migration_name, app_config.label)
|
||||
)
|
||||
self.disk_migrations[
|
||||
app_config.label, migration_name
|
||||
] = migration_module.Migration(
|
||||
self.disk_migrations[app_config.label, migration_name] = (
|
||||
migration_module.Migration(
|
||||
migration_name,
|
||||
app_config.label,
|
||||
)
|
||||
)
|
||||
|
||||
def get_migration(self, app_label, name_prefix):
|
||||
"""Return the named migration or raise NodeNotFoundError."""
|
||||
|
@ -55,12 +55,12 @@ class CreateModel(ModelOperation):
|
||||
_check_for_duplicates("fields", (name for name, _ in self.fields))
|
||||
_check_for_duplicates(
|
||||
"bases",
|
||||
(
|
||||
(
|
||||
base._meta.label_lower
|
||||
if hasattr(base, "_meta")
|
||||
else base.lower()
|
||||
if isinstance(base, str)
|
||||
else base
|
||||
else base.lower() if isinstance(base, str) else base
|
||||
)
|
||||
for base in self.bases
|
||||
),
|
||||
)
|
||||
|
@ -524,12 +524,12 @@ class ProjectState:
|
||||
if model_state.options.get("proxy"):
|
||||
proxy_models[model_key] = model_state
|
||||
# Find a concrete model for the proxy.
|
||||
concrete_models_mapping[
|
||||
model_key
|
||||
] = self._find_concrete_model_from_proxy(
|
||||
concrete_models_mapping[model_key] = (
|
||||
self._find_concrete_model_from_proxy(
|
||||
proxy_models,
|
||||
model_state,
|
||||
)
|
||||
)
|
||||
else:
|
||||
concrete_models_mapping[model_key] = model_key
|
||||
return concrete_models_mapping, proxy_models
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Classes to represent the definitions of aggregate functions.
|
||||
"""
|
||||
|
||||
from django.core.exceptions import FieldError, FullResultSet
|
||||
from django.db.models.expressions import Case, Func, Star, Value, When
|
||||
from django.db.models.fields import IntegerField
|
||||
|
@ -2265,9 +2265,11 @@ class Model(AltersData, metaclass=ModelBase):
|
||||
opts = cls._meta
|
||||
valid_fields = set(
|
||||
chain.from_iterable(
|
||||
(
|
||||
(f.name, f.attname)
|
||||
if not (f.auto_created and not f.concrete)
|
||||
else (f.field.related_query_name(),)
|
||||
)
|
||||
for f in chain(opts.fields, opts.related_objects)
|
||||
)
|
||||
)
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Constants used across the ORM in general.
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
|
||||
# Separator used to split filter strings apart.
|
||||
|
@ -204,9 +204,11 @@ class BaseExpression:
|
||||
|
||||
def _parse_expressions(self, *expressions):
|
||||
return [
|
||||
(
|
||||
arg
|
||||
if hasattr(arg, "resolve_expression")
|
||||
else (F(arg) if isinstance(arg, str) else Value(arg))
|
||||
)
|
||||
for arg in expressions
|
||||
]
|
||||
|
||||
@ -285,9 +287,11 @@ class BaseExpression:
|
||||
c.is_summary = summarize
|
||||
c.set_source_expressions(
|
||||
[
|
||||
(
|
||||
expr.resolve_expression(query, allow_joins, reuse, summarize)
|
||||
if expr
|
||||
else None
|
||||
)
|
||||
for expr in c.get_source_expressions()
|
||||
]
|
||||
)
|
||||
@ -366,22 +370,16 @@ class BaseExpression:
|
||||
field = self.output_field
|
||||
internal_type = field.get_internal_type()
|
||||
if internal_type == "FloatField":
|
||||
return (
|
||||
lambda value, expression, connection: None
|
||||
if value is None
|
||||
else float(value)
|
||||
return lambda value, expression, connection: (
|
||||
None if value is None else float(value)
|
||||
)
|
||||
elif internal_type.endswith("IntegerField"):
|
||||
return (
|
||||
lambda value, expression, connection: None
|
||||
if value is None
|
||||
else int(value)
|
||||
return lambda value, expression, connection: (
|
||||
None if value is None else int(value)
|
||||
)
|
||||
elif internal_type == "DecimalField":
|
||||
return (
|
||||
lambda value, expression, connection: None
|
||||
if value is None
|
||||
else Decimal(value)
|
||||
return lambda value, expression, connection: (
|
||||
None if value is None else Decimal(value)
|
||||
)
|
||||
return self._convert_value_noop
|
||||
|
||||
@ -432,9 +430,11 @@ class BaseExpression:
|
||||
clone = self.copy()
|
||||
clone.set_source_expressions(
|
||||
[
|
||||
(
|
||||
F(f"{prefix}{expr.name}")
|
||||
if isinstance(expr, F)
|
||||
else expr.prefix_references(prefix)
|
||||
)
|
||||
for expr in self.get_source_expressions()
|
||||
]
|
||||
)
|
||||
|
@ -62,6 +62,7 @@ and two directions (forward and reverse) for a total of six combinations.
|
||||
If you're looking for ``ForwardManyToManyDescriptor`` or
|
||||
``ReverseManyToManyDescriptor``, use ``ManyToManyDescriptor`` instead.
|
||||
"""
|
||||
|
||||
import warnings
|
||||
|
||||
from asgiref.sync import sync_to_async
|
||||
|
@ -8,6 +8,7 @@ in the ``remote_field`` attribute of the field.
|
||||
They also act as reverse fields for the purposes of the Meta API because
|
||||
they're the closest concept currently available.
|
||||
"""
|
||||
|
||||
import warnings
|
||||
|
||||
from django.core import exceptions
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Database functions that do comparisons or type conversions."""
|
||||
|
||||
from django.db import NotSupportedError
|
||||
from django.db.models.expressions import Func, Value
|
||||
from django.db.models.fields import TextField
|
||||
|
@ -318,9 +318,11 @@ class TruncBase(TimezoneMixin, Transform):
|
||||
"Cannot truncate DateField '%s' to %s."
|
||||
% (
|
||||
field.name,
|
||||
(
|
||||
output_field.__class__.__name__
|
||||
if has_explicit_output_field
|
||||
else "DateTimeField",
|
||||
else "DateTimeField"
|
||||
),
|
||||
)
|
||||
)
|
||||
elif isinstance(field, TimeField) and (
|
||||
@ -331,9 +333,11 @@ class TruncBase(TimezoneMixin, Transform):
|
||||
"Cannot truncate TimeField '%s' to %s."
|
||||
% (
|
||||
field.name,
|
||||
(
|
||||
output_field.__class__.__name__
|
||||
if has_explicit_output_field
|
||||
else "DateTimeField",
|
||||
else "DateTimeField"
|
||||
),
|
||||
)
|
||||
)
|
||||
return copy
|
||||
|
@ -47,9 +47,11 @@ class ATan2(NumericOutputFieldMixin, Func):
|
||||
clone = self.copy()
|
||||
clone.set_source_expressions(
|
||||
[
|
||||
(
|
||||
Cast(expression, FloatField())
|
||||
if isinstance(expression.output_field, IntegerField)
|
||||
else expression
|
||||
)
|
||||
for expression in self.get_source_expressions()[::-1]
|
||||
]
|
||||
)
|
||||
|
@ -14,9 +14,11 @@ class FixDecimalInputMixin:
|
||||
clone = self.copy()
|
||||
clone.set_source_expressions(
|
||||
[
|
||||
(
|
||||
Cast(expression, output_field)
|
||||
if isinstance(expression.output_field, FloatField)
|
||||
else expression
|
||||
)
|
||||
for expression in self.get_source_expressions()
|
||||
]
|
||||
)
|
||||
|
@ -89,9 +89,11 @@ class ConcatPair(Func):
|
||||
c = self.copy()
|
||||
c.set_source_expressions(
|
||||
[
|
||||
(
|
||||
expression
|
||||
if isinstance(expression.output_field, (CharField, TextField))
|
||||
else Cast(expression, TextField())
|
||||
)
|
||||
for expression in c.get_source_expressions()
|
||||
]
|
||||
)
|
||||
|
@ -196,9 +196,11 @@ class Index:
|
||||
"" if not self.fields else " fields=%s" % repr(self.fields),
|
||||
"" if not self.expressions else " expressions=%s" % repr(self.expressions),
|
||||
"" if not self.name else " name=%s" % repr(self.name),
|
||||
(
|
||||
""
|
||||
if self.db_tablespace is None
|
||||
else " db_tablespace=%s" % repr(self.db_tablespace),
|
||||
else " db_tablespace=%s" % repr(self.db_tablespace)
|
||||
),
|
||||
"" if self.condition is None else " condition=%s" % self.condition,
|
||||
"" if not self.include else " include=%s" % repr(self.include),
|
||||
"" if not self.opclasses else " opclasses=%s" % repr(self.opclasses),
|
||||
|
@ -273,9 +273,11 @@ class FieldGetDbPrepValueMixin:
|
||||
return (
|
||||
"%s",
|
||||
[
|
||||
(
|
||||
v
|
||||
if hasattr(v, "as_sql")
|
||||
else get_db_prep_value(v, connection, prepared=True)
|
||||
)
|
||||
for v in value
|
||||
],
|
||||
)
|
||||
|
@ -109,9 +109,11 @@ class ModelIterable(BaseIterable):
|
||||
related_objs,
|
||||
operator.attrgetter(
|
||||
*[
|
||||
(
|
||||
field.attname
|
||||
if from_field == "self"
|
||||
else queryset.model._meta.get_field(from_field).attname
|
||||
)
|
||||
for from_field in field.from_fields
|
||||
]
|
||||
),
|
||||
@ -1391,9 +1393,7 @@ class QuerySet(AltersData):
|
||||
clone._iterable_class = (
|
||||
NamedValuesListIterable
|
||||
if named
|
||||
else FlatValuesListIterable
|
||||
if flat
|
||||
else ValuesListIterable
|
||||
else FlatValuesListIterable if flat else ValuesListIterable
|
||||
)
|
||||
return clone
|
||||
|
||||
@ -1659,9 +1659,11 @@ class QuerySet(AltersData):
|
||||
if names is None:
|
||||
names = set(
|
||||
chain.from_iterable(
|
||||
(
|
||||
(field.name, field.attname)
|
||||
if hasattr(field, "attname")
|
||||
else (field.name,)
|
||||
)
|
||||
for field in self.model._meta.get_fields()
|
||||
)
|
||||
)
|
||||
|
@ -5,6 +5,7 @@ Factored out from django.db.models.query to avoid making the main module very
|
||||
large and/or so that they can be used by other modules without getting into
|
||||
circular import difficulties.
|
||||
"""
|
||||
|
||||
import functools
|
||||
import inspect
|
||||
import logging
|
||||
|
@ -1224,9 +1224,9 @@ class SQLCompiler:
|
||||
"field": f,
|
||||
"reverse": False,
|
||||
"local_setter": f.set_cached_value,
|
||||
"remote_setter": f.remote_field.set_cached_value
|
||||
if f.unique
|
||||
else lambda x, y: None,
|
||||
"remote_setter": (
|
||||
f.remote_field.set_cached_value if f.unique else lambda x, y: None
|
||||
),
|
||||
"from_parent": False,
|
||||
}
|
||||
related_klass_infos.append(klass_info)
|
||||
|
@ -2,6 +2,7 @@
|
||||
Useful auxiliary data structures for query construction. Not useful outside
|
||||
the SQL domain.
|
||||
"""
|
||||
|
||||
import warnings
|
||||
|
||||
from django.core.exceptions import FullResultSet
|
||||
|
@ -6,6 +6,7 @@ themselves do not have to (and could be backed by things other than SQL
|
||||
databases). The abstraction barrier only works one way: this module has to know
|
||||
all about the internals of models in order to get the information it needs.
|
||||
"""
|
||||
|
||||
import copy
|
||||
import difflib
|
||||
import functools
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Code to manage the creation and SQL rendering of 'where' constraints.
|
||||
"""
|
||||
|
||||
import operator
|
||||
from functools import reduce
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
Helper functions for creating Form classes from Django models
|
||||
and database field objects.
|
||||
"""
|
||||
|
||||
from itertools import chain
|
||||
|
||||
from django.core.exceptions import (
|
||||
@ -830,9 +831,12 @@ class BaseModelFormSet(BaseFormSet, AltersData):
|
||||
)
|
||||
# Reduce Model instances to their primary key values
|
||||
row_data = tuple(
|
||||
d._get_pk_val() if hasattr(d, "_get_pk_val")
|
||||
(
|
||||
d._get_pk_val()
|
||||
if hasattr(d, "_get_pk_val")
|
||||
# Prevent "unhashable type: list" errors later on.
|
||||
else tuple(d) if isinstance(d, list) else d
|
||||
)
|
||||
for d in row_data
|
||||
)
|
||||
if row_data and None not in row_data:
|
||||
|
@ -101,9 +101,11 @@ class Media:
|
||||
|
||||
def render_js(self):
|
||||
return [
|
||||
(
|
||||
path.__html__()
|
||||
if hasattr(path, "__html__")
|
||||
else format_html('<script src="{}"></script>', self.absolute_path(path))
|
||||
)
|
||||
for path in self._js
|
||||
]
|
||||
|
||||
@ -113,6 +115,7 @@ class Media:
|
||||
media = sorted(self._css)
|
||||
return chain.from_iterable(
|
||||
[
|
||||
(
|
||||
path.__html__()
|
||||
if hasattr(path, "__html__")
|
||||
else format_html(
|
||||
@ -120,6 +123,7 @@ class Media:
|
||||
self.absolute_path(path),
|
||||
medium,
|
||||
)
|
||||
)
|
||||
for path in self._css[medium]
|
||||
]
|
||||
for medium in media
|
||||
|
@ -4,6 +4,7 @@ Multi-part parsing for file uploads.
|
||||
Exposes one class, ``MultiPartParser``, which feeds chunks of uploaded data to
|
||||
file upload handlers for processing.
|
||||
"""
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
import collections
|
||||
|
@ -170,9 +170,11 @@ class HttpRequest:
|
||||
return "%s%s%s" % (
|
||||
escape_uri_path(path),
|
||||
"/" if force_append_slash and not path.endswith("/") else "",
|
||||
(
|
||||
("?" + iri_to_uri(self.META.get("QUERY_STRING", "")))
|
||||
if self.META.get("QUERY_STRING", "")
|
||||
else "",
|
||||
else ""
|
||||
),
|
||||
)
|
||||
|
||||
def get_signed_cookie(self, key, default=RAISE_ERROR, salt="", max_age=None):
|
||||
|
@ -4,6 +4,7 @@ Cross Site Request Forgery Middleware.
|
||||
This module provides a middleware that implements protection
|
||||
against request forgeries from other sites.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import string
|
||||
from collections import defaultdict
|
||||
|
@ -3,6 +3,7 @@ This module collects helper functions and classes that "span" multiple levels
|
||||
of MVC. In other words, these functions/classes introduce controlled coupling
|
||||
for convenience's sake.
|
||||
"""
|
||||
|
||||
from django.http import (
|
||||
Http404,
|
||||
HttpResponse,
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Default variable filters."""
|
||||
|
||||
import random as random_module
|
||||
import re
|
||||
import types
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Default tags used by the template system, available to all templates."""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import warnings
|
||||
|
@ -70,9 +70,11 @@ class Engine:
|
||||
self.__class__.__qualname__,
|
||||
"" if not self.dirs else " dirs=%s" % repr(self.dirs),
|
||||
self.app_dirs,
|
||||
(
|
||||
""
|
||||
if not self.context_processors
|
||||
else " context_processors=%s" % repr(self.context_processors),
|
||||
else " context_processors=%s" % repr(self.context_processors)
|
||||
),
|
||||
self.debug,
|
||||
repr(self.loaders),
|
||||
repr(self.string_if_invalid),
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Parser and utilities for the smart 'if' tag
|
||||
"""
|
||||
|
||||
# Using a simple top down parser, as described here:
|
||||
# http://effbot.org/zone/simple-top-down-parsing.htm.
|
||||
# 'led' = left denotation
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Compare two HTML documents."""
|
||||
|
||||
import html
|
||||
from html.parser import HTMLParser
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Functions for use in URLsconfs."""
|
||||
|
||||
from functools import partial
|
||||
from importlib import import_module
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user