Skip to content

Commit

Permalink
add settings.DISTILL_SKIP_STATICFILES_DIRS which can be used to skip …
Browse files Browse the repository at this point in the history
…copying specific static files directories, resolves #91
  • Loading branch information
meeb committed May 24, 2024
1 parent fe22f84 commit 7256117
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,19 @@ desired for statically generated sites. The default behaviour is to skip static
files.


**DISTILL_SKIP_STATICFILES_DIRS**: list, defaults to `[]`

```python
DISTILL_SKIP_STATICFILES_DIRS = ['some_dir']
```

Set `DISTILL_SKIP_STATICFILES_DIRS` to a list of directory names you want `django-distill`
to ignore directories in your defined `static/` directory. You can use this to ignore
copying directories containing files from apps you're not using that get bundled into your
`static/` directory by `collect-static`. For example if you set `DISTILL_SKIP_STATICFILES_DIRS`
to `['some_dir']` the static files directory `static/some_dir` would be skipped.


# Writing single files

As of `django-distill` version `3.0.0` you can use the
Expand Down
13 changes: 10 additions & 3 deletions django_distill/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,17 @@ def run_collectstatic(stdout):

def filter_dirs(dirs):
DISTILL_SKIP_ADMIN_DIRS = bool(getattr(settings, 'DISTILL_SKIP_ADMIN_DIRS', True))
_ignore_dirs = []
if DISTILL_SKIP_ADMIN_DIRS:
_ignore_dirs = ('admin', 'grappelli')
else:
_ignore_dirs = ()
_ignore_dirs.append('admin')
_ignore_dirs.append('grappelli')
try:
DISTILL_SKIP_STATICFILES_DIRS = list(getattr(settings, 'DISTILL_SKIP_STATICFILES_DIRS', []))
except (ValueError, TypeError):
DISTILL_SKIP_STATICFILES_DIRS = []
for d in DISTILL_SKIP_STATICFILES_DIRS:
if isinstance(d, str) and os.sep not in d:
_ignore_dirs.append(d)
return [d for d in dirs if d not in _ignore_dirs]


Expand Down
1 change: 1 addition & 0 deletions tests/static/appdir/appdir-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
8 changes: 8 additions & 0 deletions tests/test_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ def test_copying_static_files(self):
self.assertTrue(os.path.exists(test_static_file_path))
test_admin_file_path = str(Path(tempdir) / 'static' / 'admin' / 'admin-test.txt')
self.assertTrue(os.path.exists(test_admin_file_path))
test_appdir_file_path = str(Path(tempdir) / 'static' / 'appdir' / 'appdir-test.txt')
self.assertTrue(os.path.exists(test_appdir_file_path))
# Test static app dirs are skipped with DISTILL_SKIP_STATICFILES_DIRS populated
settings.DISTILL_SKIP_STATICFILES_DIRS = ['appdir']
with TemporaryDirectory() as tempdir:
copy_static_and_media_files(tempdir, null)
test_appdir_file_path = str(Path(tempdir) / 'static' / 'appdir' / 'appdir-test.txt')
self.assertFalse(os.path.exists(test_appdir_file_path))

0 comments on commit 7256117

Please sign in to comment.