Ticket #231: max_length_cleanups_with_docs.diff
File max_length_cleanups_with_docs.diff, 13.0 KB (added by , 17 years ago) |
---|
-
django/db/models/fields/__init__.py
686 686 687 687 class EmailField(CharField): 688 688 def __init__(self, *args, **kwargs): 689 if 'max_length' not in kwargs: 690 kwargs['max_length'] = 75 689 kwargs['max_length'] = kwargs.get('max_length', 75) 691 690 CharField.__init__(self, *args, **kwargs) 692 691 693 692 def get_internal_type(self): … … 707 706 class FileField(Field): 708 707 def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs): 709 708 self.upload_to = upload_to 709 kwargs['max_length'] = kwargs.get('max_length', 100) 710 710 Field.__init__(self, verbose_name, name, **kwargs) 711 711 712 712 def get_db_prep_save(self, value): … … 808 808 class FilePathField(Field): 809 809 def __init__(self, verbose_name=None, name=None, path='', match=None, recursive=False, **kwargs): 810 810 self.path, self.match, self.recursive = path, match, recursive 811 kwargs['max_length'] = kwargs.get('max_length', 100) 811 812 Field.__init__(self, verbose_name, name, **kwargs) 812 813 813 814 def get_manipulator_field_objs(self): -
django/db/backends/ado_mssql/creation.py
6 6 'DateField': 'smalldatetime', 7 7 'DateTimeField': 'smalldatetime', 8 8 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', 9 'FileField': 'varchar( 100)',10 'FilePathField': 'varchar( 100)',9 'FileField': 'varchar(%(max_length)s)', 10 'FilePathField': 'varchar(%(max_length)s)', 11 11 'FloatField': 'double precision', 12 'ImageField': 'varchar( 100)',12 'ImageField': 'varchar(%(max_length)s)', 13 13 'IntegerField': 'int', 14 14 'IPAddressField': 'char(15)', 15 15 'NullBooleanField': 'bit', -
django/db/backends/mysql_old/creation.py
10 10 'DateField': 'date', 11 11 'DateTimeField': 'datetime', 12 12 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', 13 'FileField': 'varchar( 100)',14 'FilePathField': 'varchar( 100)',13 'FileField': 'varchar(%(max_length)s)', 14 'FilePathField': 'varchar(%(max_length)s)', 15 15 'FloatField': 'double precision', 16 'ImageField': 'varchar( 100)',16 'ImageField': 'varchar(%(max_length)s)', 17 17 'IntegerField': 'integer', 18 18 'IPAddressField': 'char(15)', 19 19 'NullBooleanField': 'bool', -
django/db/backends/postgresql/creation.py
10 10 'DateField': 'date', 11 11 'DateTimeField': 'timestamp with time zone', 12 12 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', 13 'FileField': 'varchar( 100)',14 'FilePathField': 'varchar( 100)',13 'FileField': 'varchar(%(max_length)s)', 14 'FilePathField': 'varchar(%(max_length)s)', 15 15 'FloatField': 'double precision', 16 'ImageField': 'varchar( 100)',16 'ImageField': 'varchar(%(max_length)s)', 17 17 'IntegerField': 'integer', 18 18 'IPAddressField': 'inet', 19 19 'NullBooleanField': 'boolean', -
django/db/backends/sqlite3/creation.py
9 9 'DateField': 'date', 10 10 'DateTimeField': 'datetime', 11 11 'DecimalField': 'decimal', 12 'FileField': 'varchar( 100)',13 'FilePathField': 'varchar( 100)',12 'FileField': 'varchar(%(max_length)s)', 13 'FilePathField': 'varchar(%(max_length)s)', 14 14 'FloatField': 'real', 15 'ImageField': 'varchar( 100)',15 'ImageField': 'varchar(%(max_length)s)', 16 16 'IntegerField': 'integer', 17 17 'IPAddressField': 'char(15)', 18 18 'NullBooleanField': 'bool', -
django/db/backends/mysql/creation.py
10 10 'DateField': 'date', 11 11 'DateTimeField': 'datetime', 12 12 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', 13 'FileField': 'varchar( 100)',14 'FilePathField': 'varchar( 100)',13 'FileField': 'varchar(%(max_length)s)', 14 'FilePathField': 'varchar(%(max_length)s)', 15 15 'FloatField': 'double precision', 16 'ImageField': 'varchar( 100)',16 'ImageField': 'varchar(%(max_length)s)', 17 17 'IntegerField': 'integer', 18 18 'IPAddressField': 'char(15)', 19 19 'NullBooleanField': 'bool', -
django/db/backends/oracle/creation.py
13 13 'DateField': 'DATE', 14 14 'DateTimeField': 'TIMESTAMP', 15 15 'DecimalField': 'NUMBER(%(max_digits)s, %(decimal_places)s)', 16 'FileField': 'NVARCHAR2( 100)',17 'FilePathField': 'NVARCHAR2( 100)',16 'FileField': 'NVARCHAR2(%(max_length)s)', 17 'FilePathField': 'NVARCHAR2(%(max_length)s)', 18 18 'FloatField': 'DOUBLE PRECISION', 19 'ImageField': 'NVARCHAR2( 100)',19 'ImageField': 'NVARCHAR2(%(max_length)s)', 20 20 'IntegerField': 'NUMBER(11)', 21 21 'IPAddressField': 'VARCHAR2(15)', 22 22 'NullBooleanField': 'NUMBER(1) CHECK ((%(column)s IN (0,1)) OR (%(column)s IS NULL))', … … 28 28 'SmallIntegerField': 'NUMBER(11)', 29 29 'TextField': 'NCLOB', 30 30 'TimeField': 'TIMESTAMP', 31 'URLField': 'VARCHAR2( 200)',31 'URLField': 'VARCHAR2(%(max_length)s)', 32 32 'USStateField': 'CHAR(2)', 33 33 } 34 34 -
django/oldforms/__init__.py
447 447 self.field_name, self.rows, self.cols, escape(data)) 448 448 449 449 class HiddenField(FormField): 450 def __init__(self, field_name, is_required=False, validator_list=None ):450 def __init__(self, field_name, is_required=False, validator_list=None, max_length=None): 451 451 if validator_list is None: validator_list = [] 452 452 self.field_name, self.is_required = field_name, is_required 453 453 self.validator_list = validator_list[:] … … 674 674 #################### 675 675 676 676 class FileUploadField(FormField): 677 def __init__(self, field_name, is_required=False, validator_list=None ):677 def __init__(self, field_name, is_required=False, validator_list=None, max_length=None): 678 678 if validator_list is None: validator_list = [] 679 679 self.field_name, self.is_required = field_name, is_required 680 680 self.validator_list = [self.isNonEmptyFile] + validator_list … … 946 946 947 947 class FilePathField(SelectField): 948 948 "A SelectField whose choices are the files in a given directory." 949 def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None ):949 def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None, max_length=None): 950 950 import os 951 951 from django.db.models import BLANK_CHOICE_DASH 952 952 if match is not None: -
tests/regressiontests/max_lengths/__init__.py
1 -
tests/regressiontests/max_lengths/tests.py
1 from django.test import TestCase 2 from regressiontests.max_lengths.models import OldPerson, NewPerson 3 4 class MaxLengths(TestCase): 5 6 def verify_max_length(self, model,field,length): 7 self.assertEquals(model._meta.get_field(field).max_length,length) 8 9 def test_oldp(self): 10 self.verify_max_length(OldPerson, 'email', 75) 11 self.verify_max_length(OldPerson, 'vcard', 100) 12 self.verify_max_length(OldPerson, 'your_mom', 100) 13 self.verify_max_length(OldPerson, 'homepage', 200) 14 self.verify_max_length(OldPerson, 'avatar', 100) 15 16 def test_newp(self): 17 self.verify_max_length(NewPerson, 'email', 384) 18 self.verify_max_length(NewPerson, 'vcard', 1024) 19 self.verify_max_length(NewPerson, 'your_mom', 512) 20 self.verify_max_length(NewPerson, 'homepage', 256) 21 self.verify_max_length(NewPerson, 'avatar', 512) -
tests/regressiontests/max_lengths/models.py
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: tests/regressiontests/max_lengths/__init__.pyc ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
1 from django.db import models 2 3 class OldPerson(models.Model): 4 email = models.EmailField() 5 vcard = models.FileField(upload_to='/tmp') 6 your_mom = models.ImageField(upload_to='/tmp') 7 homepage = models.URLField() 8 avatar = models.FilePathField() 9 10 class NewPerson(models.Model): 11 email = models.EmailField(max_length=384) 12 vcard = models.FileField(upload_to='/tmp', max_length=1024) 13 your_mom = models.ImageField(upload_to='/tmp', max_length=512) 14 homepage = models.URLField(max_length=256) 15 avatar = models.FilePathField(max_length=512) -
docs/model-api.txt
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: tests/regressiontests/max_lengths/tests.pyc ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: tests/regressiontests/max_lengths/models.pyc ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
293 293 294 294 .. _`strftime formatting`: http://docs.python.org/lib/module-time.html#l2h-1941 295 295 296 In Django 0.96, this doesn't accept ``max_length``; its ``max_length`` is 297 automatically set to 100. In the Django development version, ``max_length`` is 298 set to 100 by default, but you can specify it to override default behavior. 299 296 300 ``FilePathField`` 297 301 ~~~~~~~~~~~~~~~~~ 298 302 … … 330 334 because the ``match`` applies to the base filename (``foo.gif`` and 331 335 ``bar.gif``). 332 336 337 In Django 0.96, this doesn't accept ``max_length``; its ``max_length`` is 338 automatically set to 100. In the Django development version, ``max_length`` is 339 set to 100 by default, but you can specify it to override default behavior. 340 333 341 ``FloatField`` 334 342 ~~~~~~~~~~~~~~ 335 343 … … 361 369 .. _Python Imaging Library: http://www.pythonware.com/products/pil/ 362 370 .. _elsewhere: ../db-api/#get-foo-height-and-get-foo-width 363 371 372 In Django 0.96, this doesn't accept ``max_length``; its ``max_length`` is 373 automatically set to 100. In the Django development version, ``max_length`` is 374 set to 100 by default, but you can specify it to override default behavior. 375 364 376 ``IntegerField`` 365 377 ~~~~~~~~~~~~~~~~ 366 378