Permalink
Browse files

Fixed #7830 -- Removed all of the remaining, deprecated, non-oldforms…

… features:

 * Support for representing files as strings was removed. Use `django.core.files.base.ContentFile` instead.
 * Support for representing uploaded files as dictionaries was removed. Use `django.core.files.uploadedfile.SimpleUploadedFile` instead.
 * The `filename`, `file_name`, `file_size`, and `chuck` properties of `UploadedFile` were removed. Use the `name`, `name`, `size`, and `chunks` properties instead, respectively.
 * The `get_FIELD_filename`, `get_FIELD_url`, `get_FIELD_size`, and `save_FIELD_file` methods for Models with `FileField` fields were removed. Instead, use the `path`, `url`, and `size` attributes and `save` method on the field itself, respectively.
 * The `get_FIELD_width` and `get_FIELD_height` methods for Models with `ImageField` fields were removed. Use the `width` and `height` attributes on the field itself instead.
 * The dispatcher `connect`, `disconnect`, `send`, and `sendExact` functions were removed. Use the signal object's own `connect`, `disconnect`, `send`, and `send` methods instead, respectively.
 * The `form_for_model` and `form_for_instance` functions were removed. Use a `ModelForm` subclass instead.
 * Support for importing `django.newforms` was removed. Use `django.forms` instead.
 * Support for importing `django.utils.images` was removed. Use `django.core.files.images` instead.
 * Support for the `follow` argument in the `create_object` and `update_object` generic views was removed. Use the `django.forms` package and the new `form_class` argument instead.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8291 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 94e8f4f commit ef48a3e69c02438db32f20531f5c679e8315d528 @gdub gdub committed Aug 10, 2008
