14.3.51. crate_anon.crateweb.consent.storage

crate_anon/crateweb/consent/storage.py


Copyright (C) 2015, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

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 <https://www.gnu.org/licenses/>.


File system storage class and instance for the consent-to-contact system.

class crate_anon.crateweb.consent.storage.CustomFileSystemStorage(*args, **kwargs)[source]

Subclasses django.core.files.storage.FileSystemStorage to improve URL processing, as below.

Notes:

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 imports storage). Problem. Specifically, a problem for making the URLs non-absolute for non-root hosting.

So we use get_script_prefix() instead?

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 django.core.files.storage.FileSystemStorage, so we can make the change at runtime.

url(name: str) str[source]

Returns the URL for a given filename.