summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authoryukihira1992 <hirayama@cancerscan.jp>2019-08-29 01:17:07 +0900
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-08-30 11:32:19 +0200
commit05457817647368be4b019314fcc655445a5b4c0c (patch)
tree91ca38fb0ba6a710929fa29fa772cb4cca5e334d /docs
parent400ec5125ec32e3b18d267bbb4f3aab09d741ce4 (diff)
Fixed #30736 -- Added Storage.get_alternative_name() to allow customization.
Diffstat (limited to 'docs')
-rw-r--r--docs/howto/custom-file-storage.txt10
-rw-r--r--docs/ref/files/storage.txt11
-rw-r--r--docs/releases/3.0.txt4
3 files changed, 19 insertions, 6 deletions
diff --git a/docs/howto/custom-file-storage.txt b/docs/howto/custom-file-storage.txt
index 0ad094da79..d9e18a6003 100644
--- a/docs/howto/custom-file-storage.txt
+++ b/docs/howto/custom-file-storage.txt
@@ -97,6 +97,12 @@ non-standard characters are converted to safe filenames.
The code provided on ``Storage`` retains only alpha-numeric characters, periods
and underscores from the original filename, removing everything else.
+.. method:: get_alternative_name(file_root, file_ext)
+
+Returns an alternative filename based on the ``file_root`` and ``file_ext``
+parameters. By default, an underscore plus a random 7 character alphanumeric
+string is appended to the filename before the extension.
+
.. method:: get_available_name(name, max_length=None)
Returns a filename that is available in the storage mechanism, possibly taking
@@ -108,5 +114,5 @@ 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 is 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.
+If a file with ``name`` already exists, ``get_alternative_name()`` is called to
+obtain an alternative name.
diff --git a/docs/ref/files/storage.txt b/docs/ref/files/storage.txt
index 2a82402fac..0724a0cda1 100644
--- a/docs/ref/files/storage.txt
+++ b/docs/ref/files/storage.txt
@@ -105,6 +105,12 @@ The ``Storage`` class
If :setting:`USE_TZ` is ``True``, returns an aware ``datetime``,
otherwise returns a naive ``datetime`` in the local timezone.
+ .. method:: get_alternative_name(file_root, file_ext)
+
+ Returns an alternative filename based on the ``file_root`` and
+ ``file_ext`` parameters, an underscore plus a random 7 character
+ alphanumeric string is appended to the filename before the extension.
+
.. method:: get_available_name(name, max_length=None)
Returns a filename based on the ``name`` parameter that's free and
@@ -116,9 +122,8 @@ The ``Storage`` class
: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.
+ If a file with ``name`` already exists, :meth:`get_alternative_name` is
+ called to obtain an alternative name.
.. method:: get_created_time(name)
diff --git a/docs/releases/3.0.txt b/docs/releases/3.0.txt
index 7a9adb3b39..910d3a2592 100644
--- a/docs/releases/3.0.txt
+++ b/docs/releases/3.0.txt
@@ -227,7 +227,9 @@ Email
File Storage
~~~~~~~~~~~~
-* ...
+* The new :meth:`.Storage.get_alternative_name` method allows customizing the
+ algorithm for generating filenames if a file with the uploaded name already
+ exists.
File Uploads
~~~~~~~~~~~~