diff --git a/AUTHORS b/AUTHORS index d43715f119..a2a0eb979a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -264,6 +264,7 @@ answer newbie questions, and generally made Django that much better: David Gouldin pradeep.gowda@gmail.com Collin Grady + Luke Granger-Brown Gabriel Grant Martin Green Daniel Greenfeld @@ -348,6 +349,7 @@ answer newbie questions, and generally made Django that much better: Cameron Knight (ckknight) Nena Kojadin Igor Kolar + Wiktor Kołodziej Tomáš Kopeček Gasper Koren Mikhail Korobov diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py index a4c5828f37..f67599a432 100644 --- a/django/contrib/admin/actions.py +++ b/django/contrib/admin/actions.py @@ -5,7 +5,7 @@ Built-in, globally-available admin actions. from django.core.exceptions import PermissionDenied from django.contrib import messages from django.contrib.admin import helpers -from django.contrib.admin.util import get_deleted_objects, model_ngettext +from django.contrib.admin.utils import get_deleted_objects, model_ngettext from django.db import router from django.template.response import TemplateResponse from django.utils.encoding import force_text diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py index 7bba3a797f..4f04a474dd 100644 --- a/django/contrib/admin/filters.py +++ b/django/contrib/admin/filters.py @@ -12,7 +12,7 @@ from django.core.exceptions import ImproperlyConfigured, ValidationError from django.utils.encoding import smart_text, force_text from django.utils.translation import ugettext_lazy as _ from django.utils import timezone -from django.contrib.admin.util import (get_model_from_relation, +from django.contrib.admin.utils import (get_model_from_relation, reverse_field_path, get_limit_choices_to_from_path, prepare_lookup_value) from django.contrib.admin.options import IncorrectLookupParameters diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index a91988bc47..cd784f5cbd 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -1,13 +1,13 @@ from __future__ import unicode_literals from django import forms -from django.contrib.admin.util import (flatten_fieldsets, lookup_field, +from django.contrib.admin.utils import (flatten_fieldsets, lookup_field, display_for_field, label_for_field, help_text_for_field) from django.contrib.admin.templatetags.admin_static import static from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.db.models.fields.related import ManyToManyRel -from django.forms.util import flatatt +from django.forms.utils import flatatt from django.template.defaultfilters import capfirst from django.utils.encoding import force_text, smart_text from django.utils.html import conditional_escape, format_html @@ -308,7 +308,7 @@ class InlineFieldset(Fieldset): yield Fieldline(self.form, field, self.readonly_fields, model_admin=self.model_admin) -class AdminErrorList(forms.util.ErrorList): +class AdminErrorList(forms.utils.ErrorList): """ Stores all errors for the form/formsets in an add/change stage view. """ diff --git a/django/contrib/admin/models.py b/django/contrib/admin/models.py index dc282b7e57..870c2b27a1 100644 --- a/django/contrib/admin/models.py +++ b/django/contrib/admin/models.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from django.db import models from django.conf import settings from django.contrib.contenttypes.models import ContentType -from django.contrib.admin.util import quote +from django.contrib.admin.utils import quote from django.core.urlresolvers import reverse, NoReverseMatch from django.utils.translation import ugettext, ugettext_lazy as _ from django.utils.encoding import smart_text diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 1b215879d1..937bbd1ebb 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -8,7 +8,7 @@ from django import forms from django.conf import settings from django.contrib import messages from django.contrib.admin import widgets, helpers -from django.contrib.admin.util import (unquote, flatten_fieldsets, get_deleted_objects, +from django.contrib.admin.utils import (unquote, flatten_fieldsets, get_deleted_objects, model_format_dict, NestedObjects, lookup_needs_distinct) from django.contrib.admin import validation from django.contrib.admin.templatetags.admin_static import static diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index ba109d1454..2b1fd8ad34 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import datetime from django.contrib.admin.templatetags.admin_urls import add_preserved_filters -from django.contrib.admin.util import (lookup_field, display_for_field, +from django.contrib.admin.utils import (lookup_field, display_for_field, display_for_value, label_for_field) from django.contrib.admin.views.main import (ALL_VAR, EMPTY_CHANGELIST_VALUE, ORDER_VAR, PAGE_VAR, SEARCH_VAR) diff --git a/django/contrib/admin/templatetags/admin_urls.py b/django/contrib/admin/templatetags/admin_urls.py index fd45bf306a..68c7083ecf 100644 --- a/django/contrib/admin/templatetags/admin_urls.py +++ b/django/contrib/admin/templatetags/admin_urls.py @@ -4,7 +4,7 @@ except ImportError: from urlparse import parse_qsl, urlparse, urlunparse from django import template -from django.contrib.admin.util import quote +from django.contrib.admin.utils import quote from django.core.urlresolvers import resolve, Resolver404 from django.utils.http import urlencode diff --git a/django/contrib/admin/util.py b/django/contrib/admin/utils.py similarity index 100% rename from django/contrib/admin/util.py rename to django/contrib/admin/utils.py diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index fb9634d114..495f72f727 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -2,7 +2,7 @@ from django.core.exceptions import ImproperlyConfigured from django.db import models from django.db.models.fields import FieldDoesNotExist from django.forms.models import BaseModelForm, BaseModelFormSet, _get_foreign_key -from django.contrib.admin.util import get_fields_from_path, NotRelationField +from django.contrib.admin.utils import get_fields_from_path, NotRelationField """ Does basic ModelAdmin option validation. Calls custom validation diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 14f7655251..cea0cba2b8 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -16,7 +16,7 @@ from django.utils.http import urlencode from django.contrib.admin import FieldListFilter from django.contrib.admin.exceptions import DisallowedModelAdminLookup from django.contrib.admin.options import IncorrectLookupParameters, IS_POPUP_VAR, TO_FIELD_VAR -from django.contrib.admin.util import (quote, get_fields_from_path, +from django.contrib.admin.utils import (quote, get_fields_from_path, lookup_needs_distinct, prepare_lookup_value) # Changelist settings diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index fe6c9e13a9..2d50f47396 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -9,7 +9,7 @@ from django import forms from django.contrib.admin.templatetags.admin_static import static from django.core.urlresolvers import reverse from django.forms.widgets import RadioFieldRenderer -from django.forms.util import flatatt +from django.forms.utils import flatatt from django.utils.html import escape, format_html, format_html_join, smart_urlquote from django.utils.text import Truncator from django.utils.translation import ugettext as _ diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 98956771b3..5019e9ab9e 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from collections import OrderedDict from django import forms -from django.forms.util import flatatt +from django.forms.utils import flatatt from django.template import loader from django.utils.encoding import force_bytes from django.utils.html import format_html, format_html_join diff --git a/django/contrib/comments/forms.py b/django/contrib/comments/forms.py index bd254d2733..17d2ef8f09 100644 --- a/django/contrib/comments/forms.py +++ b/django/contrib/comments/forms.py @@ -1,6 +1,6 @@ import time from django import forms -from django.forms.util import ErrorDict +from django.forms.utils import ErrorDict from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.contrib.comments.models import Comment diff --git a/django/contrib/gis/db/backends/oracle/creation.py b/django/contrib/gis/db/backends/oracle/creation.py index 043da916f5..14f8d4d150 100644 --- a/django/contrib/gis/db/backends/oracle/creation.py +++ b/django/contrib/gis/db/backends/oracle/creation.py @@ -1,5 +1,5 @@ from django.db.backends.oracle.creation import DatabaseCreation -from django.db.backends.util import truncate_name +from django.db.backends.utils import truncate_name class OracleCreation(DatabaseCreation): diff --git a/django/contrib/gis/db/backends/oracle/operations.py b/django/contrib/gis/db/backends/oracle/operations.py index 628018320b..a8f798d300 100644 --- a/django/contrib/gis/db/backends/oracle/operations.py +++ b/django/contrib/gis/db/backends/oracle/operations.py @@ -13,7 +13,7 @@ from decimal import Decimal from django.db.backends.oracle.base import DatabaseOperations from django.contrib.gis.db.backends.base import BaseSpatialOperations from django.contrib.gis.db.backends.oracle.adapter import OracleSpatialAdapter -from django.contrib.gis.db.backends.util import SpatialFunction +from django.contrib.gis.db.backends.utils import SpatialFunction from django.contrib.gis.geometry.backend import Geometry from django.contrib.gis.measure import Distance from django.utils import six diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py index 3863bea992..0bff02cd11 100644 --- a/django/contrib/gis/db/backends/postgis/operations.py +++ b/django/contrib/gis/db/backends/postgis/operations.py @@ -3,7 +3,7 @@ from decimal import Decimal from django.conf import settings from django.contrib.gis.db.backends.base import BaseSpatialOperations -from django.contrib.gis.db.backends.util import SpatialOperation, SpatialFunction +from django.contrib.gis.db.backends.utils import SpatialOperation, SpatialFunction from django.contrib.gis.db.backends.postgis.adapter import PostGISAdapter from django.contrib.gis.geometry.backend import Geometry from django.contrib.gis.measure import Distance diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py index 3cb2004dfd..b20b1b9157 100644 --- a/django/contrib/gis/db/backends/spatialite/operations.py +++ b/django/contrib/gis/db/backends/spatialite/operations.py @@ -3,7 +3,7 @@ import sys from decimal import Decimal from django.contrib.gis.db.backends.base import BaseSpatialOperations -from django.contrib.gis.db.backends.util import SpatialOperation, SpatialFunction +from django.contrib.gis.db.backends.utils import SpatialOperation, SpatialFunction from django.contrib.gis.db.backends.spatialite.adapter import SpatiaLiteAdapter from django.contrib.gis.geometry.backend import Geometry from django.contrib.gis.measure import Distance diff --git a/django/contrib/gis/db/backends/util.py b/django/contrib/gis/db/backends/utils.py similarity index 100% rename from django/contrib/gis/db/backends/util.py rename to django/contrib/gis/db/backends/utils.py diff --git a/django/contrib/gis/db/models/sql/compiler.py b/django/contrib/gis/db/models/sql/compiler.py index b89df0ae95..94ce30ba5d 100644 --- a/django/contrib/gis/db/models/sql/compiler.py +++ b/django/contrib/gis/db/models/sql/compiler.py @@ -1,7 +1,7 @@ import datetime from django.conf import settings -from django.db.backends.util import truncate_name, typecast_date, typecast_timestamp +from django.db.backends.utils import truncate_name, typecast_date, typecast_timestamp from django.db.models.sql import compiler from django.db.models.sql.constants import MULTI from django.utils import six diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 44024c5349..49d6b80ae4 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -14,7 +14,7 @@ from importlib import import_module from django.conf import settings from django.db import DEFAULT_DB_ALIAS from django.db.backends.signals import connection_created -from django.db.backends import util +from django.db.backends import utils from django.db.transaction import TransactionManagementError from django.db.utils import DatabaseErrorWrapper from django.utils.functional import cached_property @@ -158,7 +158,7 @@ class BaseDatabaseWrapper(object): (self.use_debug_cursor is None and settings.DEBUG)): cursor = self.make_debug_cursor(self._cursor()) else: - cursor = util.CursorWrapper(self._cursor(), self) + cursor = utils.CursorWrapper(self._cursor(), self) return cursor def commit(self): @@ -495,7 +495,7 @@ class BaseDatabaseWrapper(object): """ Creates a cursor that logs all queries in self.queries. """ - return util.CursorDebugWrapper(cursor, self) + return utils.CursorDebugWrapper(cursor, self) @contextmanager def temporary_connection(self): @@ -1131,7 +1131,7 @@ class BaseDatabaseOperations(object): """ if value is None: return None - return util.format_number(value, max_digits, decimal_places) + return utils.format_number(value, max_digits, decimal_places) def year_lookup_bounds_for_date_field(self, value): """ diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py index eba3952d0f..9c700c96b2 100644 --- a/django/db/backends/creation.py +++ b/django/db/backends/creation.py @@ -8,7 +8,7 @@ from django.db.utils import load_backend from django.utils.encoding import force_bytes from django.utils.six.moves import input -from .util import truncate_name +from .utils import truncate_name # The prefix to put on the default database name when creating # the test database. diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index a5fcead7fb..2d33f45705 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -37,7 +37,7 @@ except ImportError: from django.conf import settings from django.db import utils -from django.db.backends import (util, BaseDatabaseFeatures, +from django.db.backends import (utils as backend_utils, BaseDatabaseFeatures, BaseDatabaseOperations, BaseDatabaseWrapper) from django.db.backends.mysql.client import DatabaseClient from django.db.backends.mysql.creation import DatabaseCreation @@ -91,9 +91,9 @@ def adapt_datetime_with_timezone_support(value, conv): # timezone support is active, Django expects timezone-aware datetime objects. django_conversions = conversions.copy() django_conversions.update({ - FIELD_TYPE.TIME: util.typecast_time, - FIELD_TYPE.DECIMAL: util.typecast_decimal, - FIELD_TYPE.NEWDECIMAL: util.typecast_decimal, + FIELD_TYPE.TIME: backend_utils.typecast_time, + FIELD_TYPE.DECIMAL: backend_utils.typecast_decimal, + FIELD_TYPE.NEWDECIMAL: backend_utils.typecast_decimal, FIELD_TYPE.DATETIME: parse_datetime_with_timezone_support, datetime.datetime: adapt_datetime_with_timezone_support, }) @@ -109,7 +109,7 @@ server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})') # MySQL-4.1 and newer, so the MysqlDebugWrapper is unnecessary. Since the # point is to raise Warnings as exceptions, this can be done with the Python # warning module, and this is setup when the connection is created, and the -# standard util.CursorDebugWrapper can be used. Also, using sql_mode +# standard backend_utils.CursorDebugWrapper can be used. Also, using sql_mode # TRADITIONAL will automatically cause most warnings to be treated as errors. class CursorWrapper(object): diff --git a/django/db/backends/mysql/creation.py b/django/db/backends/mysql/creation.py index b59b225f4f..b15c3371fb 100644 --- a/django/db/backends/mysql/creation.py +++ b/django/db/backends/mysql/creation.py @@ -61,7 +61,7 @@ class DatabaseCreation(BaseDatabaseCreation): index_name = "%s_%s" % (model._meta.db_table, self._digest([f.name for f in fields])) - from ..util import truncate_name + from ..utils import truncate_name return [ style.SQL_KEYWORD("DROP INDEX") + " " + diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index c9b3fbfd27..eead105b24 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -53,7 +53,8 @@ except ImportError: from django.conf import settings from django.db import utils -from django.db.backends import BaseDatabaseFeatures, BaseDatabaseOperations, BaseDatabaseWrapper, BaseDatabaseValidation, util +from django.db.backends import (BaseDatabaseFeatures, BaseDatabaseOperations, + BaseDatabaseWrapper, BaseDatabaseValidation, utils as backend_utils) from django.db.backends.oracle.client import DatabaseClient from django.db.backends.oracle.creation import DatabaseCreation from django.db.backends.oracle.introspection import DatabaseIntrospection @@ -239,7 +240,7 @@ WHEN (new.%(col_name)s IS NULL) value = float(value) # Convert floats to decimals elif value is not None and field and field.get_internal_type() == 'DecimalField': - value = util.typecast_decimal(field.format_number(value)) + value = backend_utils.typecast_decimal(field.format_number(value)) # cx_Oracle always returns datetime.datetime objects for # DATE and TIMESTAMP columns, but Django wants to see a # python datetime.date, .time, or .datetime. We use the type @@ -316,7 +317,7 @@ WHEN (new.%(col_name)s IS NULL) # always defaults to uppercase. # We simplify things by making Oracle identifiers always uppercase. if not name.startswith('"') and not name.endswith('"'): - name = '"%s"' % util.truncate_name(name.upper(), + name = '"%s"' % backend_utils.truncate_name(name.upper(), self.max_name_length()) # Oracle puts the query text into a (query % args) construct, so % signs # in names need to be escaped. The '%%' will be collapsed back to '%' at @@ -482,11 +483,11 @@ WHEN (new.%(col_name)s IS NULL) def _get_sequence_name(self, table): name_length = self.max_name_length() - 3 - return '%s_SQ' % util.truncate_name(table, name_length).upper() + return '%s_SQ' % backend_utils.truncate_name(table, name_length).upper() def _get_trigger_name(self, table): name_length = self.max_name_length() - 3 - return '%s_TR' % util.truncate_name(table, name_length).upper() + return '%s_TR' % backend_utils.truncate_name(table, name_length).upper() def bulk_insert_sql(self, fields, num_values): items_sql = "SELECT %s FROM DUAL" % ", ".join(["%s"] * len(fields)) diff --git a/django/db/backends/postgresql_psycopg2/creation.py b/django/db/backends/postgresql_psycopg2/creation.py index 954e198764..c66b6c6f55 100644 --- a/django/db/backends/postgresql_psycopg2/creation.py +++ b/django/db/backends/postgresql_psycopg2/creation.py @@ -1,5 +1,5 @@ from django.db.backends.creation import BaseDatabaseCreation -from django.db.backends.util import truncate_name +from django.db.backends.utils import truncate_name class DatabaseCreation(BaseDatabaseCreation): diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py index bc529f47e0..9568400556 100644 --- a/django/db/backends/schema.py +++ b/django/db/backends/schema.py @@ -2,7 +2,7 @@ import hashlib import operator from django.db.backends.creation import BaseDatabaseCreation -from django.db.backends.util import truncate_name +from django.db.backends.utils import truncate_name from django.db.models.fields.related import ManyToManyField from django.db.transaction import atomic from django.utils.log import getLogger diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 8641207aec..80d88c5cab 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -13,7 +13,7 @@ import re from django.conf import settings from django.db import utils -from django.db.backends import (util, BaseDatabaseFeatures, +from django.db.backends import (utils as backend_utils, BaseDatabaseFeatures, BaseDatabaseOperations, BaseDatabaseWrapper, BaseDatabaseValidation) from django.db.backends.sqlite3.client import DatabaseClient from django.db.backends.sqlite3.creation import DatabaseCreation @@ -80,10 +80,10 @@ Database.register_converter(str("date"), decoder(parse_date)) Database.register_converter(str("datetime"), decoder(parse_datetime_with_timezone_support)) Database.register_converter(str("timestamp"), decoder(parse_datetime_with_timezone_support)) Database.register_converter(str("TIMESTAMP"), decoder(parse_datetime_with_timezone_support)) -Database.register_converter(str("decimal"), decoder(util.typecast_decimal)) +Database.register_converter(str("decimal"), decoder(backend_utils.typecast_decimal)) Database.register_adapter(datetime.datetime, adapt_datetime_with_timezone_support) -Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal) +Database.register_adapter(decimal.Decimal, backend_utils.rev_typecast_decimal) if six.PY2: Database.register_adapter(str, lambda s: s.decode('utf-8')) Database.register_adapter(SafeBytes, lambda s: s.decode('utf-8')) @@ -282,7 +282,7 @@ class DatabaseOperations(BaseDatabaseOperations): internal_type = field.get_internal_type() if internal_type == 'DecimalField': - return util.typecast_decimal(field.format_number(value)) + return backend_utils.typecast_decimal(field.format_number(value)) elif internal_type and internal_type.endswith('IntegerField') or internal_type == 'AutoField': return int(value) elif internal_type == 'DateField': @@ -487,7 +487,7 @@ def _sqlite_date_extract(lookup_type, dt): if dt is None: return None try: - dt = util.typecast_timestamp(dt) + dt = backend_utils.typecast_timestamp(dt) except (ValueError, TypeError): return None if lookup_type == 'week_day': @@ -498,7 +498,7 @@ def _sqlite_date_extract(lookup_type, dt): def _sqlite_date_trunc(lookup_type, dt): try: - dt = util.typecast_timestamp(dt) + dt = backend_utils.typecast_timestamp(dt) except (ValueError, TypeError): return None if lookup_type == 'year': @@ -513,7 +513,7 @@ def _sqlite_datetime_extract(lookup_type, dt, tzname): if dt is None: return None try: - dt = util.typecast_timestamp(dt) + dt = backend_utils.typecast_timestamp(dt) except (ValueError, TypeError): return None if tzname is not None: @@ -526,7 +526,7 @@ def _sqlite_datetime_extract(lookup_type, dt, tzname): def _sqlite_datetime_trunc(lookup_type, dt, tzname): try: - dt = util.typecast_timestamp(dt) + dt = backend_utils.typecast_timestamp(dt) except (ValueError, TypeError): return None if tzname is not None: @@ -547,7 +547,7 @@ def _sqlite_datetime_trunc(lookup_type, dt, tzname): def _sqlite_format_dtdelta(dt, conn, days, secs, usecs): try: - dt = util.typecast_timestamp(dt) + dt = backend_utils.typecast_timestamp(dt) delta = datetime.timedelta(int(days), int(secs), int(usecs)) if conn.strip() == '+': dt = dt + delta diff --git a/django/db/backends/util.py b/django/db/backends/utils.py similarity index 100% rename from django/db/backends/util.py rename to django/db/backends/utils.py diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 5d74e2002d..e019855826 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1122,14 +1122,14 @@ class DecimalField(Field): Formats a number into a string with the requisite number of digits and decimal places. """ - # Method moved to django.db.backends.util. + # Method moved to django.db.backends.utils. # # It is preserved because it is used by the oracle backend # (django.db.backends.oracle.query), and also for # backwards-compatibility with any external code which may have used # this method. - from django.db.backends import util - return util.format_number(value, self.max_digits, self.decimal_places) + from django.db.backends import utils + return utils.format_number(value, self.max_digits, self.decimal_places) def get_db_prep_save(self, value, connection): return connection.ops.value_to_db_decimal(self.to_python(value), diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 4caed4f559..fd9e8fa4d8 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -1,7 +1,7 @@ from operator import attrgetter from django.db import connection, connections, router -from django.db.backends import util +from django.db.backends import utils from django.db.models import signals from django.db.models.fields import (AutoField, Field, IntegerField, PositiveIntegerField, PositiveSmallIntegerField, FieldDoesNotExist) @@ -1440,7 +1440,7 @@ class ManyToManyField(RelatedField): elif self.db_table: return self.db_table else: - return util.truncate_name('%s_%s' % (opts.db_table, self.name), + return utils.truncate_name('%s_%s' % (opts.db_table, self.name), connection.ops.max_name_length()) def _get_m2m_attr(self, related, attr): diff --git a/django/db/models/options.py b/django/db/models/options.py index c89270eabb..8e0e1a2210 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -77,7 +77,7 @@ class Options(object): def contribute_to_class(self, cls, name): from django.db import connection - from django.db.backends.util import truncate_name + from django.db.backends.utils import truncate_name cls._meta = self self.model = cls diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 2a92978beb..a7d98f60fe 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -7,7 +7,7 @@ circular import difficulties. """ from __future__ import unicode_literals -from django.db.backends import util +from django.db.backends import utils from django.utils import six from django.utils import tree @@ -194,7 +194,7 @@ def deferred_class_factory(model, attrs): # name using the passed in attrs. It's OK to reuse an existing class # object if the attrs are identical. name = "%s_Deferred_%s" % (model.__name__, '_'.join(sorted(list(attrs)))) - name = util.truncate_name(name, 80, 32) + name = utils.truncate_name(name, 80, 32) overrides = dict((attr, DeferredAttribute(attr, model)) for attr in attrs) overrides["Meta"] = Meta diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index c42149e45a..ba2c6c91b3 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -2,7 +2,7 @@ import datetime from django.conf import settings from django.core.exceptions import FieldError -from django.db.backends.util import truncate_name +from django.db.backends.utils import truncate_name from django.db.models.constants import LOOKUP_SEP from django.db.models.query_utils import select_related_descend, QueryWrapper from django.db.models.sql.constants import (SINGLE, MULTI, ORDER_DIR, @@ -1049,7 +1049,7 @@ class SQLDateCompiler(SQLCompiler): from django.db.models.fields import DateField fields = [DateField()] else: - from django.db.backends.util import typecast_date + from django.db.backends.utils import typecast_date needs_string_cast = self.connection.features.needs_datetime_string_cast offset = len(self.query.extra_select) @@ -1075,7 +1075,7 @@ class SQLDateTimeCompiler(SQLCompiler): from django.db.models.fields import DateTimeField fields = [DateTimeField()] else: - from django.db.backends.util import typecast_timestamp + from django.db.backends.utils import typecast_timestamp needs_string_cast = self.connection.features.needs_datetime_string_cast offset = len(self.query.extra_select) diff --git a/django/forms/fields.py b/django/forms/fields.py index 80550c232b..d90b8dbb51 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -14,7 +14,7 @@ from io import BytesIO from django.core import validators from django.core.exceptions import ValidationError -from django.forms.util import ErrorList, from_current_timezone, to_current_timezone +from django.forms.utils import ErrorList, from_current_timezone, to_current_timezone from django.forms.widgets import ( TextInput, NumberInput, EmailInput, URLInput, HiddenInput, MultipleHiddenInput, ClearableFileInput, CheckboxInput, Select, diff --git a/django/forms/forms.py b/django/forms/forms.py index e04d6a0781..64d1550066 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -10,7 +10,7 @@ import warnings from django.core.exceptions import ValidationError from django.forms.fields import Field, FileField -from django.forms.util import flatatt, ErrorDict, ErrorList +from django.forms.utils import flatatt, ErrorDict, ErrorList from django.forms.widgets import Media, media_property, TextInput, Textarea from django.utils.html import conditional_escape, format_html from django.utils.encoding import smart_text, force_text, python_2_unicode_compatible diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 02b07a8604..59bfe33a63 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from django.core.exceptions import ValidationError from django.forms import Form from django.forms.fields import IntegerField, BooleanField -from django.forms.util import ErrorList +from django.forms.utils import ErrorList from django.forms.widgets import HiddenInput from django.utils.encoding import python_2_unicode_compatible from django.utils.functional import cached_property diff --git a/django/forms/models.py b/django/forms/models.py index f292606862..c05c452383 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -12,7 +12,7 @@ from django.core.exceptions import ValidationError, NON_FIELD_ERRORS, FieldError from django.forms.fields import Field, ChoiceField from django.forms.forms import BaseForm, get_declared_fields from django.forms.formsets import BaseFormSet, formset_factory -from django.forms.util import ErrorList +from django.forms.utils import ErrorList from django.forms.widgets import (SelectMultiple, HiddenInput, MultipleHiddenInput, media_property, CheckboxSelectMultiple) from django.utils.encoding import smart_text, force_text diff --git a/django/forms/util.py b/django/forms/utils.py similarity index 100% rename from django/forms/util.py rename to django/forms/utils.py diff --git a/django/forms/widgets.py b/django/forms/widgets.py index ea701bdcf9..372c0f440b 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -9,7 +9,7 @@ from itertools import chain import warnings from django.conf import settings -from django.forms.util import flatatt, to_current_timezone +from django.forms.utils import flatatt, to_current_timezone from django.utils.datastructures import MultiValueDict, MergeDict from django.utils.html import conditional_escape, format_html from django.utils.translation import ugettext_lazy diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 054e3b32fc..9e473dfa46 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -444,6 +444,15 @@ these changes. * ``ModelAdmin.declared_fieldsets`` will be removed. +* Instances of ``util.py`` in the Django codebase have been renamed to + ``utils.py`` in an effort to unify all util and utils references. + The modules that provided backwards compatability will be removed: + + * ``django.contrib.admin.util`` + * ``django.contrib.gis.db.backends.util`` + * ``django.db.backends.util`` + * ``django.forms.util`` + 2.0 --- diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index f084273cd9..977da4b7be 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -571,12 +571,12 @@ method you're using:: Customizing the error list format ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -By default, forms use ``django.forms.util.ErrorList`` to format validation +By default, forms use ``django.forms.utils.ErrorList`` to format validation errors. If you'd like to use an alternate class for displaying errors, you can pass that in at construction time (replace ``__unicode__`` by ``__str__`` on Python 3):: - >>> from django.forms.util import ErrorList + >>> from django.forms.utils import ErrorList >>> class DivErrorList(ErrorList): ... def __unicode__(self): ... return self.as_divs() @@ -592,6 +592,10 @@ Python 3)::

Sender:

Cc myself:

+.. versionchanged:: 1.7 + + ``django.forms.util`` was renamed to ``django.forms.utils``. + More granular output ~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/ref/forms/validation.txt b/docs/ref/forms/validation.txt index b6113098bb..c1e619113c 100644 --- a/docs/ref/forms/validation.txt +++ b/docs/ref/forms/validation.txt @@ -219,10 +219,10 @@ through the ``Form.non_field_errors()`` method. When you really do need to attach the error to a particular field, you should store (or amend) a key in the ``Form._errors`` attribute. This attribute is an -instance of a ``django.forms.util.ErrorDict`` class. Essentially, though, it's +instance of a ``django.forms.utils.ErrorDict`` class. Essentially, though, it's just a dictionary. There is a key in the dictionary for each field in the form that has an error. Each value in the dictionary is a -``django.forms.util.ErrorList`` instance, which is a list that knows how to +``django.forms.utils.ErrorList`` instance, which is a list that knows how to display itself in different ways. So you can treat ``_errors`` as a dictionary mapping field names to lists. diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt index 3e247fd211..685efe04b3 100644 --- a/docs/releases/1.7.txt +++ b/docs/releases/1.7.txt @@ -460,3 +460,14 @@ a bug and has been addressed. The ``syncdb`` command has been deprecated in favour of the new ``migrate`` command. ``migrate`` takes the same arguments as ``syncdb`` used to plus a few more, so it's safe to just change the name you're calling and nothing else. + +``util`` modules renamed to ``utils`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The following instances of ``util.py`` in the Django codebase have been renamed +to ``utils.py`` in an effort to unify all util and utils references: + +* ``django.contrib.admin.util`` +* ``django.contrib.gis.db.backends.util`` +* ``django.db.backends.util`` +* ``django.forms.util`` diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt index 8be6e10ff6..384187bdaf 100644 --- a/docs/topics/forms/formsets.txt +++ b/docs/topics/forms/formsets.txt @@ -215,7 +215,7 @@ this management data, an exception will be raised:: >>> formset = ArticleFormSet(data) Traceback (most recent call last): ... - django.forms.util.ValidationError: [u'ManagementForm data is missing or has been tampered with'] + django.forms.utils.ValidationError: [u'ManagementForm data is missing or has been tampered with'] It is used to keep track of how many form instances are being displayed. If you are adding new forms via JavaScript, you should increment the count fields diff --git a/tests/admin_custom_urls/tests.py b/tests/admin_custom_urls/tests.py index 257638afb1..1dc9da7efd 100644 --- a/tests/admin_custom_urls/tests.py +++ b/tests/admin_custom_urls/tests.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals import warnings -from django.contrib.admin.util import quote +from django.contrib.admin.utils import quote from django.core.urlresolvers import reverse from django.template.response import TemplateResponse from django.test import TestCase diff --git a/tests/admin_util/tests.py b/tests/admin_util/tests.py index 8c63e90ce1..31bb412af4 100644 --- a/tests/admin_util/tests.py +++ b/tests/admin_util/tests.py @@ -5,7 +5,7 @@ from datetime import datetime from django.conf import settings from django.contrib import admin from django.contrib.admin import helpers -from django.contrib.admin.util import (display_for_field, flatten_fieldsets, +from django.contrib.admin.utils import (display_for_field, flatten_fieldsets, label_for_field, lookup_field, NestedObjects) from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE from django.contrib.sites.models import Site diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index 5649a3c492..8d864378ce 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -768,7 +768,7 @@ site.register(UnchangeableObject, UnchangeableObjectAdmin) # related OneToOne object not registered in admin # when deleting Book so as exercise all four troublesome (w.r.t escaping # and calling force_text to avoid problems on Python 2.3) paths through -# contrib.admin.util's get_deleted_objects function. +# contrib.admin.utils's get_deleted_objects function. site.register(Book, inlines=[ChapterInline]) site.register(Promo) site.register(ChapterXtra1, ChapterXtra1Admin) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 75e8a51acd..4793a27f23 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -15,14 +15,14 @@ from django.contrib.auth import get_permission_codename from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME from django.contrib.admin.models import LogEntry, DELETION from django.contrib.admin.sites import LOGIN_FORM_KEY -from django.contrib.admin.util import quote +from django.contrib.admin.utils import quote from django.contrib.admin.views.main import IS_POPUP_VAR from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase from django.contrib.auth import REDIRECT_FIELD_NAME from django.contrib.auth.models import Group, User, Permission from django.contrib.contenttypes.models import ContentType from django.db import connection -from django.forms.util import ErrorList +from django.forms.utils import ErrorList from django.template.response import TemplateResponse from django.test import TestCase from django.test.utils import patch_logger diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 903aedec20..a6badac9a9 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -15,7 +15,7 @@ from django.db import (connection, connections, DEFAULT_DB_ALIAS, from django.db.backends.signals import connection_created from django.db.backends.sqlite3.base import DatabaseOperations from django.db.backends.postgresql_psycopg2 import version as pg_version -from django.db.backends.util import format_number +from django.db.backends.utils import format_number from django.db.models import Sum, Avg, Variance, StdDev from django.db.models.fields import (AutoField, DateField, DateTimeField, DecimalField, IntegerField, TimeField) diff --git a/tests/db_typecasts/tests.py b/tests/db_typecasts/tests.py index fc5305dcdd..27b89c0c8c 100644 --- a/tests/db_typecasts/tests.py +++ b/tests/db_typecasts/tests.py @@ -3,7 +3,7 @@ import datetime import unittest -from django.db.backends import util as typecasts +from django.db.backends import utils as typecasts from django.utils import six diff --git a/tests/forms_tests/tests/test_error_messages.py b/tests/forms_tests/tests/test_error_messages.py index 2b1bec1647..a884bdc75b 100644 --- a/tests/forms_tests/tests/test_error_messages.py +++ b/tests/forms_tests/tests/test_error_messages.py @@ -215,7 +215,7 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin): raise ValidationError("I like to be awkward.") @python_2_unicode_compatible - class CustomErrorList(util.ErrorList): + class CustomErrorList(utils.ErrorList): def __str__(self): return self.as_divs() diff --git a/tests/forms_tests/tests/test_extra.py b/tests/forms_tests/tests/test_extra.py index 21186682d5..d0409155dd 100644 --- a/tests/forms_tests/tests/test_extra.py +++ b/tests/forms_tests/tests/test_extra.py @@ -5,7 +5,7 @@ import datetime from django.forms import * from django.forms.extras import SelectDateWidget -from django.forms.util import ErrorList +from django.forms.utils import ErrorList from django.test import TestCase from django.test.utils import override_settings from django.utils import six diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py index 6f305d78c4..990aa9d1f9 100644 --- a/tests/forms_tests/tests/test_fields.py +++ b/tests/forms_tests/tests/test_fields.py @@ -1142,7 +1142,7 @@ class FieldsTests(SimpleTestCase): ('/django/forms/forms.py', 'forms.py'), ('/django/forms/formsets.py', 'formsets.py'), ('/django/forms/models.py', 'models.py'), - ('/django/forms/util.py', 'util.py'), + ('/django/forms/utils.py', 'utils.py'), ('/django/forms/widgets.py', 'widgets.py') ] for exp, got in zip(expected, fix_os_paths(f.choices)): @@ -1162,7 +1162,7 @@ class FieldsTests(SimpleTestCase): ('/django/forms/forms.py', 'forms.py'), ('/django/forms/formsets.py', 'formsets.py'), ('/django/forms/models.py', 'models.py'), - ('/django/forms/util.py', 'util.py'), + ('/django/forms/utils.py', 'utils.py'), ('/django/forms/widgets.py', 'widgets.py') ] for exp, got in zip(expected, fix_os_paths(f.choices)): @@ -1182,7 +1182,7 @@ class FieldsTests(SimpleTestCase): ('/django/forms/forms.py', 'forms.py'), ('/django/forms/formsets.py', 'formsets.py'), ('/django/forms/models.py', 'models.py'), - ('/django/forms/util.py', 'util.py'), + ('/django/forms/utils.py', 'utils.py'), ('/django/forms/widgets.py', 'widgets.py') ] for exp, got in zip(expected, fix_os_paths(f.choices)): diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index bd34babef6..12d68283cb 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -6,7 +6,7 @@ import datetime from django.forms import (CharField, DateField, FileField, Form, IntegerField, SplitDateTimeField, ValidationError, formsets) from django.forms.formsets import BaseFormSet, formset_factory -from django.forms.util import ErrorList +from django.forms.utils import ErrorList from django.test import TestCase diff --git a/tests/forms_tests/tests/test_util.py b/tests/forms_tests/tests/test_util.py index c2d213ae23..87f9f0d048 100644 --- a/tests/forms_tests/tests/test_util.py +++ b/tests/forms_tests/tests/test_util.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django.core.exceptions import ValidationError -from django.forms.util import flatatt, ErrorDict, ErrorList +from django.forms.utils import flatatt, ErrorDict, ErrorList from django.test import TestCase from django.utils.safestring import mark_safe from django.utils import six @@ -11,7 +11,7 @@ from django.utils.encoding import python_2_unicode_compatible class FormsUtilTestCase(TestCase): - # Tests for forms/util.py module. + # Tests for forms/utils.py module. def test_flatatt(self): ########### diff --git a/tests/model_formsets_regress/tests.py b/tests/model_formsets_regress/tests.py index 782c7d6fbc..6715b5b10e 100644 --- a/tests/model_formsets_regress/tests.py +++ b/tests/model_formsets_regress/tests.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django import forms from django.forms.formsets import BaseFormSet, DELETION_FIELD_NAME -from django.forms.util import ErrorDict, ErrorList +from django.forms.utils import ErrorDict, ErrorList from django.forms.models import modelform_factory, inlineformset_factory, modelformset_factory, BaseModelFormSet from django.test import TestCase from django.utils import six diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py index f9cb132225..988996c9f1 100644 --- a/tests/proxy_models/tests.py +++ b/tests/proxy_models/tests.py @@ -382,7 +382,7 @@ class ProxyModelAdminTests(TestCase): base_user = BaseUser.objects.all()[0] issue = Issue.objects.all()[0] with self.assertNumQueries(7): - collector = admin.util.NestedObjects('default') + collector = admin.utils.NestedObjects('default') collector.collect(ProxyTrackerUser.objects.all()) self.assertTrue(tracker_user in collector.edges.get(None, ())) self.assertTrue(base_user in collector.edges.get(None, ()))