Permalink
Browse files

Fixed #2101 -- Renamed `maxlength` argument to `max_length` for oldfo…

…rms `FormField`s and db model `Field`s. This is fully backwards compatible at the moment since the legacy `maxlength` argument is still supported. Using `maxlength` will, however, issue a `PendingDeprecationWarning` when used.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5803 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 973f44a commit 212ee65be782240554749f25bbd3772240d56fff @gdub gdub committed Aug 5, 2007
Showing with 647 additions and 407 deletions.
  1. +1 −1 django/contrib/admin/models.py
  2. +1 −1 django/contrib/admin/templatetags/admin_modify.py
  3. +2 −2 django/contrib/admin/views/doc.py
  4. +10 −10 django/contrib/auth/forms.py
  5. +7 −7 django/contrib/auth/models.py
  6. +4 −4 django/contrib/comments/models.py
  7. +3 −3 django/contrib/comments/views/comments.py
  8. +3 −3 django/contrib/contenttypes/models.py
  9. +3 −3 django/contrib/flatpages/models.py
  10. +2 −2 django/contrib/redirects/models.py
  11. +1 −1 django/contrib/sessions/models.py
  12. +2 −2 django/contrib/sites/models.py
  13. +8 −8 django/core/management.py
  14. +3 −3 django/db/backends/ado_mssql/creation.py
  15. +3 −3 django/db/backends/mysql/creation.py
  16. +3 −3 django/db/backends/mysql_old/creation.py
  17. +2 −2 django/db/backends/oracle/creation.py
  18. +3 −3 django/db/backends/postgresql/creation.py
  19. +3 −3 django/db/backends/sqlite3/creation.py
  20. +1 −1 django/db/backends/sqlite3/introspection.py
  21. +13 −9 django/db/models/fields/__init__.py
  22. +1 −0 django/newforms/fields.py
  23. +60 −56 django/oldforms/__init__.py
  24. +67 −0 django/utils/maxlength.py
  25. +10 −10 docs/contributing.txt
  26. +5 −5 docs/db-api.txt
  27. +5 −5 docs/forms.txt
  28. +57 −53 docs/model-api.txt
  29. +4 −4 docs/newforms.txt
  30. +3 −3 docs/overview.txt
  31. +4 −4 docs/sites.txt
  32. +2 −2 docs/testing.txt
  33. +3 −3 docs/tutorial01.txt
  34. +1 −1 docs/tutorial02.txt
  35. +1 −1 tests/modeltests/basic/models.py
  36. +2 −2 tests/modeltests/choices/models.py
  37. +3 −3 tests/modeltests/custom_columns/models.py
  38. +5 −5 tests/modeltests/custom_managers/models.py
  39. +1 −1 tests/modeltests/custom_methods/models.py
  40. +4 −4 tests/modeltests/custom_pk/models.py
  41. +1 −1 tests/modeltests/field_defaults/models.py
  42. +1 −1 tests/modeltests/fixtures/models.py
  43. +4 −4 tests/modeltests/generic_relations/models.py
  44. +2 −2 tests/modeltests/get_latest/models.py
  45. +2 −2 tests/modeltests/get_object_or_404/models.py
  46. +2 −2 tests/modeltests/get_or_create/models.py
  47. +22 −22 tests/modeltests/invalid_models/models.py
  48. +1 −1 tests/modeltests/lookup/models.py
  49. +1 −1 tests/modeltests/m2m_and_m2o/models.py
  50. +4 −4 tests/modeltests/m2m_intermediary/models.py
  51. +2 −2 tests/modeltests/m2m_multiple/models.py
  52. +1 −1 tests/modeltests/m2m_recursive/models.py
  53. +1 −1 tests/modeltests/m2o_recursive/models.py
  54. +1 −1 tests/modeltests/m2o_recursive2/models.py
  55. +3 −3 tests/modeltests/manipulators/models.py
  56. +2 −2 tests/modeltests/many_to_many/models.py
  57. +3 −3 tests/modeltests/many_to_one/models.py
  58. +2 −2 tests/modeltests/many_to_one_null/models.py
  59. +5 −5 tests/modeltests/model_forms/models.py
  60. +2 −2 tests/modeltests/model_inheritance/models.py
  61. +2 −2 tests/modeltests/mutually_referential/models.py
  62. +6 −6 tests/modeltests/one_to_one/models.py
  63. +1 −1 tests/modeltests/or_lookups/models.py
  64. +1 −1 tests/modeltests/ordering/models.py
  65. +1 −1 tests/modeltests/pagination/models.py
  66. +2 −2 tests/modeltests/properties/models.py
  67. +8 −8 tests/modeltests/reserved_names/models.py
  68. +3 −3 tests/modeltests/reverse_lookup/models.py
  69. +2 −2 tests/modeltests/save_delete_hooks/models.py
  70. +8 −8 tests/modeltests/select_related/models.py
  71. +3 −3 tests/modeltests/serializers/models.py
  72. +2 −2 tests/modeltests/str/models.py
  73. +2 −2 tests/modeltests/transactions/models.py
  74. +1 −1 tests/modeltests/validation/models.py
  75. +1 −1 tests/regressiontests/bug639/models.py
  76. +1 −1 tests/regressiontests/datatypes/models.py
  77. +4 −4 tests/regressiontests/fixtures_regress/models.py
  78. +1 −1 tests/regressiontests/initial_sql_regress/models.py
  79. +37 −37 tests/regressiontests/invalid_admin_options/models.py
  80. +3 −3 tests/regressiontests/many_to_one_regress/models.py
  81. 0 tests/regressiontests/maxlength/__init__.py
  82. 0 tests/regressiontests/maxlength/models.py
  83. +160 −0 tests/regressiontests/maxlength/tests.py
  84. +1 −1 tests/regressiontests/model_regress/models.py
  85. +2 −2 tests/regressiontests/null_queries/models.py
  86. +3 −3 tests/regressiontests/one_to_one_regress/models.py
  87. +8 −8 tests/regressiontests/serializers_regress/models.py
  88. +6 −6 tests/regressiontests/string_lookup/models.py
