Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ Django will silently throw away `hello!` because you wrote :code:`contents` inst
of :code:`content`. :code:`django-fastdev` will turn this into an error which lists the
invalid and valid block names in alphabetical order.

You can customize the filter to understand also custom blocks in your `settings.py` file in this way (an example to integrate [Unfold](https://github.com/unfoldadmin/django-unfold)):

settings.py:

```
FASTDEV_INVALID_BLOCKS_CALLBACK = "your_app.settings.fastdev_blocks"

def fastdev_blocks(x, result):
if hasattr(x, 'varname') and x.varname is not None:
result.add(x.varname)
result.add(x.varname.replace('_', '-'))
return result
```

Better error messages for reverse
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
5 changes: 5 additions & 0 deletions django_fastdev/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import sys
import threading
import importlib
from functools import cache
from typing import Optional
import warnings
Expand Down Expand Up @@ -450,6 +451,10 @@ def get_extends_node_parent(extends_node, context):
def collect_valid_blocks(template, context):
result = set()
for x in template.nodelist:
if getattr(settings, 'FASTDEV_INVALID_BLOCKS_CALLBACK', False) is not False:
module, callback = settings.FASTDEV_INVALID_BLOCKS_CALLBACK.rsplit(".", 1)
module = importlib.import_module(module)
result = getattr(module, callback)(x, result)
if isinstance(x, ExtendsNode):
result |= collect_nested_blocks(x)
result |= collect_valid_blocks(get_extends_node_parent(x, context), context)
Expand Down
Loading