Ticket #8912: storage_save_8975.diff

File storage_save_8975.diff, 3.1 KB (added by shadfc, 16 years ago)

simple patch against r8975

  • django/db/models/fields/files.py

     
    7171
    7272    def save(self, name, content, save=True):
    7373        name = self.field.generate_filename(self.instance, name)
    74         self._name = self.storage.save(name, content)
     74        self._name = self.storage.save(name, content, save)
    7575        setattr(self.instance, self.field.name, self.name)
    7676
    7777        # Update the filesize cache
  • django/core/files/storage.py

     
    3232            file.__class__ = type(mixin.__name__, (mixin, file.__class__), {})
    3333        return file
    3434
    35     def save(self, name, content):
     35    def save(self, name, content, save=True):
    3636        """
    3737        Saves new content to the file specified by name. The content should be a
    3838        proper File object, ready to be read from the beginning.
     
    4242            name = content.name
    4343       
    4444        name = self.get_available_name(name)
    45         name = self._save(name, content)
     45        name = self._save(name, content, save)
    4646
    4747        # Store filenames with forward slashes, even on Windows
    4848        return force_unicode(name.replace('\\', '/'))
  • docs/howto/custom-file-storage.txt

     
    5858you'll want to return some subclass here that implements logic specific to the
    5959backend storage system.
    6060
    61 ``_save(name, content)``
     61``_save(name, content, save=True)``
    6262~~~~~~~~~~~~~~~~~~~~~~~~
    6363
    6464Called by ``Storage.save()``. The ``name`` will already have gone through
    6565``get_valid_name()`` and ``get_available_name()``, and the ``content`` will be a
    66 ``File`` object itself. No return value is expected.
     66``File`` object itself.  If the ``save`` argument is false, then the content
     67should not be saved to backend.  The actual name of the destination file is expected
     68as a return value, regardless of whether the save argument is True or False.
    6769
    6870``get_valid_name(name)``
    6971------------------------
  • docs/ref/files/storage.txt

     
    3434case of remote file storage this means that reading/writing could be quite slow,
    3535so be warned.
    3636
    37 ``Storage.save(name, content)``
     37``Storage.save(name, content, save=True)``
    3838~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3939
    4040Saves a new file using the storage system, preferably with the name specified.
     
    4646:class:`django.db.files.File` or of a subclass of
    4747:class:`~django.db.files.File`.
    4848
     49If the save argument is false, the proper ``name`` will still be returned, but
     50the file won't actually be saved to the backend.
     51
    4952``Storage.delete(name)``
    5053~~~~~~~~~~~~~~~~~~~~~~~~
    5154
Back to Top