X-Git-Url: https://git.mdrn.pl/fnpdjango.git/blobdiff_plain/56089af0e8c5732caaa777ee0691d9ae7a557d31..9d71c7700e8f059d5494a6e04a67d8d746a101d1:/fnpdjango/storage.py?ds=inline diff --git a/fnpdjango/storage.py b/fnpdjango/storage.py new file mode 100644 index 0000000..72719b2 --- /dev/null +++ b/fnpdjango/storage.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from django.core.files.storage import FileSystemStorage + +class BofhStorageMixin(FileSystemStorage): + """Bastard Operator From Hell file storage for Django. + + When a user asks for a place available for saving a file and + the proposed filename is occupied, default Django file storage + looks for a free spot by appending a suffix. + + This storage just deletes the previous content and replies: + sure, just save it right where you want it. + + The user is now responsible for making sure they don't + accidentally overwrite anything they weren't supposed to, + and for sane caching settings. + + """ + def get_available_name(self, name): + if self.exists(name): + self.delete(name) + return name + +class BofhFileSystemStorage(BofhStorageMixin, FileSystemStorage): + """Bastard Operator From Hell storage for standard filesystem.""" + pass