-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
storage.py
38 lines (31 loc) · 1.32 KB
/
storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from django.core.files.storage import FileSystemStorage
from django.core.checks import Error
class SingleFileStorage(FileSystemStorage):
'''
This class allows for a reference to an individual file to be held while the staticfiles
module attempts to collect static files for deployment.
To use it, just pass an absolute path to the desired file as `location`
'''
def __init__(self, location=None, base_url=None, file_permissions_mode=None,
directory_permissions_mode=None):
self._file_path = ''
self._file_name = ''
if os.path.isfile(location):
# Separate the path from the filename
self._file_path, self._file_name = os.path.split(location)
else:
# This class won't work if `location` doesn't point to an actual file
raise IOError('Path should point to an existing file')
# Pass in the folder so this acts like a typical FileSystemStorage that needs a path
super().__init__(
self._file_path,
base_url,
file_permissions_mode,
directory_permissions_mode
)
def listdir(self, path):
'''
Return the file name as the sole file that needs to be collected from the specified path
'''
return [], [self._file_name]