Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
from django.utils.crypto import get_random_string | ||
from django.core.files.storage import FileSystemStorage | ||
|
||
|
||
class RandomFileSystemStorage(FileSystemStorage): | ||
|
||
def get_valid_name(self, name): | ||
file_root, file_ext = os.path.splitext(name) | ||
return "%s%s" % (get_random_string(32).lower(), file_ext) | ||
|
||
def get_available_name(self, name): | ||
dir_name, file_name = os.path.split(name) | ||
file_root, file_ext = os.path.splitext(file_name) | ||
while self.exists(name): | ||
name = os.path.join(dir_name, "%s%s" % (get_random_string(32).lower(), file_ext)) | ||
return name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters