15.3.19. crate_anon.crateweb.consent.storage


Copyright (C) 2015-2018 Rudolf Cardinal (rudolf@pobox.com).

This file is part of CRATE.

CRATE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CRATE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CRATE. If not, see <http://www.gnu.org/licenses/>.


class crate_anon.crateweb.consent.storage.CustomFileSystemStorage(location=None, base_url=None, file_permissions_mode=None, directory_permissions_mode=None)[source]
url(name: str) → str[source]

Return an absolute URL where the file’s contents can be accessed directly by a Web browser.

crate_anon.crateweb.consent.storage.privatestorage = <crate_anon.crateweb.consent.storage.CustomFileSystemStorage object>

In order to use reverse(), config/urls.py can’t import views that import models that use this… so use string, not actual Python object, references for urls.py

However, in urls.py, we also need things like mgr_admin_site.urls, and consent/admin.py also imports models (which import storage). Problem. Specifically, a problem for making the URLs non-absolute for non-root hosting.

So we use get_script_prefix() instead? https://docs.djangoproject.com/en/1.8/ref/urlresolvers/ But that isn’t set at the time this is loaded, so that’s no good either. The only other way to handle this would be to override the view form, or offer the private storage via Apache (but the latter would prevent proper security, so that’s a no-no).

Therefore, let’s subclass FileSystemStorage, so we can make the change at runtime.