@@ -18,7 +18,7 @@ class LogEntry(models.Model):
user = models.ForeignKey(User)
content_type = models.ForeignKey(ContentType, blank=True, null=True)
object_id = models.TextField(_('object id'), blank=True, null=True)
- object_repr = models.CharField(_('object repr'), maxlength=200)
+ object_repr = models.CharField(_('object repr'), max_length=200)
action_flag = models.PositiveSmallIntegerField(_('action flag'))
change_message = models.TextField(_('change message'), blank=True)
objects = LogEntryManager()
@@ -192,7 +192,7 @@ def auto_populated_field_script(auto_pop_fields, change = False):
t.append(u'document.getElementById("id_%s").onkeyup = function() {' \
' var e = document.getElementById("id_%s");' \
' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % (
- f, field.name, add_values, field.maxlength))
+ f, field.name, add_values, field.max_length))
return u''.join(t)
auto_populated_field_script = register.simple_tag(auto_populated_field_script)
@@ -291,7 +291,7 @@ def get_return_data_type(func_name):
DATA_TYPE_MAPPING = {
'AutoField' : _('Integer'),
'BooleanField' : _('Boolean (Either True or False)'),
- 'CharField' : _('String (up to %(maxlength)s)'),
+ 'CharField' : _('String (up to %(max_length)s)'),
'CommaSeparatedIntegerField': _('Comma-separated integers'),
'DateField' : _('Date (without time)'),
'DateTimeField' : _('Date (with time)'),
@@ -310,7 +310,7 @@ def get_return_data_type(func_name):
'PhoneNumberField' : _('Phone number'),
'PositiveIntegerField' : _('Integer'),
'PositiveSmallIntegerField' : _('Integer'),
- 'SlugField' : _('String (up to %(maxlength)s)'),
+ 'SlugField' : _('String (up to %(max_length)s)'),
'SmallIntegerField' : _('Integer'),
'TextField' : _('Text'),
'TimeField' : _('Time'),
@@ -10,10 +10,10 @@ class UserCreationForm(oldforms.Manipulator):
"A form that creates a user, with no privileges, from the given username and password."
def __init__(self):
self.fields = (
- oldforms.TextField(field_name='username', length=30, maxlength=30, is_required=True,
+ oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True,
validator_list=[validators.isAlphaNumeric, self.isValidUsername]),
- oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
- oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
+ oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True),
+ oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True,
validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
)
@@ -42,9 +42,9 @@ def __init__(self, request=None):
"""
self.request = request
self.fields = [
- oldforms.TextField(field_name="username", length=15, maxlength=30, is_required=True,
+ oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True,
validator_list=[self.isValidUser, self.hasCookiesEnabled]),
- oldforms.PasswordField(field_name="password", length=15, maxlength=30, is_required=True),
+ oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True),
]
self.user_cache = None
@@ -111,11 +111,11 @@ class PasswordChangeForm(oldforms.Manipulator):
def __init__(self, user):
self.user = user
self.fields = (
- oldforms.PasswordField(field_name="old_password", length=30, maxlength=30, is_required=True,
+ oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True,
validator_list=[self.isValidOldPassword]),
- oldforms.PasswordField(field_name="new_password1", length=30, maxlength=30, is_required=True,
+ oldforms.PasswordField(field_name="new_password1", length=30, max_length=30, is_required=True,
validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]),
- oldforms.PasswordField(field_name="new_password2", length=30, maxlength=30, is_required=True),
+ oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True),
)
def isValidOldPassword(self, new_data, all_data):
@@ -133,8 +133,8 @@ class AdminPasswordChangeForm(oldforms.Manipulator):
def __init__(self, user):
self.user = user
self.fields = (
- oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
- oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
+ oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True),
+ oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True,
validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
)
@@ -50,9 +50,9 @@ class Permission(models.Model):
Three basic permissions -- add, change and delete -- are automatically created for each Django model.
"""
- name = models.CharField(_('name'), maxlength=50)
+ name = models.CharField(_('name'), max_length=50)
content_type = models.ForeignKey(ContentType)
- codename = models.CharField(_('codename'), maxlength=100)
+ codename = models.CharField(_('codename'), max_length=100)
class Meta:
verbose_name = _('permission')
@@ -70,7 +70,7 @@ class Group(models.Model):
Beyond permissions, groups are a convenient way to categorize users to apply some label, or extended functionality, to them. For example, you could create a group 'Special users', and you could write code that would do special things to those users -- such as giving them access to a members-only portion of your site, or sending them members-only e-mail messages.
"""
- name = models.CharField(_('name'), maxlength=80, unique=True)
+ name = models.CharField(_('name'), max_length=80, unique=True)
permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True, filter_interface=models.HORIZONTAL)
class Meta:
@@ -108,11 +108,11 @@ class User(models.Model):
Username and password are required. Other fields are optional.
"""
- username = models.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
- first_name = models.CharField(_('first name'), maxlength=30, blank=True)
- last_name = models.CharField(_('last name'), maxlength=30, blank=True)
+ username = models.CharField(_('username'), max_length=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
+ first_name = models.CharField(_('first name'), max_length=30, blank=True)
+ last_name = models.CharField(_('last name'), max_length=30, blank=True)
email = models.EmailField(_('e-mail address'), blank=True)
- password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
+ password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts."))
is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
@@ -65,8 +65,8 @@ class Comment(models.Model):
user = models.ForeignKey(User, raw_id_admin=True)
content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField(_('object ID'))
- headline = models.CharField(_('headline'), maxlength=255, blank=True)
- comment = models.TextField(_('comment'), maxlength=3000)
+ headline = models.CharField(_('headline'), max_length=255, blank=True)
+ comment = models.TextField(_('comment'), max_length=3000)
rating1 = models.PositiveSmallIntegerField(_('rating #1'), blank=True, null=True)
rating2 = models.PositiveSmallIntegerField(_('rating #2'), blank=True, null=True)
rating3 = models.PositiveSmallIntegerField(_('rating #3'), blank=True, null=True)
@@ -164,8 +164,8 @@ class FreeComment(models.Model):
# A FreeComment is a comment by a non-registered user.
content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField(_('object ID'))
- comment = models.TextField(_('comment'), maxlength=3000)
- person_name = models.CharField(_("person's name"), maxlength=50)
+ comment = models.TextField(_('comment'), max_length=3000)
+ person_name = models.CharField(_("person's name"), max_length=50)
submit_date = models.DateTimeField(_('date/time submitted'), auto_now_add=True)
is_public = models.BooleanField(_('is public'))
ip_address = models.IPAddressField(_('ip address'))
@@ -29,7 +29,7 @@ def get_validator_list(rating_num):
else:
return []
self.fields.extend([
- oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
+ oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True,
validator_list=[self.hasNoProfanities]),
oldforms.RadioSelectField(field_name="rating1", choices=choices,
is_required=ratings_required and num_rating_choices > 0,
@@ -122,9 +122,9 @@ class PublicFreeCommentManipulator(oldforms.Manipulator):
"Manipulator that handles public free (unregistered) comments"
def __init__(self):
self.fields = (
- oldforms.TextField(field_name="person_name", maxlength=50, is_required=True,
+ oldforms.TextField(field_name="person_name", max_length=50, is_required=True,
validator_list=[self.hasNoProfanities]),
- oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
+ oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True,
validator_list=[self.hasNoProfanities]),
)
@@ -32,9 +32,9 @@ def clear_cache(self):
CONTENT_TYPE_CACHE = {}
class ContentType(models.Model):
- name = models.CharField(maxlength=100)
- app_label = models.CharField(maxlength=100)
- model = models.CharField(_('python model class name'), maxlength=100)
+ name = models.CharField(max_length=100)
+ app_label = models.CharField(max_length=100)
+ model = models.CharField(_('python model class name'), max_length=100)
objects = ContentTypeManager()
class Meta:
verbose_name = _('content type')
@@ -4,12 +4,12 @@
from django.utils.translation import ugettext_lazy as _
class FlatPage(models.Model):
- url = models.CharField(_('URL'), maxlength=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
+ url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes."))
- title = models.CharField(_('title'), maxlength=200)
+ title = models.CharField(_('title'), max_length=200)
content = models.TextField(_('content'))
enable_comments = models.BooleanField(_('enable comments'))
- template_name = models.CharField(_('template name'), maxlength=70, blank=True,
+ template_name = models.CharField(_('template name'), max_length=70, blank=True,
help_text=_("Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use 'flatpages/default.html'."))
registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page."))
sites = models.ManyToManyField(Site)
@@ -4,9 +4,9 @@
class Redirect(models.Model):
site = models.ForeignKey(Site, radio_admin=models.VERTICAL)
- old_path = models.CharField(_('redirect from'), maxlength=200, db_index=True,
+ old_path = models.CharField(_('redirect from'), max_length=200, db_index=True,
help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'."))
- new_path = models.CharField(_('redirect to'), maxlength=200, blank=True,
+ new_path = models.CharField(_('redirect to'), max_length=200, blank=True,
help_text=_("This can be either an absolute path (as above) or a full URL starting with 'http://'."))
class Meta:
@@ -65,7 +65,7 @@ class Session(models.Model):
the sessions documentation that is shipped with Django (also available
on the Django website).
"""
- session_key = models.CharField(_('session key'), maxlength=40, primary_key=True)
+ session_key = models.CharField(_('session key'), max_length=40, primary_key=True)
session_data = models.TextField(_('session data'))
expire_date = models.DateTimeField(_('expire date'))
objects = SessionManager()
@@ -12,8 +12,8 @@ def get_current(self):
return self.get(pk=sid)
class Site(models.Model):
- domain = models.CharField(_('domain name'), maxlength=100)
- name = models.CharField(_('display name'), maxlength=50)
+ domain = models.CharField(_('domain name'), max_length=100)
+ name = models.CharField(_('display name'), max_length=50)
objects = SiteManager()
class Meta:
db_table = 'django_site'
@@ -910,9 +910,9 @@ def inspectdb():
field_type, new_params = field_type
extra_params.update(new_params)
- # Add maxlength for all CharFields.
+ # Add max_length for all CharFields.
if field_type == 'CharField' and row[3]:
- extra_params['maxlength'] = row[3]
+ extra_params['max_length'] = row[3]
if field_type == 'DecimalField':
extra_params['max_digits'] = row[4]
@@ -987,8 +987,8 @@ def get_validation_errors(outfile, app=None):
for f in opts.fields:
if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':
e.add(opts, '"%s": You can\'t use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.' % f.name)
- if isinstance(f, models.CharField) and f.maxlength in (None, 0):
- e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name)
+ if isinstance(f, models.CharField) and f.max_length in (None, 0):
+ e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name)
if isinstance(f, models.DecimalField):
if f.decimal_places is None:
e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name)
@@ -1013,11 +1013,11 @@ def get_validation_errors(outfile, app=None):
if f.db_index not in (None, True, False):
e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name)
- # Check that maxlength <= 255 if using older MySQL versions.
+ # Check that max_length <= 255 if using older MySQL versions.
if settings.DATABASE_ENGINE == 'mysql':
db_version = connection.get_server_version()
- if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.maxlength > 255:
- e.add(opts, '"%s": %s cannot have a "maxlength" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]])))
+ if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255:
+ e.add(opts, '"%s": %s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]])))
# Check to see if the related field will clash with any
# existing fields, m2m fields, m2m related objects or related objects
@@ -1252,7 +1252,7 @@ def createcachetable(tablename):
from django.db import backend, connection, transaction, models
fields = (
# "key" is a reserved word in MySQL, so use "cache_key" instead.
- models.CharField(name='cache_key', maxlength=255, unique=True, primary_key=True),
+ models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True),
models.TextField(name='value'),
models.DateTimeField(name='expires', db_index=True),
)
@@ -1,8 +1,8 @@
DATA_TYPES = {
'AutoField': 'int IDENTITY (1, 1)',
'BooleanField': 'bit',
- 'CharField': 'varchar(%(maxlength)s)',
- 'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
+ 'CharField': 'varchar(%(max_length)s)',
+ 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
'DateField': 'smalldatetime',
'DateTimeField': 'smalldatetime',
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -17,7 +17,7 @@
'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK ([%(column)s] > 0)',
'PositiveSmallIntegerField': 'smallint CONSTRAINT [CK_smallint_pos_%(column)s] CHECK ([%(column)s] > 0)',
- 'SlugField': 'varchar(%(maxlength)s)',
+ 'SlugField': 'varchar(%(max_length)s)',
'SmallIntegerField': 'smallint',
'TextField': 'text',
'TimeField': 'time',
@@ -5,8 +5,8 @@
DATA_TYPES = {
'AutoField': 'integer AUTO_INCREMENT',
'BooleanField': 'bool',
- 'CharField': 'varchar(%(maxlength)s)',
- 'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
+ 'CharField': 'varchar(%(max_length)s)',
+ 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
'DateField': 'date',
'DateTimeField': 'datetime',
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -21,7 +21,7 @@
'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer UNSIGNED',
'PositiveSmallIntegerField': 'smallint UNSIGNED',
- 'SlugField': 'varchar(%(maxlength)s)',
+ 'SlugField': 'varchar(%(max_length)s)',
'SmallIntegerField': 'smallint',
'TextField': 'longtext',
'TimeField': 'time',
Oops, something went wrong.

0 comments on commit 212ee65

Please sign in to comment.