diff --git a/README.rst b/README.rst index c447554..41f90a6 100644 --- a/README.rst +++ b/README.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/django_fastdev/apps.py b/django_fastdev/apps.py index 6aa682d..2118b0f 100644 --- a/django_fastdev/apps.py +++ b/django_fastdev/apps.py @@ -4,6 +4,7 @@ import subprocess import sys import threading +import importlib from functools import cache from typing import Optional import warnings @@ -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)