0.5: Django 3.2 support, drop Django<1.11, Python<3.6, remove some compatibility...
[fnpdjango.git] / fnpdjango / storage.py
1 # This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django.core.files.storage import FileSystemStorage
5
6 class BofhStorageMixin(FileSystemStorage):
7     """Bastard Operator From Hell file storage for Django.
8
9     When a user asks for a place available for saving a file and
10     the proposed filename is occupied, default Django file storage
11     looks for a free spot by appending a suffix.
12
13     This storage just deletes the previous content and replies:
14     sure, just save it right where you want it.
15
16     The user is now responsible for making sure they don't
17     accidentally overwrite anything they weren't supposed to,
18     and for sane caching settings.
19
20     """
21     def get_available_name(self, name, max_length=None):
22         if self.exists(name):
23             self.delete(name)
24         return name
25
26 class BofhFileSystemStorage(BofhStorageMixin, FileSystemStorage):
27     """Bastard Operator From Hell storage for standard filesystem."""
28     pass