Fixed #17627 -- Renamed util.py files to utils.py

Thanks PaulM for the suggestion and Luke Granger-Brown and
Wiktor Kołodziej for the initial patch.
This commit is contained in:
Tim Graham 2013-09-16 12:52:05 -04:00
parent 8d29005524
commit 18ffdb1772
58 changed files with 111 additions and 84 deletions

View File

@ -264,6 +264,7 @@ answer newbie questions, and generally made Django that much better:
David Gouldin <dgouldin@gmail.com>
pradeep.gowda@gmail.com
Collin Grady <collin@collingrady.com>
Luke Granger-Brown <django@lukegb.com>
Gabriel Grant <g@briel.ca>
Martin Green
Daniel Greenfeld
@ -348,6 +349,7 @@ answer newbie questions, and generally made Django that much better:
Cameron Knight (ckknight)
Nena Kojadin <nena@kiberpipa.org>
Igor Kolar <ike@email.si>
Wiktor Kołodziej
Tomáš Kopeček <permonik@m6.cz>
Gasper Koren
Mikhail Korobov <kmike84@googlemail.com>

View File

@ -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

View File

@ -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

View File

@ -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.
"""

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 _

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):
"""

View File

@ -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.

View File

@ -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):

View File

@ -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") + " " +

View File

@ -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))

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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),

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
---

View File

@ -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)::
<p>Sender: <input type="email" name="sender" value="invalid email address" /></p>
<p>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p>
.. versionchanged:: 1.7
``django.forms.util`` was renamed to ``django.forms.utils``.
More granular output
~~~~~~~~~~~~~~~~~~~~

View File

@ -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.

View File

@ -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``

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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)):

View File

@ -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

View File

@ -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):
###########

View File

@ -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

View File

@ -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, ()))