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