mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #9893 -- Allowed using a field's max_length in the Storage.
This commit is contained in:
parent
b5c1a85b50
commit
a7c256cb54
8 changed files with 194 additions and 21 deletions
|
@ -114,12 +114,17 @@ The Storage Class
|
|||
in the storage system, or ``False`` if the name is available for a new
|
||||
file.
|
||||
|
||||
.. method:: get_available_name(name)
|
||||
.. method:: get_available_name(name, max_length=None)
|
||||
|
||||
Returns a filename based on the ``name`` parameter that's free and
|
||||
available for new content to be written to on the target storage
|
||||
system.
|
||||
|
||||
The length of the filename will not exceed ``max_length``, if provided.
|
||||
If a free unique filename cannot be found, a
|
||||
:exc:`SuspiciousFileOperation
|
||||
<django.core.exceptions.SuspiciousOperation>` exception will be raised.
|
||||
|
||||
If a file with ``name`` already exists, an underscore plus a random
|
||||
7 character alphanumeric string is appended to the filename before
|
||||
the extension.
|
||||
|
@ -133,6 +138,10 @@ The Storage Class
|
|||
attack. This change was also made in Django 1.6.6, 1.5.9, and
|
||||
1.4.14.
|
||||
|
||||
.. versionchanged:: 1.8
|
||||
|
||||
The ``max_length`` argument was added.
|
||||
|
||||
.. method:: get_valid_name(name)
|
||||
|
||||
Returns a filename based on the ``name`` parameter that's suitable
|
||||
|
@ -165,17 +174,24 @@ The Storage Class
|
|||
standard ``open()``. For storage systems that aren't accessible from
|
||||
the local filesystem, this will raise ``NotImplementedError`` instead.
|
||||
|
||||
.. method:: save(name, content)
|
||||
.. method:: save(name, content, max_length=None)
|
||||
|
||||
Saves a new file using the storage system, preferably with the name
|
||||
specified. If there already exists a file with this name ``name``, the
|
||||
storage system may modify the filename as necessary to get a unique
|
||||
name. The actual name of the stored file will be returned.
|
||||
|
||||
The ``max_length`` argument is passed along to
|
||||
:meth:`get_available_name`.
|
||||
|
||||
The ``content`` argument must be an instance of
|
||||
:class:`django.core.files.File` or of a subclass of
|
||||
:class:`~django.core.files.File`.
|
||||
|
||||
.. versionchanged:: 1.8
|
||||
|
||||
The ``max_length`` argument was added.
|
||||
|
||||
.. method:: size(name)
|
||||
|
||||
Returns the total size, in bytes, of the file referenced by ``name``.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue