dj-file-browser-panel 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dj_file_browser_panel-0.1.0/LICENSE +21 -0
- dj_file_browser_panel-0.1.0/MANIFEST.in +3 -0
- dj_file_browser_panel-0.1.0/PKG-INFO +238 -0
- dj_file_browser_panel-0.1.0/README.md +195 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/__init__.py +3 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/admin.py +11 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/apps.py +7 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/browser.py +336 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/conf.py +26 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/models.py +13 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/panel.py +28 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/static/dj_file_browser_panel/css/styles.css +92 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/templates/admin/dj_file_browser_panel/base.html +19 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/templates/admin/dj_file_browser_panel/browse.html +148 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/templates/admin/dj_file_browser_panel/file_detail.html +94 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/templates/admin/dj_file_browser_panel/index.html +92 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/urls.py +11 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel/views.py +236 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel.egg-info/PKG-INFO +238 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel.egg-info/SOURCES.txt +27 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel.egg-info/dependency_links.txt +1 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel.egg-info/entry_points.txt +2 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel.egg-info/requires.txt +13 -0
- dj_file_browser_panel-0.1.0/dj_file_browser_panel.egg-info/top_level.txt +3 -0
- dj_file_browser_panel-0.1.0/pyproject.toml +124 -0
- dj_file_browser_panel-0.1.0/setup.cfg +4 -0
- dj_file_browser_panel-0.1.0/tests/test_browser.py +305 -0
- dj_file_browser_panel-0.1.0/tests/test_panel.py +21 -0
- dj_file_browser_panel-0.1.0/tests/test_views.py +295 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Taufan Budiman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dj-file-browser-panel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A read-only Django Admin file browser panel for Django Control Room
|
|
5
|
+
Author: Taufan Budiman
|
|
6
|
+
Maintainer: Taufan Budiman
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Repository, https://github.com/taufanbudiman/dj-file-browser-panel
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/taufanbudiman/dj-file-browser-panel/issues
|
|
10
|
+
Keywords: django,file-browser,admin,panel,filesystem,media
|
|
11
|
+
Classifier: Framework :: Django
|
|
12
|
+
Classifier: Framework :: Django :: 4.2
|
|
13
|
+
Classifier: Framework :: Django :: 5.0
|
|
14
|
+
Classifier: Framework :: Django :: 5.1
|
|
15
|
+
Classifier: Framework :: Django :: 5.2
|
|
16
|
+
Classifier: Framework :: Django :: 6.0
|
|
17
|
+
Classifier: Framework :: Django :: 6.1
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Operating System :: OS Independent
|
|
26
|
+
Classifier: Intended Audience :: Developers
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
28
|
+
Requires-Python: >=3.9
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: Django>=4.2
|
|
32
|
+
Requires-Dist: dj-control-room-base>=1.6.0
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-django>=4.5.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-xdist>=3.2.0; extra == "dev"
|
|
38
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
39
|
+
Provides-Extra: build
|
|
40
|
+
Requires-Dist: build>=1.0.0; extra == "build"
|
|
41
|
+
Requires-Dist: twine>=4.0.0; extra == "build"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
[](https://djangocontrolroom.com)
|
|
45
|
+
[](https://opensource.org/licenses/MIT)
|
|
46
|
+
[](https://pypi.org/project/dj-file-browser-panel/)
|
|
47
|
+
[](https://github.com/taufanbudiman/dj-file-browser-panel)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# Django File Browser Panel
|
|
51
|
+
|
|
52
|
+
A strictly **read-only** Django Admin panel for browsing the local filesystem —
|
|
53
|
+
`MEDIA_ROOT`, `STATIC_ROOT`, and any other configured roots — without shell
|
|
54
|
+
access. Part of the [Django Control Room](https://djangocontrolroom.com)
|
|
55
|
+
ecosystem.
|
|
56
|
+
|
|
57
|
+
Answer "did my upload land?" in two clicks: browse directories, check file
|
|
58
|
+
sizes and modified times, and optionally preview small text files — all from
|
|
59
|
+
the Django admin.
|
|
60
|
+
|
|
61
|
+
**Compatible with [dj-control-room](https://djangocontrolroom.com).** Register
|
|
62
|
+
this panel in the Control Room to manage it from a centralized dashboard.
|
|
63
|
+
|
|
64
|
+
- **Official site:** [djangocontrolroom.com](https://djangocontrolroom.com)
|
|
65
|
+
- **Panel registry:** [djangocontrolroom.com/panels](https://djangocontrolroom.com/panels)
|
|
66
|
+
|
|
67
|
+
## Features
|
|
68
|
+
|
|
69
|
+
- **Browsable roots**: `MEDIA_ROOT` and `STATIC_ROOT` by default, or any list
|
|
70
|
+
of directories via `DJ_FILE_BROWSER_PANEL_SETTINGS["ROOTS"]`.
|
|
71
|
+
- **Directory listings**: folders first, then files; name, human-readable
|
|
72
|
+
size, and modified time. Dotfiles hidden by default with a toggle.
|
|
73
|
+
- **Breadcrumbs + pagination**: navigate deep trees; large directories are
|
|
74
|
+
paginated, never loaded whole.
|
|
75
|
+
- **File details**: path, size, modified time, MIME type guess, and an
|
|
76
|
+
optional preview — text files inline (size-capped), images and PDF
|
|
77
|
+
embedded via the browser.
|
|
78
|
+
- **Hard read-only**: no upload, delete, rename, or chmod — there is no
|
|
79
|
+
mutation code path at all.
|
|
80
|
+
- **Path sandboxing**: every path is resolved and must stay inside a
|
|
81
|
+
configured root. `..` traversal, absolute paths outside roots, and symlink
|
|
82
|
+
escapes are rejected; escaping symlinks render as disabled entries.
|
|
83
|
+
- **No models, no migrations**: `managed=False` placeholder only.
|
|
84
|
+
- **Django admin styling**: dark mode and admin skins supported through
|
|
85
|
+
`dj-control-room-base`.
|
|
86
|
+
|
|
87
|
+
## Screenshots
|
|
88
|
+
|
|
89
|
+

|
|
90
|
+
|
|
91
|
+

|
|
92
|
+
|
|
93
|
+
## Known limitations
|
|
94
|
+
|
|
95
|
+
- **Office document previews are not supported yet** — DOCX, XLSX, PPTX,
|
|
96
|
+
ODT and similar formats show metadata only. Rendering them faithfully
|
|
97
|
+
needs either server-side conversion (e.g. LibreOffice → PDF) or
|
|
98
|
+
client-side libraries; both are still under consideration.
|
|
99
|
+
- Preview is strictly opt-in (`PREVIEW_ENABLED`) and capped by
|
|
100
|
+
`PREVIEW_MAX_BYTES`; SVG is deliberately excluded from image embeds.
|
|
101
|
+
- This panel is intentionally read-only — there is no download button and
|
|
102
|
+
no archive extraction; raw bytes are only served for allowlisted
|
|
103
|
+
preview types.
|
|
104
|
+
|
|
105
|
+
## Requirements
|
|
106
|
+
|
|
107
|
+
- Python 3.9+
|
|
108
|
+
- Django 4.2+
|
|
109
|
+
- `dj-control-room-base` 1.6+
|
|
110
|
+
|
|
111
|
+
## Installation
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pip install dj-file-browser-panel dj-control-room
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Add it to `INSTALLED_APPS`, include its URLs, and migrate (the base package
|
|
118
|
+
needs it; this panel has no migrations of its own):
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
INSTALLED_APPS = [
|
|
122
|
+
# ...
|
|
123
|
+
"dj_control_room_base",
|
|
124
|
+
"dj_file_browser_panel",
|
|
125
|
+
"dj_control_room",
|
|
126
|
+
# ...
|
|
127
|
+
]
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
urlpatterns = [
|
|
132
|
+
path("admin/dj-control-room-base/", include("dj_control_room_base.urls")),
|
|
133
|
+
path("admin/files/", include("dj_file_browser_panel.urls")),
|
|
134
|
+
path("admin/dj-control-room/", include("dj_control_room.urls")),
|
|
135
|
+
path("admin/", admin.site.urls),
|
|
136
|
+
]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
python manage.py migrate
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Then visit `/admin/` and look for the "DJ FILE BROWSER PANEL" section.
|
|
144
|
+
|
|
145
|
+
## Configuration
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
DJ_FILE_BROWSER_PANEL_SETTINGS = {
|
|
149
|
+
# None -> MEDIA_ROOT + STATIC_ROOT. Entries may be path strings or
|
|
150
|
+
# {"name": ..., "path": ..., "description": ...} dicts.
|
|
151
|
+
"ROOTS": [
|
|
152
|
+
{"name": "Media", "path": MEDIA_ROOT},
|
|
153
|
+
{"name": "Static", "path": STATIC_ROOT},
|
|
154
|
+
"/var/www/uploads",
|
|
155
|
+
],
|
|
156
|
+
"PAGE_SIZE": 100,
|
|
157
|
+
"SHOW_HIDDEN": False,
|
|
158
|
+
# File content preview (off by default). Raster images (except SVG)
|
|
159
|
+
# and PDF are embedded inline. PREVIEW_TYPES allowlists *text* preview
|
|
160
|
+
# MIME types (plus any text/* type), capped at PREVIEW_MAX_BYTES.
|
|
161
|
+
"PREVIEW_ENABLED": False,
|
|
162
|
+
"PREVIEW_MAX_BYTES": 262144,
|
|
163
|
+
"PREVIEW_TYPES": [
|
|
164
|
+
"application/json",
|
|
165
|
+
"text/csv",
|
|
166
|
+
"text/plain",
|
|
167
|
+
],
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
All keys are optional; unset keys fall back to the defaults above. Roots
|
|
172
|
+
that don't exist or aren't directories are skipped — if none are valid the
|
|
173
|
+
panel shows an empty state instead of an error.
|
|
174
|
+
|
|
175
|
+
Access control follows the `dj-control-room-base` panel permission model:
|
|
176
|
+
staff users only, with optional `ALLOWED_GROUPS`, `REQUIRE_SUPERUSER`, and
|
|
177
|
+
per-scope `SCOPE_PERMISSIONS` overrides — see the
|
|
178
|
+
[dj-control-room-base](https://github.com/django-control-room/dj-control-room)
|
|
179
|
+
documentation.
|
|
180
|
+
|
|
181
|
+
## Development
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
pip install -e ".[dev]"
|
|
185
|
+
pytest # runs the suite and writes coverage.xml + htmlcov/
|
|
186
|
+
ruff check . && ruff format .
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`example_project/` is a runnable Django project for manual testing:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
cd example_project
|
|
193
|
+
python manage.py migrate
|
|
194
|
+
python manage.py runserver
|
|
195
|
+
# visit http://127.0.0.1:8000/admin/files/
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Tests run with `pytest-django` against `tmp_path` fixtures — they never touch
|
|
199
|
+
the repo root or real media directories. Coverage is enforced at 85%
|
|
200
|
+
(`--cov-fail-under=85`) and runs on every push/PR via GitHub Actions.
|
|
201
|
+
|
|
202
|
+
## Contributing
|
|
203
|
+
|
|
204
|
+
Contributions are welcome — bug reports, docs fixes, and features alike.
|
|
205
|
+
|
|
206
|
+
1. **Fork and clone** the repository, then set up a dev environment:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
pip install -e ".[dev]"
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
2. **Run the checks locally before pushing:**
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
pytest # tests + coverage (must stay >= 85%)
|
|
216
|
+
ruff check . && ruff format .
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
3. **Open a pull request** against `main` with a short description of the
|
|
220
|
+
change and any relevant context (issue link, screenshots for UI changes).
|
|
221
|
+
|
|
222
|
+
House rules:
|
|
223
|
+
|
|
224
|
+
- **Read-only, always.** The panel must never gain upload, delete, rename,
|
|
225
|
+
chmod, or any other filesystem mutation. Every filesystem path must stay
|
|
226
|
+
inside a configured root (`Path.resolve()` + `is_relative_to`) — reject
|
|
227
|
+
`..` traversal, absolute paths outside roots, and symlink escapes.
|
|
228
|
+
- Follow the existing `dj-control-room-base` conventions: `PanelPlugin` for
|
|
229
|
+
registration, `panel_base.html` for templates, `dcr-*` design-system
|
|
230
|
+
classes for UI, `DJ_FILE_BROWSER_PANEL_SETTINGS` for configuration.
|
|
231
|
+
- Listings must paginate — never load an entire directory into memory.
|
|
232
|
+
- Keep tests on `tmp_path` fixtures — never touch the real filesystem in
|
|
233
|
+
tests.
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE)
|
|
238
|
+
file for details.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
[](https://djangocontrolroom.com)
|
|
2
|
+
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
[](https://pypi.org/project/dj-file-browser-panel/)
|
|
4
|
+
[](https://github.com/taufanbudiman/dj-file-browser-panel)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Django File Browser Panel
|
|
8
|
+
|
|
9
|
+
A strictly **read-only** Django Admin panel for browsing the local filesystem —
|
|
10
|
+
`MEDIA_ROOT`, `STATIC_ROOT`, and any other configured roots — without shell
|
|
11
|
+
access. Part of the [Django Control Room](https://djangocontrolroom.com)
|
|
12
|
+
ecosystem.
|
|
13
|
+
|
|
14
|
+
Answer "did my upload land?" in two clicks: browse directories, check file
|
|
15
|
+
sizes and modified times, and optionally preview small text files — all from
|
|
16
|
+
the Django admin.
|
|
17
|
+
|
|
18
|
+
**Compatible with [dj-control-room](https://djangocontrolroom.com).** Register
|
|
19
|
+
this panel in the Control Room to manage it from a centralized dashboard.
|
|
20
|
+
|
|
21
|
+
- **Official site:** [djangocontrolroom.com](https://djangocontrolroom.com)
|
|
22
|
+
- **Panel registry:** [djangocontrolroom.com/panels](https://djangocontrolroom.com/panels)
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **Browsable roots**: `MEDIA_ROOT` and `STATIC_ROOT` by default, or any list
|
|
27
|
+
of directories via `DJ_FILE_BROWSER_PANEL_SETTINGS["ROOTS"]`.
|
|
28
|
+
- **Directory listings**: folders first, then files; name, human-readable
|
|
29
|
+
size, and modified time. Dotfiles hidden by default with a toggle.
|
|
30
|
+
- **Breadcrumbs + pagination**: navigate deep trees; large directories are
|
|
31
|
+
paginated, never loaded whole.
|
|
32
|
+
- **File details**: path, size, modified time, MIME type guess, and an
|
|
33
|
+
optional preview — text files inline (size-capped), images and PDF
|
|
34
|
+
embedded via the browser.
|
|
35
|
+
- **Hard read-only**: no upload, delete, rename, or chmod — there is no
|
|
36
|
+
mutation code path at all.
|
|
37
|
+
- **Path sandboxing**: every path is resolved and must stay inside a
|
|
38
|
+
configured root. `..` traversal, absolute paths outside roots, and symlink
|
|
39
|
+
escapes are rejected; escaping symlinks render as disabled entries.
|
|
40
|
+
- **No models, no migrations**: `managed=False` placeholder only.
|
|
41
|
+
- **Django admin styling**: dark mode and admin skins supported through
|
|
42
|
+
`dj-control-room-base`.
|
|
43
|
+
|
|
44
|
+
## Screenshots
|
|
45
|
+
|
|
46
|
+

|
|
47
|
+
|
|
48
|
+

|
|
49
|
+
|
|
50
|
+
## Known limitations
|
|
51
|
+
|
|
52
|
+
- **Office document previews are not supported yet** — DOCX, XLSX, PPTX,
|
|
53
|
+
ODT and similar formats show metadata only. Rendering them faithfully
|
|
54
|
+
needs either server-side conversion (e.g. LibreOffice → PDF) or
|
|
55
|
+
client-side libraries; both are still under consideration.
|
|
56
|
+
- Preview is strictly opt-in (`PREVIEW_ENABLED`) and capped by
|
|
57
|
+
`PREVIEW_MAX_BYTES`; SVG is deliberately excluded from image embeds.
|
|
58
|
+
- This panel is intentionally read-only — there is no download button and
|
|
59
|
+
no archive extraction; raw bytes are only served for allowlisted
|
|
60
|
+
preview types.
|
|
61
|
+
|
|
62
|
+
## Requirements
|
|
63
|
+
|
|
64
|
+
- Python 3.9+
|
|
65
|
+
- Django 4.2+
|
|
66
|
+
- `dj-control-room-base` 1.6+
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install dj-file-browser-panel dj-control-room
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Add it to `INSTALLED_APPS`, include its URLs, and migrate (the base package
|
|
75
|
+
needs it; this panel has no migrations of its own):
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
INSTALLED_APPS = [
|
|
79
|
+
# ...
|
|
80
|
+
"dj_control_room_base",
|
|
81
|
+
"dj_file_browser_panel",
|
|
82
|
+
"dj_control_room",
|
|
83
|
+
# ...
|
|
84
|
+
]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
urlpatterns = [
|
|
89
|
+
path("admin/dj-control-room-base/", include("dj_control_room_base.urls")),
|
|
90
|
+
path("admin/files/", include("dj_file_browser_panel.urls")),
|
|
91
|
+
path("admin/dj-control-room/", include("dj_control_room.urls")),
|
|
92
|
+
path("admin/", admin.site.urls),
|
|
93
|
+
]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
python manage.py migrate
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Then visit `/admin/` and look for the "DJ FILE BROWSER PANEL" section.
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
DJ_FILE_BROWSER_PANEL_SETTINGS = {
|
|
106
|
+
# None -> MEDIA_ROOT + STATIC_ROOT. Entries may be path strings or
|
|
107
|
+
# {"name": ..., "path": ..., "description": ...} dicts.
|
|
108
|
+
"ROOTS": [
|
|
109
|
+
{"name": "Media", "path": MEDIA_ROOT},
|
|
110
|
+
{"name": "Static", "path": STATIC_ROOT},
|
|
111
|
+
"/var/www/uploads",
|
|
112
|
+
],
|
|
113
|
+
"PAGE_SIZE": 100,
|
|
114
|
+
"SHOW_HIDDEN": False,
|
|
115
|
+
# File content preview (off by default). Raster images (except SVG)
|
|
116
|
+
# and PDF are embedded inline. PREVIEW_TYPES allowlists *text* preview
|
|
117
|
+
# MIME types (plus any text/* type), capped at PREVIEW_MAX_BYTES.
|
|
118
|
+
"PREVIEW_ENABLED": False,
|
|
119
|
+
"PREVIEW_MAX_BYTES": 262144,
|
|
120
|
+
"PREVIEW_TYPES": [
|
|
121
|
+
"application/json",
|
|
122
|
+
"text/csv",
|
|
123
|
+
"text/plain",
|
|
124
|
+
],
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
All keys are optional; unset keys fall back to the defaults above. Roots
|
|
129
|
+
that don't exist or aren't directories are skipped — if none are valid the
|
|
130
|
+
panel shows an empty state instead of an error.
|
|
131
|
+
|
|
132
|
+
Access control follows the `dj-control-room-base` panel permission model:
|
|
133
|
+
staff users only, with optional `ALLOWED_GROUPS`, `REQUIRE_SUPERUSER`, and
|
|
134
|
+
per-scope `SCOPE_PERMISSIONS` overrides — see the
|
|
135
|
+
[dj-control-room-base](https://github.com/django-control-room/dj-control-room)
|
|
136
|
+
documentation.
|
|
137
|
+
|
|
138
|
+
## Development
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
pip install -e ".[dev]"
|
|
142
|
+
pytest # runs the suite and writes coverage.xml + htmlcov/
|
|
143
|
+
ruff check . && ruff format .
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`example_project/` is a runnable Django project for manual testing:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
cd example_project
|
|
150
|
+
python manage.py migrate
|
|
151
|
+
python manage.py runserver
|
|
152
|
+
# visit http://127.0.0.1:8000/admin/files/
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Tests run with `pytest-django` against `tmp_path` fixtures — they never touch
|
|
156
|
+
the repo root or real media directories. Coverage is enforced at 85%
|
|
157
|
+
(`--cov-fail-under=85`) and runs on every push/PR via GitHub Actions.
|
|
158
|
+
|
|
159
|
+
## Contributing
|
|
160
|
+
|
|
161
|
+
Contributions are welcome — bug reports, docs fixes, and features alike.
|
|
162
|
+
|
|
163
|
+
1. **Fork and clone** the repository, then set up a dev environment:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
pip install -e ".[dev]"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
2. **Run the checks locally before pushing:**
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
pytest # tests + coverage (must stay >= 85%)
|
|
173
|
+
ruff check . && ruff format .
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
3. **Open a pull request** against `main` with a short description of the
|
|
177
|
+
change and any relevant context (issue link, screenshots for UI changes).
|
|
178
|
+
|
|
179
|
+
House rules:
|
|
180
|
+
|
|
181
|
+
- **Read-only, always.** The panel must never gain upload, delete, rename,
|
|
182
|
+
chmod, or any other filesystem mutation. Every filesystem path must stay
|
|
183
|
+
inside a configured root (`Path.resolve()` + `is_relative_to`) — reject
|
|
184
|
+
`..` traversal, absolute paths outside roots, and symlink escapes.
|
|
185
|
+
- Follow the existing `dj-control-room-base` conventions: `PanelPlugin` for
|
|
186
|
+
registration, `panel_base.html` for templates, `dcr-*` design-system
|
|
187
|
+
classes for UI, `DJ_FILE_BROWSER_PANEL_SETTINGS` for configuration.
|
|
188
|
+
- Listings must paginate — never load an entire directory into memory.
|
|
189
|
+
- Keep tests on `tmp_path` fixtures — never touch the real filesystem in
|
|
190
|
+
tests.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE)
|
|
195
|
+
file for details.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from dj_control_room_base.core import BasePanelAdmin
|
|
2
|
+
from django.contrib import admin
|
|
3
|
+
|
|
4
|
+
from .conf import panel_config
|
|
5
|
+
from .models import FileBrowserPanelPlaceholder
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@admin.register(FileBrowserPanelPlaceholder)
|
|
9
|
+
class FileBrowserPanelPlaceholderAdmin(BasePanelAdmin):
|
|
10
|
+
redirect_url_name = "dj_file_browser_panel:index"
|
|
11
|
+
panel_config = panel_config
|