Commit ef48a3e6 authored by Gary Wilson Jr's avatar Gary Wilson Jr
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
parent 94e8f4fb
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -36,19 +36,6 @@ class Storage(object):
        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
+5 −66
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ Classes representing uploaded files.
"""

import os
import warnings
try:
    from cStringIO import StringIO
except ImportError:
@@ -11,34 +10,10 @@ except ImportError:

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 @@ class UploadedFile(File):

    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 @@ class UploadedFile(File):
    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).
+0 −38
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ import types
import sys
import os
from itertools import izip
from warnings import warn
try:
    set
except NameError:
@@ -477,43 +476,6 @@ class Model(object):
            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()


############################################
+2 −26
Original line number Diff line number Diff line
@@ -192,10 +192,6 @@ class FileField(Field):
    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,17 +258,6 @@ class FileField(Field):

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)

@@ -300,15 +285,6 @@ class ImageField(FileField):
    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)
+0 −45
Original line number Diff line number Diff line
import weakref
import warnings
try:
    set
except NameError:
@@ -197,47 +196,3 @@ class Signal(object):
            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)
Loading