~ubuntu-branches/ubuntu/natty/python-django/natty-security

« back to all changes in this revision

Viewing changes to django/db/models/fields/files.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2011-02-17 13:34:07 UTC
  • mfrom: (1.1.13 upstream) (4.4.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110217133407-rwr88elhhq6j7ba0
Tags: 1.2.5-1ubuntu1
* Merge from Debian for security fixes (LP: #719031). Remaining changes:
  - debian/control: don't Build-Depends on locales-all, which doesn't exist
    in natty
* Drop the following patches, now included upstream:
  - debian/patches/07_security_admin_infoleak.diff
  - debian/patches/08_security_pasword_reset_dos.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
    def _get_size(self):
74
74
        self._require_file()
75
75
        if not self._committed:
76
 
            return len(self.file)
 
76
            return self.file.size
77
77
        return self.storage.size(self.name)
78
78
    size = property(_get_size)
79
79
 
93
93
        setattr(self.instance, self.field.name, self.name)
94
94
 
95
95
        # Update the filesize cache
96
 
        self._size = len(content)
 
96
        self._size = content.size
97
97
        self._committed = True
98
98
 
99
99
        # Save the object because it has changed, unless save is False
258
258
    def contribute_to_class(self, cls, name):
259
259
        super(FileField, self).contribute_to_class(cls, name)
260
260
        setattr(cls, self.name, self.descriptor_class(self))
261
 
        signals.post_delete.connect(self.delete_file, sender=cls)
262
 
 
263
 
    def delete_file(self, instance, sender, **kwargs):
264
 
        file = getattr(instance, self.attname)
265
 
        # If no other object of this type references the file,
266
 
        # and it's not the default value for future objects,
267
 
        # delete it from the backend.
268
 
        if file and file.name != self.default and \
269
 
            not sender._default_manager.filter(**{self.name: file.name}):
270
 
                file.delete(save=False)
271
 
        elif file:
272
 
            # Otherwise, just close the file, so it doesn't tie up resources.
273
 
            file.close()
274
261
 
275
262
    def get_directory_name(self):
276
263
        return os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(self.upload_to))))