-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom django storage for filemanager
- Loading branch information
wlorenzetti
committed
Jan 18, 2025
1 parent
fc9fffb
commit 4caa564
Showing
3 changed files
with
42 additions
and
2 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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# coding=utf-8 | ||
"""" | ||
File storage for filemanager module | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the Mozilla Public License 2.0. | ||
""" | ||
|
||
__author__ = '[email protected]' | ||
__date__ = '2025-01-18' | ||
__copyright__ = 'Copyright 2015 - 2025, Gis3w' | ||
__license__ = 'MPL 2.0' | ||
|
||
from django.core.files import File | ||
from qdjango.utils.storage import OverwriteStorage | ||
|
||
|
||
class FileManagerOverwriteStorage(OverwriteStorage): | ||
""" | ||
Custom storage for filemanager module | ||
""" | ||
|
||
def save(self, name, content, max_length=None): | ||
""" | ||
Override save method for bypass trasversal storage file checking | ||
""" | ||
# Get the proper name for the file, as it will actually be saved. | ||
if name is None: | ||
name = content.name | ||
|
||
if not hasattr(content, "chunks"): | ||
content = File(content, name) | ||
|
||
# Potentially find a different name depending on storage constraints. | ||
name = self.get_available_name(name, max_length=max_length) | ||
|
||
# The save operation should return the actual name of the file saved. | ||
name = self._save(name, content) | ||
|
||
return name |