@@ -36,19 +36,6 @@ def save(self, name, content):
Saves new content to the file specified by name. The content should be a
proper File object, ready to be read from the beginning.
"""
- # Check for old-style usage. Warn here first since there are multiple
- # locations where we need to support both new and old usage.
- if isinstance(content, basestring):
- import warnings
- warnings.warn(
- message = "Representing files as strings is deprecated." \
- "Use django.core.files.base.ContentFile instead.",
- category = DeprecationWarning,
- stacklevel = 2
- )
- from django.core.files.base import ContentFile
- content = ContentFile(content)
-
# Get the proper name for the file, as it will actually be saved.
if name is None:
name = content.name
@@ -3,42 +3,17 @@
"""
import os
-import warnings
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from django.conf import settings
from django.core.files.base import File
-
from django.core.files import temp as tempfile
-__all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile', 'SimpleUploadedFile')
-
-# Because we fooled around with it a bunch, UploadedFile has a bunch
-# of deprecated properties. This little shortcut helps define 'em
-# without too much code duplication.
-def deprecated_property(old, new, readonly=False):
- def issue_warning():
- warnings.warn(
- message = "UploadedFile.%s is deprecated; use UploadedFile.%s instead." % (old, new),
- category = DeprecationWarning,
- stacklevel = 3
- )
-
- def getter(self):
- issue_warning()
- return getattr(self, new)
-
- def setter(self, value):
- issue_warning()
- setattr(self, new, value)
-
- if readonly:
- return property(getter)
- else:
- return property(getter, setter)
+__all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile',
+ 'SimpleUploadedFile')
class UploadedFile(File):
"""
@@ -77,21 +52,6 @@ def _set_name(self, name):
name = property(_get_name, _set_name)
- # Deprecated properties
- filename = deprecated_property(old="filename", new="name")
- file_name = deprecated_property(old="file_name", new="name")
- file_size = deprecated_property(old="file_size", new="size")
- chunk = deprecated_property(old="chunk", new="chunks", readonly=True)
-
- def _get_data(self):
- warnings.warn(
- message = "UploadedFile.data is deprecated; use UploadedFile.read() instead.",
- category = DeprecationWarning,
- stacklevel = 2
- )
- return self.read()
- data = property(_get_data)
-
# Abstract methods; subclasses *must* define read() and probably should
# define open/close.
def read(self, num_bytes=None):
@@ -103,27 +63,6 @@ def open(self):
def close(self):
pass
- # Backwards-compatible support for uploaded-files-as-dictionaries.
- def __getitem__(self, key):
- warnings.warn(
- message = "The dictionary access of uploaded file objects is deprecated. Use the new object interface instead.",
- category = DeprecationWarning,
- stacklevel = 2
- )
- backwards_translate = {
- 'filename': 'name',
- 'content-type': 'content_type',
- }
-
- if key == 'content':
- return self.read()
- elif key == 'filename':
- return self.name
- elif key == 'content-type':
- return self.content_type
- else:
- return getattr(self, key)
-
class TemporaryUploadedFile(UploadedFile):
"""
A file uploaded to a temporary location (i.e. stream-to-disk).
@@ -140,7 +79,7 @@ def temporary_file_path(self):
Returns the full path of this file.
"""
return self._file.name
-
+
# Most methods on this object get proxied to NamedTemporaryFile.
# We can't directly subclass because NamedTemporaryFile is actually a
# factory function
@@ -159,9 +98,9 @@ def close(self):
# Still sets self._file.close_called and calls self._file.file.close()
# before the exception
return
- else:
+ else:
raise e
-
+
class InMemoryUploadedFile(UploadedFile):
"""
A file uploaded into memory (i.e. stream-to-memory).
@@ -3,7 +3,6 @@
import sys
import os
from itertools import izip
-from warnings import warn
try:
set
except NameError:
@@ -477,43 +476,6 @@ def _get_next_or_previous_in_order(self, is_next):
setattr(self, cachename, obj)
return getattr(self, cachename)
- def _get_FIELD_filename(self, field):
- warn("instance.get_%s_filename() is deprecated. Use instance.%s.path instead." % \
- (field.attname, field.attname), DeprecationWarning, stacklevel=3)
- try:
- return getattr(self, field.attname).path
- except ValueError:
- return ''
-
- def _get_FIELD_url(self, field):
- warn("instance.get_%s_url() is deprecated. Use instance.%s.url instead." % \
- (field.attname, field.attname), DeprecationWarning, stacklevel=3)
- try:
- return getattr(self, field.attname).url
- except ValueError:
- return ''
-
- def _get_FIELD_size(self, field):
- warn("instance.get_%s_size() is deprecated. Use instance.%s.size instead." % \
- (field.attname, field.attname), DeprecationWarning, stacklevel=3)
- return getattr(self, field.attname).size
-
- def _save_FIELD_file(self, field, filename, content, save=True):
- warn("instance.save_%s_file() is deprecated. Use instance.%s.save() instead." % \
- (field.attname, field.attname), DeprecationWarning, stacklevel=3)
- return getattr(self, field.attname).save(filename, content, save)
-
- _save_FIELD_file.alters_data = True
-
- def _get_FIELD_width(self, field):
- warn("instance.get_%s_width() is deprecated. Use instance.%s.width instead." % \
- (field.attname, field.attname), DeprecationWarning, stacklevel=3)
- return getattr(self, field.attname).width()
-
- def _get_FIELD_height(self, field):
- warn("instance.get_%s_height() is deprecated. Use instance.%s.height instead." % \
- (field.attname, field.attname), DeprecationWarning, stacklevel=3)
- return getattr(self, field.attname).height()
############################################
@@ -192,10 +192,6 @@ def isWithinMediaRoot(field_data, all_data):
def contribute_to_class(self, cls, name):
super(FileField, self).contribute_to_class(cls, name)
setattr(cls, self.name, FileDescriptor(self))
- setattr(cls, 'get_%s_filename' % self.name, curry(cls._get_FIELD_filename, field=self))
- setattr(cls, 'get_%s_url' % self.name, curry(cls._get_FIELD_url, field=self))
- setattr(cls, 'get_%s_size' % self.name, curry(cls._get_FIELD_size, field=self))
- setattr(cls, 'save_%s_file' % self.name, lambda instance, name, content, save=True: instance._save_FIELD_file(self, name, content, save))
signals.post_delete.connect(self.delete_file, sender=cls)
def delete_file(self, instance, sender, **kwargs):
@@ -262,26 +258,15 @@ def formfield(self, **kwargs):
class ImageFieldFile(ImageFile, FieldFile):
def save(self, name, content, save=True):
-
- if not hasattr(content, 'read'):
- import warnings
- warnings.warn(
- message = "Representing files as strings is deprecated." \
- "Use django.core.files.base.ContentFile instead.",
- category = DeprecationWarning,
- stacklevel = 2
- )
- content = ContentFile(content)
-
# Repopulate the image dimension cache.
self._dimensions_cache = get_image_dimensions(content)
-
+
# Update width/height fields, if needed
if self.field.width_field:
setattr(self.instance, self.field.width_field, self.width)
if self.field.height_field:
setattr(self.instance, self.field.height_field, self.height)
-
+
super(ImageFieldFile, self).save(name, content, save)
def delete(self, save=True):
@@ -300,15 +285,6 @@ def __init__(self, verbose_name=None, name=None, width_field=None, height_field=
def get_manipulator_field_objs(self):
return [oldforms.ImageUploadField, oldforms.HiddenField]
- def contribute_to_class(self, cls, name):
- super(ImageField, self).contribute_to_class(cls, name)
- # Add get_BLAH_width and get_BLAH_height methods, but only if the
- # image field doesn't have width and height cache fields.
- if not self.width_field:
- setattr(cls, 'get_%s_width' % self.name, curry(cls._get_FIELD_width, field=self))
- if not self.height_field:
- setattr(cls, 'get_%s_height' % self.name, curry(cls._get_FIELD_height, field=self))
-
def formfield(self, **kwargs):
defaults = {'form_class': forms.ImageField}
defaults.update(kwargs)
@@ -1,5 +1,4 @@
import weakref
-import warnings
try:
set
except NameError:
@@ -197,47 +196,3 @@ def _remove_receiver(self, receiver):
for idx, (r_key, _) in enumerate(self.receivers):
if r_key == key:
del self.receivers[idx]
-
-def connect(receiver, signal, sender=None, weak=True):
- """
- For backward compatibility only. See Signal.connect()
- """
- warnings.warn(
- category = DeprecationWarning,
- message = "dispatcher.connect() is deprecated; use Signal.connect() instead.",
- stacklevel = 2
- )
- return signal.connect(receiver, sender, weak)
-
-def disconnect(receiver, signal, sender=None, weak=True):
- """
- For backward compatibility only. See Signal.disconnect()
- """
- warnings.warn(
- category = DeprecationWarning,
- message = "dispatcher.disconnect() is deprecated; use Signal.disconnect() instead.",
- stacklevel = 2
- )
- signal.disconnect(receiver, sender, weak)
-
-def send(signal, sender=None, **named):
- """
- For backward compatibility only. See Signal.send()
- """
- warnings.warn(
- category = DeprecationWarning,
- message = "dispatcher.send() is deprecated; use Signal.send() instead.",
- stacklevel = 2
- )
- return signal.send(sender=sender, **named)
-
-def sendExact(signal, sender, **named ):
- """
- This function is deprecated, as it now has the same meaning as send.
- """
- warnings.warn(
- category = DeprecationWarning,
- message = "dispatcher.sendExact() is deprecated; use Signal.send() instead.",
- stacklevel = 2
- )
- return signal.send(sender=sender, **named)
@@ -442,16 +442,7 @@ def clean(self, data, initial=None):
elif not data and initial:
return initial
- if isinstance(data, dict):
- # We warn once, then support both ways below.
- import warnings
- warnings.warn(
- message = "Representing uploaded files as dictionaries is deprecated. Use django.core.files.uploadedfile.SimpleUploadedFile instead.",
- category = DeprecationWarning,
- stacklevel = 2
- )
- data = UploadedFile(data['filename'], data['content'])
-
+ # UploadedFile objects should have name and size attributes.
try:
file_name = data.name
file_size = data.size
@@ -507,10 +498,10 @@ def clean(self, data, initial=None):
# but it must be called immediately after the constructor
trial_image = Image.open(file)
trial_image.verify()
- except ImportError:
+ except ImportError:
# Under PyPy, it is possible to import PIL. However, the underlying
- # _imaging C module isn't available, so an ImportError will be
- # raised. Catch and re-raise.
+ # _imaging C module isn't available, so an ImportError will be
+ # raised. Catch and re-raise.
raise
except Exception: # Python Imaging Library doesn't recognize it as an image
raise ValidationError(self.error_messages['invalid_image'])
@@ -643,7 +634,7 @@ def valid_value(self, value):
if value == smart_unicode(k):
return True
return False
-
+
class MultipleChoiceField(ChoiceField):
hidden_widget = MultipleHiddenInput
widget = SelectMultiple
Oops, something went wrong.

0 comments on commit ef48a3e

Please sign in to comment.