Changeset 5822 for django/branches/schema-evolution/django
- Timestamp:
- 08/06/07 11:50:17 (1 year ago)
- Files:
-
- django/branches/schema-evolution/django/contrib/admin/models.py (modified) (1 diff)
- django/branches/schema-evolution/django/contrib/admin/templatetags/admin_modify.py (modified) (1 diff)
- django/branches/schema-evolution/django/contrib/admin/views/doc.py (modified) (2 diffs)
- django/branches/schema-evolution/django/contrib/admin/views/main.py (modified) (1 diff)
- django/branches/schema-evolution/django/contrib/auth/forms.py (modified) (4 diffs)
- django/branches/schema-evolution/django/contrib/auth/models.py (modified) (3 diffs)
- django/branches/schema-evolution/django/contrib/comments/models.py (modified) (2 diffs)
- django/branches/schema-evolution/django/contrib/comments/views/comments.py (modified) (2 diffs)
- django/branches/schema-evolution/django/contrib/contenttypes/models.py (modified) (1 diff)
- django/branches/schema-evolution/django/contrib/flatpages/models.py (modified) (1 diff)
- django/branches/schema-evolution/django/contrib/redirects/models.py (modified) (1 diff)
- django/branches/schema-evolution/django/contrib/sessions/models.py (modified) (1 diff)
- django/branches/schema-evolution/django/contrib/sites/models.py (modified) (1 diff)
- django/branches/schema-evolution/django/core/management.py (modified) (7 diffs)
- django/branches/schema-evolution/django/core/validators.py (modified) (1 diff)
- django/branches/schema-evolution/django/db/backends/ado_mssql/creation.py (modified) (2 diffs)
- django/branches/schema-evolution/django/db/backends/mysql/creation.py (modified) (2 diffs)
- django/branches/schema-evolution/django/db/backends/mysql_old/creation.py (modified) (2 diffs)
- django/branches/schema-evolution/django/db/backends/oracle/creation.py (modified) (1 diff)
- django/branches/schema-evolution/django/db/backends/postgresql/creation.py (modified) (2 diffs)
- django/branches/schema-evolution/django/db/backends/sqlite3/creation.py (modified) (2 diffs)
- django/branches/schema-evolution/django/db/backends/sqlite3/introspection.py (modified) (1 diff)
- django/branches/schema-evolution/django/db/models/fields/__init__.py (modified) (14 diffs)
- django/branches/schema-evolution/django/db/models/fields/related.py (modified) (1 diff)
- django/branches/schema-evolution/django/newforms/extras/widgets.py (modified) (1 diff)
- django/branches/schema-evolution/django/newforms/fields.py (modified) (4 diffs)
- django/branches/schema-evolution/django/newforms/forms.py (modified) (4 diffs)
- django/branches/schema-evolution/django/newforms/models.py (modified) (1 diff)
- django/branches/schema-evolution/django/newforms/widgets.py (modified) (6 diffs)
- django/branches/schema-evolution/django/oldforms/__init__.py (modified) (20 diffs)
- django/branches/schema-evolution/django/template/defaulttags.py (modified) (2 diffs)
- django/branches/schema-evolution/django/utils/encoding.py (modified) (1 diff)
- django/branches/schema-evolution/django/utils/maxlength.py (copied) (copied from django/trunk/django/utils/maxlength.py)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/schema-evolution/django/contrib/admin/models.py
r5734 r5822 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) django/branches/schema-evolution/django/contrib/admin/templatetags/admin_modify.py
r5734 r5822 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) django/branches/schema-evolution/django/contrib/admin/views/doc.py
r5734 r5822 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)'), … … 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'), django/branches/schema-evolution/django/contrib/admin/views/main.py
r5734 r5822 674 674 attr = getattr(lookup_opts.admin.manager.model, field_name) 675 675 order_field = attr.admin_order_field 676 except IndexError:676 except AttributeError: 677 677 pass 678 678 else: django/branches/schema-evolution/django/contrib/auth/forms.py
r5734 r5822 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 ) … … 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 … … 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 … … 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 ) django/branches/schema-evolution/django/contrib/auth/models.py
r5788 r5822 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: … … 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 … … 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.")) django/branches/schema-evolution/django/contrib/comments/models.py
r5734 r5822 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) … … 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')) django/branches/schema-evolution/django/contrib/comments/views/comments.py
r5734 r5822 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, … … 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 ) django/branches/schema-evolution/django/contrib/contenttypes/models.py
r5734 r5822 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: django/branches/schema-evolution/django/contrib/flatpages/models.py
r5734 r5822 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.")) django/branches/schema-evolution/django/contrib/redirects/models.py
r5734 r5822 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 django/branches/schema-evolution/django/contrib/sessions/models.py
r5734 r5822 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')) django/branches/schema-evolution/django/contrib/sites/models.py
r5734 r5822 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: django/branches/schema-evolution/django/core/management.py
r5821 r5822 1065 1065 extra_params.update(new_params) 1066 1066 1067 # Add max length for all CharFields.1067 # Add max_length for all CharFields. 1068 1068 if field_type == 'CharField' and row[3]: 1069 extra_params['max length'] = row[3]1069 extra_params['max_length'] = row[3] 1070 1070 1071 1071 if field_type == 'DecimalField': … … 1142 1142 if f.name == 'id' and not f.primary_key and opts.pk.name == 'id': 1143 1143 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) 1144 if isinstance(f, models.CharField) and f.max length in (None, 0):1145 e.add(opts, '"%s": CharFields require a "max length" attribute.' % f.name)1144 if isinstance(f, models.CharField) and f.max_length in (None, 0): 1145 e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name) 1146 1146 if isinstance(f, models.DecimalField): 1147 1147 if f.decimal_places is None: … … 1168 1168 e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name) 1169 1169 1170 # Check that max length <= 255 if using older MySQL versions.1170 # Check that max_length <= 255 if using older MySQL versions. 1171 1171 if settings.DATABASE_ENGINE == 'mysql': 1172 1172 db_version = connection.get_server_version() 1173 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max length > 255:1174 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]])))1173 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255: 1174 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]]))) 1175 1175 1176 1176 # Check to see if the related field will clash with any … … 1407 1407 fields = ( 1408 1408 # "key" is a reserved word in MySQL, so use "cache_key" instead. 1409 models.CharField(name='cache_key', max length=255, unique=True, primary_key=True),1409 models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True), 1410 1410 models.TextField(name='value'), 1411 1411 models.DateTimeField(name='expires', db_index=True), … … 1455 1455 except ImportError: 1456 1456 import code 1457 # Set up a dictionary to serve as the environment for the shell, so 1458 # that tab completion works on objects that are imported at runtime. 1459 # See ticket 5082. 1460 imported_objects = {} 1457 1461 try: # Try activating rlcompleter, because it's handy. 1458 1462 import readline … … 1463 1467 # we already know 'readline' was imported successfully. 1464 1468 import rlcompleter 1469 readline.set_completer(rlcompleter.Completer(imported_objects).complete) 1465 1470 readline.parse_and_bind("tab:complete") 1466 code.interact( )1471 code.interact(local=imported_objects) 1467 1472 run_shell.args = '[--plain]' 1468 1473 … … 1579 1584 (format, fixture_name, humanize(fixture_dir)) 1580 1585 try: 1581 objects = serializers.deserialize(format, fixture)1586 objects = serializers.deserialize(format, fixture) 1582 1587 for obj in objects: 1583 1588 count[0] += 1 django/branches/schema-evolution/django/core/validators.py
r5734 r5822 443 443 float(data) 444 444 except ValueError: 445 raise ValidationError, ugettext("Please enter a valid floating point number.")445 raise ValidationError, _("Please enter a valid floating point number.") 446 446 447 447 class HasAllowableSize(object): django/branches/schema-evolution/django/db/backends/ado_mssql/creation.py
r5734 r5822 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', … … 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', django/branches/schema-evolution/django/db/backends/mysql/creation.py
r5734 r5822 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', … … 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', django/branches/schema-evolution/django/db/backends/mysql_old/creation.py
r5734 r5822 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', … … 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', django/branches/schema-evolution/django/db/backends/oracle/creation.py
r5734 r5822 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', django/branches/schema-evolution/django/db/backends/postgresql/creation.py
r5734 r5822 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', … … 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', django/branches/schema-evolution/django/db/backends/sqlite3/creation.py
r5734 r5822 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', … … 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', django/branches/schema-evolution/django/db/backends/sqlite3/introspection.py
r5787 r5822 138 138 m = re.search(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$', key) 139 139 if m: 140 return ('CharField', {'max length': int(m.group(1))})140 return ('CharField', {'max_length': int(m.group(1))}) 141 141 raise KeyError 142 142 django/branches/schema-evolution/django/db/models/fields/__init__.py
r5788 r5822 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 LegacyMaxlength 14 15 import datetime, os, time 15 16 try: … … 64 65 65 66 class Field(object): 67 # Provide backwards compatibility for the maxlength attribute and 68 # argument for this class and all subclasses. 69 __metaclass__ = LegacyMaxlength 66 70 67 71 # Designates whether empty strings fundamentally are allowed at the … … 73 77 74 78 def __init__(self, verbose_name=None, name=None, primary_key=False, 75 max length=None, unique=False, blank=False, null=False, db_index=False,79 max_length=None, unique=False, blank=False, null=False, db_index=False, 76 80 core=False, rel=None, default=NOT_PROVIDED, editable=True, serialize=True, 77 81 prepopulate_from=None, unique_for_date=None, unique_for_month=None, … … 81 85 self.verbose_name = verbose_name 82 86 self.primary_key = primary_key 83 self.max length, self.unique = maxlength, unique87 self.max_length, self.unique = max_length, unique 84 88 self.blank, self.null = blank, null 85 89 # Oracle treats the empty string ('') as null, so coerce the null … … 246 250 def prepare_field_objs_and_params(self, manipulator, name_prefix): 247 251 params = {'validator_list': self.validator_list[:]} 248 if self.max length and not self.choices: # Don't give SelectFields a maxlength parameter.249 params['max length'] = self.maxlength252 if self.max_length and not self.choices: # Don't give SelectFields a max_length parameter. 253 params['max_length'] = self.max_length 250 254 251 255 if self.choices: … … 378 382 choices = property(_get_choices) 379 383 384 def save_form_data(self, instance, data): 385 setattr(instance, self.name, data) 386 380 387 def formfield(self, form_class=forms.CharField, **kwargs): 381 388 "Returns a django.newforms.Field instance for this database Field." … … 463 470 464 471 def formfield(self, **kwargs): 465 defaults = {'max_length': self.max length}472 defaults = {'max_length': self.max_length} 466 473 defaults.update(kwargs) 467 474 return super(CharField, self).formfield(**defaults) … … 672 679 class EmailField(CharField): 673 680 def __init__(self, *args, **kwargs): 674 kwargs['max length'] = 75681 kwargs['max_length'] = 75 675 682 CharField.__init__(self, *args, **kwargs) 676 683 … … 693 700 self.upload_to = upload_to 694 701 Field.__init__(self, verbose_name, name, **kwargs) 702 703 def get_db_prep_save(self, value): 704 "Returns field's value prepared for saving into a database." 705 # Need to convert UploadedFile objects provided via a form to unicode for database insertion 706 if value is None: 707 return None 708 return unicode(value) 695 709 696 710 def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True): … … 770 784 return os.path.normpath(f) 771 785 786 def save_form_data(self, instance, data): 787 if data: 788 getattr(instance, "save_%s_file" % self.name)(os.path.join(self.upload_to, data.filename), data.content, save=False) 789 790 def formfield(self, **kwargs): 791 defaults = {'form_class': forms.FileField} 792 # If a file has been provided previously, then the form doesn't require 793 # that a new file is provided this time. 794 if 'initial' in kwargs: 795 defaults['required'] = False 796 defaults.update(kwargs) 797 return super(FileField, self).formfield(**defaults) 798 772 799 class FilePathField(Field): 773 800 def __init__(self, verbose_name=None, name=None, path='', match=None, recursive=False, **kwargs): … … 818 845 new_object.save() 819 846 847 def formfield(self, **kwargs): 848 defaults = {'form_class': forms.ImageField} 849 return super(ImageField, self).formfield(**defaults) 850 820 851 class IntegerField(Field): 821 852 empty_strings_allowed = False … … 831 862 empty_strings_allowed = False 832 863 def __init__(self, *args, **kwargs): 833 kwargs['max length'] = 15864 kwargs['max_length'] = 15 834 865 Field.__init__(self, *args, **kwargs) 835 866 … … 879 910 class SlugField(Field): 880 911 def __init__(self, *args, **kwargs): 881 kwargs['max length'] = kwargs.get('maxlength', 50)912 kwargs['max_length'] = kwargs.get('max_length', 50) 882 913 kwargs.setdefault('validator_list', []).append(validators.isSlug) 883 914 # Set db_index=True unless it's been set manually. … … 965 996 class URLField(CharField): 966 997 def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): 967 kwargs['max length'] = kwargs.get('maxlength', 200)998 kwargs['max_length'] = kwargs.get('max_length', 200) 968 999 if verify_exists: 969 1000 kwargs.setdefault('validator_list', []).append(validators.isExistingURL) django/branches/schema-evolution/django/db/models/fields/related.py
r5734 r5822 757 757 return getattr(obj, self.attname).all() 758 758 759 def save_form_data(self, instance, data): 760 setattr(instance, self.attname, data) 761 759 762 def formfield(self, **kwargs): 760 763 defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.all()} django/branches/schema-evolution/django/newforms/extras/widgets.py
r5734 r5822 54 54 return u'\n'.join(output) 55 55 56 def value_from_datadict(self, data, name):56 def value_from_datadict(self, data, files, name): 57 57 y, m, d = data.get(self.year_field % name), data.get(self.month_field % name), data.get(self.day_field % name) 58 58 if y and m and d: django/branches/schema-evolution/django/newforms/fields.py
r5734 r5822 8 8 9 9 from django.utils.translation import ugettext 10 from django.utils.encoding import smart_unicode10 from django.utils.encoding import StrAndUnicode, smart_unicode 11 11 12 12 from util import ErrorList, ValidationError 13 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple13 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple 14 14 15 15 try: … … 23 23 'DEFAULT_TIME_INPUT_FORMATS', 'TimeField', 24 24 'DEFAULT_DATETIME_INPUT_FORMATS', 'DateTimeField', 25 'RegexField', 'EmailField', ' URLField', 'BooleanField',25 'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField', 'BooleanField', 26 26 'ChoiceField', 'NullBooleanField', 'MultipleChoiceField', 27 27 'ComboField', 'MultiValueField', 'FloatField', 'DecimalField', … … 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 … … 348 349 URL_VALIDATOR_USER_AGENT = 'Django (http://www.djangoproject.com/)' 349 350 351 class UploadedFile(StrAndUnicode): 352 "A wrapper for files uploaded in a FileField" 353 def __init__(self, filename, content): 354 self.filename = filename 355 self.content = content 356 357 def __unicode__(self): 358 """ 359 The unicode representation is the filename, so that the pre-database-insertion 360 logic can use UploadedFile objects 361 """ 362 return self.filename 363 364 class FileField(Field): 365 widget = FileInput 366 def __init__(self, *args, **kwargs): 367 super(FileField, self).__init__(*args, **kwargs) 368 369 def clean(self, data): 370 super(FileField, self).clean(data) 371 if not self.required and data in EMPTY_VALUES: 372 return None 373 try: 374 f = UploadedFile(data['filename'], data['content']) 375 except TypeError: 376 raise ValidationError(ugettext(u"No file was submitted. Check the encoding type on the form.")) 377 except KeyError: 378 raise ValidationError(ugettext(u"No file was submitted.")) 379 if not f.content: 380 raise ValidationError(ugettext(u"The submitted file is empty.")) 381 return f 382 383 class ImageField(FileField): 384 def clean(self, data): 385 """ 386 Checks that the file-upload field data contains a valid image (GIF, JPG, 387 PNG,
