Refactor local settings to dotenv-based gallery paths

This commit is contained in:
2026-03-22 22:52:07 -04:00
parent 16bd651cfb
commit 912446d9b7
5 changed files with 83 additions and 74 deletions

View File

@@ -53,7 +53,7 @@ The project has one Django app: **`viewer`**. All gallery functionality is conso
### Gallery Data Flow
**Filesystem as Data Source:**
- Images served from `GALLERY_ROOT` path (configured in `local_settings.py`)
- Images served from `GALLERY_ROOT` path (configured in `.env`)
- Thumbnails cached in `THUMBNAILS_ROOT` path
- No database models for images or directories
- Directory structure navigated using Python's `pathlib`
@@ -108,22 +108,17 @@ Uses Django's built-in `django.contrib.auth` system:
## Configuration
### Required Local Settings
### Required Environment Variables
Create `NibasaViewer/local_settings.py` (not in git):
Create `.env` (not in git):
```python
from pathlib import Path
GALLERY_ROOT = Path('/path/to/your/images')
THUMBNAILS_ROOT = Path('/path/to/thumbnail/cache')
# Production settings
DEBUG = False
ALLOWED_HOSTS = ['yourdomain.com']
SECRET_KEY = 'your-secret-key'
```env
GALLERY_ROOT=/path/to/your/images
THUMBNAILS_ROOT=/path/to/thumbnail/cache
```
`settings.py` loads `.env` with `python-dotenv` and parses both values as `pathlib.Path`. Each variable is optional and resolves to `None` when unset or empty.
### Pagination Constants
Defined in viewer/views.py:23-25:
@@ -143,7 +138,7 @@ Default production location: `/var/lib/NibasaViewer`
- **Django 4.2.3** - Web framework
- **Pillow 10.0.0** - Image processing (thumbnails)
- **filetype 1.2.0** - Legacy dependency (no longer actively used)
- **python-dotenv 1.1.1** - Loads local `.env` configuration
- **gunicorn 21.2.0** - WSGI server (production)
## Code Patterns