Ticket #2101: max_length.3.diff
| File max_length.3.diff, 124.9 kB (added by gwilson, 1 year ago) |
|---|
-
django/utils/maxlength.py
old new 1 """ 2 Methods and functions for legacy maxlength support. 3 """ 4 5 def get_maxlength(self): 6 return self.max_length 7 8 def set_maxlength(self, value): 9 self.max_length = value 10 11 def legacy_maxlength(max_length, maxlength, default=None): 12 """ 13 Provides backwards compatibilty for the legacy "maxlength" attribute. 14 If one of max_length or maxlength is given, then that value is returned. 15 If both are given, a TypeError is raised. 16 If neither are given, the default value or None is returned depending on 17 if a default value was given or not. 18 """ 19 if max_length is not None and maxlength is not None: 20 raise TypeError("field can not take both the max_length argument and" 21 " the legacy maxlength argument.") 22 for value in [max_length, maxlength, default]: 23 if value is not None: 24 return value 25 26 def legacy_maxlength_kwargs(kwargs, default=None): 27 """ 28 Similar to legacy_maxlength, but operates on a dictionary with max_length 29 and maxlength keys. The resulting maximum length is stored using the key 30 "max_length", and the "maxlength" key is removed it if exists. 31 """ 32 kwargs['max_length'] = legacy_maxlength(kwargs.get('max_length', None), 33 kwargs.get('maxlength', None), 34 default) 35 if 'maxlength' in kwargs: 36 del kwargs['maxlength'] 37 return kwargs -
tests/regressiontests/maxlength/tests.py
old new 1 # Test access to max_length while still providing full backwards compatibility 2 # with legacy maxlength attribute. 3 """ 4 # legacy_maxlength 5 6 >>> from django.oldforms import legacy_maxlength 7 8 >>> legacy_maxlength(None, None) 9 10 11 >>> legacy_maxlength(10, None) 12 10 13 14 >>> legacy_maxlength(None, 10) 15 10 16 17 >>> legacy_maxlength(10, 12) 18 Traceback (most recent call last): 19 ... 20 TypeError: field can not take both the max_length argument and the legacy maxlength argument. 21 22 >>> legacy_maxlength(None, None, 50) 23 50 24 25 >>> legacy_maxlength(10, None, 50) 26 10 27 28 >>> legacy_maxlength(None, 10, 50) 29 10 30 31 >>> legacy_maxlength(10, 12, 50) 32 Traceback (most recent call last): 33 ... 34 TypeError: field can not take both the max_length argument and the legacy maxlength argument. 35 36 >>> legacy_maxlength(0, 10) 37 Traceback (most recent call last): 38 ... 39 TypeError: field can not take both the max_length argument and the legacy maxlength argument. 40 41 >>> legacy_maxlength(0, None, 10) 42 0 43 44 >>> legacy_maxlength(None, 0, 10) 45 0 46 47 #=============================================================================== 48 # Fields 49 #=============================================================================== 50 51 # Set up fields 52 >>> from django.db.models import fields 53 >>> new = fields.Field(max_length=15) 54 >>> old = fields.Field(maxlength=10) 55 56 # Ensure both max_length and legacy maxlength are not able to both be specified 57 >>> fields.Field(maxlength=10, max_length=15) 58 Traceback (most recent call last): 59 ... 60 TypeError: field can not take both the max_length argument and the legacy maxlength argument. 61 62 # Test max_length 63 >>> new.max_length 64 15 65 >>> old.max_length 66 10 67 68 # Test accessing maxlength 69 >>> new.maxlength 70 15 71 >>> old.maxlength 72 10 73 74 # Test setting maxlength 75 >>> new.maxlength += 1 76 >>> old.maxlength += 1 77 >>> new.max_length 78 16 79 >>> old.max_length 80 11 81 82 # SlugField __init__ passes through max_length so test that too 83 >>> fields.SlugField('new', max_length=15).max_length 84 15 85 >>> fields.SlugField('empty').max_length 86 50 87 >>> fields.SlugField('old', maxlength=10).max_length 88 10 89 90 #=============================================================================== 91 # (old)forms 92 #=============================================================================== 93 94 >>> from django import oldforms 95 96 # Test max_length attribute 97 98 >>> oldforms.TextField('new', max_length=15).render('') 99 u'<input type="text" id="id_new" class="vTextField" name="new" size="30" value="" maxlength="15" />' 100 101 >>> oldforms.IntegerField('new', max_length=15).render('') 102 u'<input type="text" id="id_new" class="vIntegerField" name="new" size="10" value="" maxlength="15" />' 103 104 >>> oldforms.SmallIntegerField('new', max_length=15).render('') 105 u'<input type="text" id="id_new" class="vSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 106 107 >>> oldforms.PositiveIntegerField('new', max_length=15).render('') 108 u'<input type="text" id="id_new" class="vPositiveIntegerField" name="new" size="10" value="" maxlength="15" />' 109 110 >>> oldforms.PositiveSmallIntegerField('new', max_length=15).render('') 111 u'<input type="text" id="id_new" class="vPositiveSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 112 113 >>> oldforms.DatetimeField('new', max_length=15).render('') 114 u'<input type="text" id="id_new" class="vDatetimeField" name="new" size="30" value="" maxlength="15" />' 115 116 >>> oldforms.EmailField('new', max_length=15).render('') 117 u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="15" />' 118 >>> oldforms.EmailField('new').render('') 119 u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="75" />' 120 121 >>> oldforms.URLField('new', max_length=15).render('') 122 u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="15" />' 123 >>> oldforms.URLField('new').render('') 124 u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="200" />' 125 126 >>> oldforms.IPAddressField('new', max_length=15).render('') 127 u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 128 >>> oldforms.IPAddressField('new').render('') 129 u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 130 131 >>> oldforms.CommaSeparatedIntegerField('new', max_length=15).render('') 132 u'<input type="text" id="id_new" class="vCommaSeparatedIntegerField" name="new" size="20" value="" maxlength="15" />' 133 134 135 # Test legacy maxlength attribute 136 137 >>> oldforms.TextField('old', maxlength=10).render('') 138 u'<input type="text" id="id_old" class="vTextField" name="old" size="30" value="" maxlength="10" />' 139 140 >>> oldforms.IntegerField('old', maxlength=10).render('') 141 u'<input type="text" id="id_old" class="vIntegerField" name="old" size="10" value="" maxlength="10" />' 142 143 >>> oldforms.SmallIntegerField('old', maxlength=10).render('') 144 u'<input type="text" id="id_old" class="vSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 145 146 >>> oldforms.PositiveIntegerField('old', maxlength=10).render('') 147 u'<input type="text" id="id_old" class="vPositiveIntegerField" name="old" size="10" value="" maxlength="10" />' 148 149 >>> oldforms.PositiveSmallIntegerField('old', maxlength=10).render('') 150 u'<input type="text" id="id_old" class="vPositiveSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 151 152 >>> oldforms.DatetimeField('old', maxlength=10).render('') 153 u'<input type="text" id="id_old" class="vDatetimeField" name="old" size="30" value="" maxlength="10" />' 154 155 >>> oldforms.EmailField('old', maxlength=10).render('') 156 u'<input type="text" id="id_old" class="vEmailField" name="old" size="50" value="" maxlength="10" />' 157 158 >>> oldforms.URLField('old', maxlength=10).render('') 159 u'<input type="text" id="id_old" class="vURLField" name="old" size="50" value="" maxlength="10" />' 160 161 >>> oldforms.IPAddressField('old', maxlength=10).render('') 162 u'<input type="text" id="id_old" class="vIPAddressField" name="old" size="15" value="" maxlength="10" />' 163 164 >>> oldforms.CommaSeparatedIntegerField('old', maxlength=10).render('') 165 u'<input type="text" id="id_old" class="vCommaSeparatedIntegerField" name="old" size="20" value="" maxlength="10" />' 166 """ 167 if __name__ == "__main__": 168 import doctest 169 doctest.testmod() -
django/contrib/admin/models.py
old new 18 18 user = models.ForeignKey(User) 19 19 content_type = models.ForeignKey(ContentType, blank=True, null=True) 20 20 object_id = models.TextField(_('object id'), blank=True, null=True) 21 object_repr = models.CharField(_('object repr'), max length=200)21 object_repr = models.CharField(_('object repr'), max_length=200) 22 22 action_flag = models.PositiveSmallIntegerField(_('action flag')) 23 23 change_message = models.TextField(_('change message'), blank=True) 24 24 objects = LogEntryManager() -
django/contrib/admin/templatetags/admin_modify.py
old new 192 192 t.append(u'document.getElementById("id_%s").onkeyup = function() {' \ 193 193 ' var e = document.getElementById("id_%s");' \ 194 194 ' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % ( 195 f, field.name, add_values, field.max length))195 f, field.name, add_values, field.max_length)) 196 196 return u''.join(t) 197 197 auto_populated_field_script = register.simple_tag(auto_populated_field_script) 198 198 -
django/contrib/admin/views/doc.py
old new 291 291 DATA_TYPE_MAPPING = { 292 292 'AutoField' : _('Integer'), 293 293 'BooleanField' : _('Boolean (Either True or False)'), 294 'CharField' : _('String (up to %(max length)s)'),294 'CharField' : _('String (up to %(max_length)s)'), 295 295 'CommaSeparatedIntegerField': _('Comma-separated integers'), 296 296 'DateField' : _('Date (without time)'), 297 297 'DateTimeField' : _('Date (with time)'), … … 310 310 'PhoneNumberField' : _('Phone number'), 311 311 'PositiveIntegerField' : _('Integer'), 312 312 'PositiveSmallIntegerField' : _('Integer'), 313 'SlugField' : _('String (up to %(max length)s)'),313 'SlugField' : _('String (up to %(max_length)s)'), 314 314 'SmallIntegerField' : _('Integer'), 315 315 'TextField' : _('Text'), 316 316 'TimeField' : _('Time'), -
django/contrib/auth/forms.py
old new 10 10 "A form that creates a user, with no privileges, from the given username and password." 11 11 def __init__(self): 12 12 self.fields = ( 13 oldforms.TextField(field_name='username', length=30, max length=30, is_required=True,13 oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True, 14 14 validator_list=[validators.isAlphaNumeric, self.isValidUsername]), 15 oldforms.PasswordField(field_name='password1', length=30, max length=60, is_required=True),16 oldforms.PasswordField(field_name='password2', length=30, max length=60, is_required=True,15 oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 16 oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 17 17 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 18 18 ) 19 19 … … 42 42 """ 43 43 self.request = request 44 44 self.fields = [ 45 oldforms.TextField(field_name="username", length=15, max length=30, is_required=True,45 oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True, 46 46 validator_list=[self.isValidUser, self.hasCookiesEnabled]), 47 oldforms.PasswordField(field_name="password", length=15, max length=30, is_required=True),47 oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True), 48 48 ] 49 49 self.user_cache = None 50 50 … … 111 111 def __init__(self, user): 112 112 self.user = user 113 113 self.fields = ( 114 oldforms.PasswordField(field_name="old_password", length=30, max length=30, is_required=True,114 oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True, 115 115 validator_list=[self.isValidOldPassword]), 116 oldforms.PasswordField(field_name="new_password1", length=30, max length=30, is_required=True,116 oldforms.PasswordField(field_name="new_password1", length=30, max_length=30, is_required=True, 117 117 validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]), 118 oldforms.PasswordField(field_name="new_password2", length=30, max length=30, is_required=True),118 oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True), 119 119 ) 120 120 121 121 def isValidOldPassword(self, new_data, all_data): … … 133 133 def __init__(self, user): 134 134 self.user = user 135 135 self.fields = ( 136 oldforms.PasswordField(field_name='password1', length=30, max length=60, is_required=True),137 oldforms.PasswordField(field_name='password2', length=30, max length=60, is_required=True,136 oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 137 oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 138 138 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 139 139 ) 140 140 -
django/contrib/auth/models.py
old new 50 50 51 51 Three basic permissions -- add, change and delete -- are automatically created for each Django model. 52 52 """ 53 name = models.CharField(_('name'), max length=50)53 name = models.CharField(_('name'), max_length=50) 54 54 content_type = models.ForeignKey(ContentType) 55 codename = models.CharField(_('codename'), max length=100)55 codename = models.CharField(_('codename'), max_length=100) 56 56 57 57 class Meta: 58 58 verbose_name = _('permission') … … 70 70 71 71 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. 72 72 """ 73 name = models.CharField(_('name'), max length=80, unique=True)73 name = models.CharField(_('name'), max_length=80, unique=True) 74 74 permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True, filter_interface=models.HORIZONTAL) 75 75 76 76 class Meta: … … 108 108 109 109 Username and password are required. Other fields are optional. 110 110 """ 111 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)."))112 first_name = models.CharField(_('first name'), max length=30, blank=True)113 last_name = models.CharField(_('last name'), max length=30, blank=True)111 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).")) 112 first_name = models.CharField(_('first name'), max_length=30, blank=True) 113 last_name = models.CharField(_('last name'), max_length=30, blank=True) 114 114 email = models.EmailField(_('e-mail address'), blank=True) 115 password = models.CharField(_('password'), max length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))115 password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.")) 116 116 is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site.")) 117 117 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.")) 118 118 is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them.")) -
django/contrib/comments/models.py
old new 65 65 user = models.ForeignKey(User, raw_id_admin=True) 66 66 content_type = models.ForeignKey(ContentType) 67 67 object_id = models.IntegerField(_('object ID')) 68 headline = models.CharField(_('headline'), max length=255, blank=True)69 comment = models.TextField(_('comment'), max length=3000)68 headline = models.CharField(_('headline'), max_length=255, blank=True) 69 comment = models.TextField(_('comment'), max_length=3000) 70 70 rating1 = models.PositiveSmallIntegerField(_('rating #1'), blank=True, null=True) 71 71 rating2 = models.PositiveSmallIntegerField(_('rating #2'), blank=True, null=True) 72 72 rating3 = models.PositiveSmallIntegerField(_('rating #3'), blank=True, null=True) … … 164 164 # A FreeComment is a comment by a non-registered user. 165 165 content_type = models.ForeignKey(ContentType) 166 166 object_id = models.IntegerField(_('object ID')) 167 comment = models.TextField(_('comment'), max length=3000)168 person_name = models.CharField(_("person's name"), max length=50)167 comment = models.TextField(_('comment'), max_length=3000) 168 person_name = models.CharField(_("person's name"), max_length=50) 169 169 submit_date = models.DateTimeField(_('date/time submitted'), auto_now_add=True) 170 170 is_public = models.BooleanField(_('is public')) 171 171 ip_address = models.IPAddressField(_('ip address')) -
django/contrib/comments/views/comments.py
old new 29 29 else: 30 30 return [] 31 31 self.fields.extend([ 32 oldforms.LargeTextField(field_name="comment", max length=3000, is_required=True,32 oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True, 33 33 validator_list=[self.hasNoProfanities]), 34 34 oldforms.RadioSelectField(field_name="rating1", choices=choices, 35 35 is_required=ratings_required and num_rating_choices > 0, … … 122 122 "Manipulator that handles public free (unregistered) comments" 123 123 def __init__(self): 124 124 self.fields = ( 125 oldforms.TextField(field_name="person_name", max length=50, is_required=True,125 oldforms.TextField(field_name="person_name", max_length=50, is_required=True, 126 126 validator_list=[self.hasNoProfanities]), 127 oldforms.LargeTextField(field_name="comment", max length=3000, is_required=True,127 oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True, 128 128 validator_list=[self.hasNoProfanities]), 129 129 ) 130 130 -
django/contrib/contenttypes/models.py
old new 32 32 CONTENT_TYPE_CACHE = {} 33 33 34 34 class ContentType(models.Model): 35 name = models.CharField(max length=100)36 app_label = models.CharField(max length=100)37 model = models.CharField(_('python model class name'), max length=100)35 name = models.CharField(max_length=100) 36 app_label = models.CharField(max_length=100) 37 model = models.CharField(_('python model class name'), max_length=100) 38 38 objects = ContentTypeManager() 39 39 class Meta: 40 40 verbose_name = _('content type') -
django/contrib/flatpages/models.py
old new 4 4 from django.utils.translation import ugettext_lazy as _ 5 5 6 6 class FlatPage(models.Model): 7 url = models.CharField(_('URL'), max length=100, validator_list=[validators.isAlphaNumericURL], db_index=True,7 url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], db_index=True, 8 8 help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes.")) 9 title = models.CharField(_('title'), max length=200)9 title = models.CharField(_('title'), max_length=200) 10 10 content = models.TextField(_('content')) 11 11 enable_comments = models.BooleanField(_('enable comments')) 12 template_name = models.CharField(_('template name'), max length=70, blank=True,12 template_name = models.CharField(_('template name'), max_length=70, blank=True, 13 13 help_text=_("Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use 'flatpages/default.html'.")) 14 14 registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page.")) 15 15 sites = models.ManyToManyField(Site) -
django/contrib/redirects/models.py
old new 4 4 5 5 class Redirect(models.Model): 6 6 site = models.ForeignKey(Site, radio_admin=models.VERTICAL) 7 old_path = models.CharField(_('redirect from'), max length=200, db_index=True,7 old_path = models.CharField(_('redirect from'), max_length=200, db_index=True, 8 8 help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'.")) 9 new_path = models.CharField(_('redirect to'), max length=200, blank=True,9 new_path = models.CharField(_('redirect to'), max_length=200, blank=True, 10 10 help_text=_("This can be either an absolute path (as above) or a full URL starting with 'http://'.")) 11 11 12 12 class Meta: -
django/contrib/sessions/models.py
old new 65 65 the sessions documentation that is shipped with Django (also available 66 66 on the Django website). 67 67 """ 68 session_key = models.CharField(_('session key'), max length=40, primary_key=True)68 session_key = models.CharField(_('session key'), max_length=40, primary_key=True) 69 69 session_data = models.TextField(_('session data')) 70 70 expire_date = models.DateTimeField(_('expire date')) 71 71 objects = SessionManager() -
django/contrib/sites/models.py
old new 12 12 return self.get(pk=sid) 13 13 14 14 class Site(models.Model): 15 domain = models.CharField(_('domain name'), max length=100)16 name = models.CharField(_('display name'), max length=50)15 domain = models.CharField(_('domain name'), max_length=100) 16 name = models.CharField(_('display name'), max_length=50) 17 17 objects = SiteManager() 18 18 class Meta: 19 19 db_table = 'django_site' -
django/core/management.py
old new 910 910 field_type, new_params = field_type 911 911 extra_params.update(new_params) 912 912 913 # Add max length for all CharFields.913 # Add max_length for all CharFields. 914 914 if field_type == 'CharField' and row[3]: 915 extra_params['max length'] = row[3]915 extra_params['max_length'] = row[3] 916 916 917 917 if field_type == 'DecimalField': 918 918 extra_params['max_digits'] = row[4] … … 987 987 for f in opts.fields: 988 988 if f.name == 'id' and not f.primary_key and opts.pk.name == 'id': 989 989 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) 990 if isinstance(f, models.CharField) and f.max length in (None, 0):991 e.add(opts, '"%s": CharFields require a "max length" attribute.' % f.name)990 if isinstance(f, models.CharField) and f.max_length in (None, 0): 991 e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name) 992 992 if isinstance(f, models.DecimalField): 993 993 if f.decimal_places is None: 994 994 e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name) … … 1013 1013 if f.db_index not in (None, True, False): 1014 1014 e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name) 1015 1015 1016 # Check that max length <= 255 if using older MySQL versions.1016 # Check that max_length <= 255 if using older MySQL versions. 1017 1017 if settings.DATABASE_ENGINE == 'mysql': 1018 1018 db_version = connection.get_server_version() 1019 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max length > 255:1020 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]])))1019 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255: 1020 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]]))) 1021 1021 1022 1022 # Check to see if the related field will clash with any 1023 1023 # existing fields, m2m fields, m2m related objects or related objects … … 1252 1252 from django.db import backend, connection, transaction, models 1253 1253 fields = ( 1254 1254 # "key" is a reserved word in MySQL, so use "cache_key" instead. 1255 models.CharField(name='cache_key', max length=255, unique=True, primary_key=True),1255 models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True), 1256 1256 models.TextField(name='value'), 1257 1257 models.DateTimeField(name='expires', db_index=True), 1258 1258 ) -
django/db/backends/ado_mssql/creation.py
old new 1 1 DATA_TYPES = { 2 2 'AutoField': 'int IDENTITY (1, 1)', 3 3 'BooleanField': 'bit', 4 'CharField': 'varchar(%(max length)s)',5 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',4 'CharField': 'varchar(%(max_length)s)', 5 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 6 6 'DateField': 'smalldatetime', 7 7 'DateTimeField': 'smalldatetime', 8 8 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', … … 17 17 'PhoneNumberField': 'varchar(20)', 18 18 'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK ([%(column)s] > 0)', 19 19 'PositiveSmallIntegerField': 'smallint CONSTRAINT [CK_smallint_pos_%(column)s] CHECK ([%(column)s] > 0)', 20 'SlugField': 'varchar(%(max length)s)',20 'SlugField': 'varchar(%(max_length)s)', 21 21 'SmallIntegerField': 'smallint', 22 22 'TextField': 'text', 23 23 'TimeField': 'time', -
django/db/backends/mysql/creation.py
old new 5 5 DATA_TYPES = { 6 6 'AutoField': 'integer AUTO_INCREMENT', 7 7 'BooleanField': 'bool', 8 'CharField': 'varchar(%(max length)s)',9 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',8 'CharField': 'varchar(%(max_length)s)', 9 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 10 10 'DateField': 'date', 11 11 'DateTimeField': 'datetime', 12 12 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', … … 21 21 'PhoneNumberField': 'varchar(20)', 22 22 'PositiveIntegerField': 'integer UNSIGNED', 23 23 'PositiveSmallIntegerField': 'smallint UNSIGNED', 24 'SlugField': 'varchar(%(max length)s)',24 'SlugField': 'varchar(%(max_length)s)', 25 25 'SmallIntegerField': 'smallint', 26 26 'TextField': 'longtext', 27 27 'TimeField': 'time', -
django/db/backends/mysql_old/creation.py
old new 5 5 DATA_TYPES = { 6 6 'AutoField': 'integer AUTO_INCREMENT', 7 7 'BooleanField': 'bool', 8 'CharField': 'varchar(%(max length)s)',9 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',8 'CharField': 'varchar(%(max_length)s)', 9 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 10 10 'DateField': 'date', 11 11 'DateTimeField': 'datetime', 12 12 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', … … 21 21 'PhoneNumberField': 'varchar(20)', 22 22 'PositiveIntegerField': 'integer UNSIGNED', 23 23 'PositiveSmallIntegerField': 'smallint UNSIGNED', 24 'SlugField': 'varchar(%(max length)s)',24 'SlugField': 'varchar(%(max_length)s)', 25 25 'SmallIntegerField': 'smallint', 26 26 'TextField': 'longtext', 27 27 'TimeField': 'time', -
django/db/backends/oracle/creation.py
old new 8 8 DATA_TYPES = { 9 9 'AutoField': 'NUMBER(11)', 10 10 'BooleanField': 'NUMBER(1) CHECK (%(column)s IN (0,1))', 11 'CharField': 'NVARCHAR2(%(max length)s)',12 'CommaSeparatedIntegerField': 'VARCHAR2(%(max length)s)',11 'CharField': 'NVARCHAR2(%(max_length)s)', 12 'CommaSeparatedIntegerField': 'VARCHAR2(%(max_length)s)', 13 13 'DateField': 'DATE', 14 14 'DateTimeField': 'TIMESTAMP', 15 15 'DecimalField': 'NUMBER(%(max_digits)s, %(decimal_places)s)', -
django/db/backends/postgresql/creation.py
old new 5 5 DATA_TYPES = { 6 6 'AutoField': 'serial', 7 7 'BooleanField': 'boolean', 8 'CharField': 'varchar(%(max length)s)',9 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',8 'CharField': 'varchar(%(max_length)s)', 9 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 10 10 'DateField': 'date', 11 11 'DateTimeField': 'timestamp with time zone', 12 12 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', … … 21 21 'PhoneNumberField': 'varchar(20)', 22 22 'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)', 23 23 'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)', 24 'SlugField': 'varchar(%(max length)s)',24 'SlugField': 'varchar(%(max_length)s)', 25 25 'SmallIntegerField': 'smallint', 26 26 'TextField': 'text', 27 27 'TimeField': 'time', -
django/db/backends/sqlite3/creation.py
old new 4 4 DATA_TYPES = { 5 5 'AutoField': 'integer', 6 6 'BooleanField': 'bool', 7 'CharField': 'varchar(%(max length)s)',8 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',7 'CharField': 'varchar(%(max_length)s)', 8 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 9 9 'DateField': 'date', 10 10 'DateTimeField': 'datetime', 11 11 'DecimalField': 'decimal', … … 20 20 'PhoneNumberField': 'varchar(20)', 21 21 'PositiveIntegerField': 'integer unsigned', 22 22 'PositiveSmallIntegerField': 'smallint unsigned', 23 'SlugField': 'varchar(%(max length)s)',23 'SlugField': 'varchar(%(max_length)s)', 24 24 'SmallIntegerField': 'smallint', 25 25 'TextField': 'text', 26 26 'TimeField': 'time', -
django/db/backends/sqlite3/introspection.py
old new 81 81 import re 82 82 m = re.search(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$', key) 83 83 if m: 84 return ('CharField', {'max length': int(m.group(1))})84 return ('CharField', {'max_length': int(m.group(1))}) 85 85 raise KeyError 86 86 87 87 DATA_TYPES_REVERSE = FlexibleFieldLookupDict() -
django/db/models/fields/__init__.py
old new 11 11 from django.utils.text import capfirst 12 12 from django.utils.translation import ugettext_lazy, ugettext as _ 13 13 from django.utils.encoding import smart_unicode, force_unicode, smart_str 14 from django.utils.maxlength import get_maxlength, set_maxlength, legacy_maxlength, legacy_maxlength_kwargs 14 15 import datetime, os, time 15 16 try: 16 17 import decimal … … 72 73 creation_counter = 0 73 74 74 75 def __init__(self, verbose_name=None, name=None, primary_key=False, 75 max length=None, unique=False, blank=False, null=False, db_index=False,76 max_length=None, unique=False, blank=False, null=False, db_index=False, 76 77 core=False, rel=None, default=NOT_PROVIDED, editable=True, serialize=True, 77 78 prepopulate_from=None, unique_for_date=None, unique_for_month=None, 78 79 unique_for_year=None, validator_list=None, choices=None, radio_admin=None, 79 help_text='', db_column=None, db_tablespace=None ):80 help_text='', db_column=None, db_tablespace=None, maxlength=None): 80 81 self.name = name 81 82 self.verbose_name = verbose_name 82 83 self.primary_key = primary_key 83 self.maxlength, self.unique = maxlength, unique 84 # Fields now use max_length, but still support the legacy 85 # maxlength argument. 86 self.max_length = legacy_maxlength(max_length=max_length, 87 maxlength=maxlength) 88 self.unique = unique 84 89 self.blank, self.null = blank, null 85 90 # Oracle treats the empty string ('') as null, so coerce the null 86 91 # option whenever '' is a possible value. … … 106 111 self.creation_counter = Field.creation_counter 107 112 Field.creation_counter += 1 108 113 114 # Support accessing and setting to the legacy maxlength argument. 115 maxlength = property(get_maxlength, set_maxlength) 116 109 117 def __cmp__(self, other): 110 118 # This is needed because bisect does not take a comparison function. 111 119 return cmp(self.creation_counter, other.creation_counter) … … 244 252 245 253 def prepare_field_objs_and_params(self, manipulator, name_prefix): 246 254 params = {'validator_list': self.validator_list[:]} 247 if self.max length and not self.choices: # Don't give SelectFields a maxlength parameter.248 params['max length'] = self.maxlength255 if self.max_length and not self.choices: # Don't give SelectFields a max_length parameter. 256 params['max_length'] = self.max_length 249 257 250 258 if self.choices: 251 259 if self.radio_admin: … … 461 469 return smart_unicode(value) 462 470 463 471 def formfield(self, **kwargs): 464 defaults = {'max_length': self.max length}472 defaults = {'max_length': self.max_length} 465 473 defaults.update(kwargs) 466 474 return super(CharField, self).formfield(**defaults) 467 475 … … 670 678 671 679 class EmailField(CharField): 672 680 def __init__(self, *args, **kwargs): 673 kwargs['maxlength'] = 75 681 kwargs = legacy_maxlength_kwargs(kwargs) 682 kwargs['max_length'] = 75 674 683 CharField.__init__(self, *args, **kwargs) 675 684 676 685 def get_internal_type(self): … … 829 838 class IPAddressField(Field): 830 839 empty_strings_allowed = False 831 840 def __init__(self, *args, **kwargs): 832 kwargs['maxlength'] = 15 841 kwargs = legacy_maxlength_kwargs(kwargs) 842 kwargs['max_length'] = 15 833 843 Field.__init__(self, *args, **kwargs) 834 844 835 845 def get_manipulator_field_objs(self): … … 877 887 878 888 class SlugField(Field): 879 889 def __init__(self, *args, **kwargs): 880 kwargs ['maxlength'] = kwargs.get('maxlength',50)890 kwargs = legacy_maxlength_kwargs(kwargs, default=50) 881 891 kwargs.setdefault('validator_list', []).append(validators.isSlug) 882 892 # Set db_index=True unless it's been set manually. 883 893 if 'db_index' not in kwargs: … … 963 973 964 974 class URLField(CharField): 965 975 def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): 966 kwargs ['maxlength'] = kwargs.get('maxlength',200)976 kwargs = legacy_maxlength_kwargs(kwargs, default=200) 967 977 if verify_exists: 968 978 kwargs.setdefault('validator_list', []).append(validators.isExistingURL) 969 979 self.verify_exists = verify_exists -
django/newforms/fields.py
old new 120 120 121 121 def widget_attrs(self, widget): 122 122 if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): 123 # The HTML attribute is maxlength, not max_length. 123 124 return {'maxlength': str(self.max_length)} 124 125 125 126 class IntegerField(Field): -
django/oldforms/__init__.py
old new 4 4 from django.conf import settings 5 5 from django.utils.translation import ugettext, ungettext 6 6 from django.utils.encoding import smart_unicode, force_unicode 7 from django.utils.maxlength import get_maxlength, set_maxlength, legacy_maxlength, legacy_maxlength_kwargs 7 8 8 9 FORM_FIELD_ID_PREFIX = 'id_' 9 10 … … 390 391 391 392 class TextField(FormField): 392 393 input_type = "text" 393 def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None, member_name=None): 394 def __init__(self, field_name, length=30, max_length=None, 395 is_required=False, validator_list=None, member_name=None, 396 maxlength=None): 394 397 if validator_list is None: validator_list = [] 395 398 self.field_name = field_name 396 self.length, self.maxlength = length, maxlength 399 self.length = length 400 # Fields now use max_length, but still support the legacy 401 # maxlength argument. 402 self.max_length = legacy_maxlength(max_length, maxlength) 397 403 self.is_required = is_required 398 404 self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list 399 405 if member_name != None: 400 406 self.member_name = member_name 401 407 408 # Support accessing and setting the legacy maxlength argument. 409 maxlength = property(get_maxlength, set_maxlength) 410 402 411 def isValidLength(self, data, form): 403 if data and self.max length and len(smart_unicode(data)) > self.maxlength:412 if data and self.max_length and len(smart_unicode(data)) > self.max_length: 404 413 raise validators.ValidationError, ungettext("Ensure your text is less than %s character.", 405 "Ensure your text is less than %s characters.", self.max length) % self.maxlength414 "Ensure your text is less than %s characters.", self.max_length) % self.max_length 406 415 407 416 def hasNoNewlines(self, data, form): 408 417 if data and '\n' in data: … … 411 420 def render(self, data): 412 421 if data is None: 413 422 data = u'' 414 max length = u''415 if self.max length:416 max length = u'maxlength="%s" ' % self.maxlength423 max_length = u'' 424 if self.max_length: 425 max_length = u'maxlength="%s" ' % self.max_length 417 426 return u'<input type="%s" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \ 418 427 (self.input_type, self.get_id(), self.__class__.__name__, self.is_required and u' required' or '', 419 self.field_name, self.length, escape(data), max length)428 self.field_name, self.length, escape(data), max_length) 420 429 421 430 def html2python(data): 422 431 return data … … 426 435 input_type = "password" 427 436 428 437 class LargeTextField(TextField): 429 def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, maxlength=None): 438 def __init__(self, field_name, rows=10, cols=40, is_required=False, 439 validator_list=None, max_length=None, maxlength=None): 440 max_length = legacy_maxlength(max_length, maxlength) 430 441 if validator_list is None: validator_list = [] 431 442 self.field_name = field_name 432 443 self.rows, self.cols, self.is_required = rows, cols, is_required 433 444 self.validator_list = validator_list[:] 434 if max length:445 if max_length: 435 446 self.validator_list.append(self.isValidLength) 436 self.max length = maxlength447 self.max_length = max_length 437 448 438 449 def render(self, data): 439 450 if data is None: … … 710 721 #################### 711 722 712 723 class IntegerField(TextField): 713 def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None, member_name=None): 724 def __init__(self, field_name, length=10, max_length=None, 725 is_required=False, validator_list=None, member_name=None, 726 maxlength=None): 727 max_length = legacy_maxlength(max_length, maxlength) 714 728 if validator_list is None: validator_list = [] 715 729 validator_list = [self.isInteger] + validator_list 716 730 if member_name is not None: 717 731 self.member_name = member_name 718 TextField.__init__(self, field_name, length, max length, is_required, validator_list)732 TextField.__init__(self, field_name, length, max_length, is_required, validator_list) 719 733 720 734 def isInteger(self, field_data, all_data): 721 735 try: … … 730 744 html2python = staticmethod(html2python) 731 745 732 746 class SmallIntegerField(IntegerField): 733 def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=None): 747 def __init__(self, field_name, length=5, max_length=None, 748 is_required=False, v
