Debian Codegraph @

docs/views/storage.txt

raw
1 ###################
2 StorageDownloadView
3 ###################
4
5 .. py:module:: django_downloadview.views.storage
6
7 :class:`StorageDownloadView` **serves files given a storage and a path**.
8
9 Use this view when you manage files in a storage (which is a good practice),
10 unrelated to a model.
11
12
13 **************
14 Simple example
15 **************
16
17 Given a storage:
18
19 .. literalinclude:: /../demo/demoproject/storage/views.py
20 :language: python
21 :lines: 1, 4-5
22
23 Setup a view to stream files in storage:
24
25 .. literalinclude:: /../demo/demoproject/storage/views.py
26 :language: python
27 :lines: 3-6, 8-9
28
29 The view accepts a ``path`` argument you can setup either in ``as_view`` or
30 via URLconfs:
31
32 .. literalinclude:: /../demo/demoproject/storage/urls.py
33 :language: python
34 :lines: 1-6, 7-11, 17
35
36
37 ************
38 Base options
39 ************
40
41 :class:`StorageDownloadView` inherits from
42 :class:`~django_downloadview.views.base.DownloadMixin`, which has various
43 options such as :attr:`~django_downloadview.views.base.DownloadMixin.basename`
44 or :attr:`~django_downloadview.views.base.DownloadMixin.attachment`.
45
46
47 **************************
48 Computing path dynamically
49 **************************
50
51 Override the :meth:`StorageDownloadView.get_path` method to adapt path
52 resolution to your needs.
53
54 As an example, here is the same view as above, but the path is converted to
55 uppercase:
56
57 .. literalinclude:: /../demo/demoproject/storage/views.py
58 :language: python
59 :lines: 3-5, 11-20
60
61
62 *************
63 API reference
64 *************
65
66 .. autoclass:: StorageDownloadView
67 :members:
68 :undoc-members:
69 :show-inheritance:
70 :member-order: bysource