BlockReference support for Wagtail - enables forward and cyclic block references
Project description
wagtail-block-reference
BlockReference support for Wagtail — enables forward and cyclic block references.
Heads up: this package is quite hacky. It works by monkey-patching Wagtail internals (Python and JS), which is inherently fragile. It exists because the upstream PR (wagtail#14279) may take a while to land (if it ever does), and waiting wasn't an option for me :). The test suite deliberately targets the patched internals so that a future Wagtail upgrade that breaks the patches fails loudly rather than silently misbehaving.
Installation
pip install wagtail-block-reference
Add to INSTALLED_APPS:
INSTALLED_APPS = [
...
"wagtail_block_reference",
]
Usage
from wagtail import blocks
from wagtail_block_reference import BlockReference
class CommentBlock(blocks.StructBlock):
text = blocks.CharBlock()
replies = blocks.ListBlock(BlockReference(lambda: CommentBlock))
How it works
BlockReference is a lazy proxy that resolves its target block on first access. The target
can be a lambda (for forward/cyclic references), a dotted import path, or a block class.
The package ships two patches:
Python patch (patches.py, applied at import time): hooks into Wagtail's block
metaclass so that BlockReference attributes declared on a StructBlock are collected as
child blocks, and registers a telepath adapter so the block serialises as its resolved target.
JS patch (patch.js, injected via insert_global_admin_js): intercepts window.telepath
before Wagtail's own bundles load, then wraps StructBlock and StreamBlock prototypes with
a lazy childBlockDefsByName getter. Without this, the cyclic telepath graph causes a
Maximum call stack size exceeded crash when the editor tries to build the block name map
at construction time.
Supported versions
All Wagtail versions that are currently under active or security support: 7.0 LTS, 7.3, and 7.4 LTS. CI tests against each of these. Versions drop off the matrix as they go end-of-life.
Development
# Install dependencies
uv sync
# Lint & format
uv run ruff check .
uv run ruff format .
# Run all tests (unit + E2E) against a single Wagtail version
uv run playwright install chromium
uv run pytest tests/
# Run all tests against all supported Wagtail versions (installs Chromium automatically)
uv run tox
# Run all tests against all supported Wagtail versions (installs Chromium automatically)
# and see visually what the browser is doing
uv run tox -- --headed --slowmo=500
# Run against a specific version
uv run tox -e wagtail74
# Run against a specific version and see visually what the browser is doing
uv run tox -e wagtail74 -- --headed --slowmo=500
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wagtail_block_reference-0.1.0.tar.gz.
File metadata
- Download URL: wagtail_block_reference-0.1.0.tar.gz
- Upload date:
- Size: 61.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39fc848f12d74e6b21bf4769505b8de5f83d03883a0ba5f143463ad6c5b92fdc
|
|
| MD5 |
2869c5a287b12e143db27d677d0de8b9
|
|
| BLAKE2b-256 |
47274d3596016e3e972cc7519a80af4b2b555e70676a80a5fdcd353e80c5cf5f
|
Provenance
The following attestation bundles were made for wagtail_block_reference-0.1.0.tar.gz:
Publisher:
publish.yml on joeyjurjens/wagtail-block-reference
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wagtail_block_reference-0.1.0.tar.gz -
Subject digest:
39fc848f12d74e6b21bf4769505b8de5f83d03883a0ba5f143463ad6c5b92fdc - Sigstore transparency entry: 1868631687
- Sigstore integration time:
-
Permalink:
joeyjurjens/wagtail-block-reference@9ec5c937cbce75a4c687e31eb05f9e9d389dc273 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/joeyjurjens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9ec5c937cbce75a4c687e31eb05f9e9d389dc273 -
Trigger Event:
release
-
Statement type:
File details
Details for the file wagtail_block_reference-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wagtail_block_reference-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d8ff2a50114904e2a55a43cdf977142e9e0b9d3f90d39d11591d510e6b518f7
|
|
| MD5 |
f7c78f0c18300ed5e74b94d0a8efc698
|
|
| BLAKE2b-256 |
13670f1123ab361627bd3b56f8a5f6af690e7a92ab019e2bfb09a5551eb96695
|
Provenance
The following attestation bundles were made for wagtail_block_reference-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on joeyjurjens/wagtail-block-reference
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wagtail_block_reference-0.1.0-py3-none-any.whl -
Subject digest:
1d8ff2a50114904e2a55a43cdf977142e9e0b9d3f90d39d11591d510e6b518f7 - Sigstore transparency entry: 1868631775
- Sigstore integration time:
-
Permalink:
joeyjurjens/wagtail-block-reference@9ec5c937cbce75a4c687e31eb05f9e9d389dc273 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/joeyjurjens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9ec5c937cbce75a4c687e31eb05f9e9d389dc273 -
Trigger Event:
release
-
Statement type: