Metadata-Version: 2.5
Name: django-wagtail-blocks-exchange
Version: 0.1.0
Summary: Copy Wagtail StreamField blocks between pages from the admin page editor
Author-email: Aymane Nahji <aymanenahjidev@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: cms,django,streamfield,wagtail
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5
Classifier: Framework :: Wagtail
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Requires-Dist: django>=5.0
Requires-Dist: wagtail>=6.0
Provides-Extra: dev
Requires-Dist: pytest-django>=4.11; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# django-wagtail-blocks-exchange

Portable Django library: **Copy to pages** on each block in every Wagtail **StreamField** on the page editor. Select target page(s) and which **StreamField(s)** on each page receive the block (multi-select supported).

**Author:** Aymane Nahji

## Zero configuration

After adding the app to `INSTALLED_APPS`, you **do not** need `WAGTAIL_BLOCKS_EXCHANGE_BODY_FIELD`.

- Copy actions appear on blocks in **every** StreamField the editor renders (`{field_name}-root`).
- Eligible targets are pages you can edit whose model **includes that block type** on at least one StreamField.
- In the modal you pick **pages** and **stream fields**; the block is prepended at the top of each chosen field (draft revision).

Optional: `WAGTAIL_BLOCKS_EXCHANGE_STREAM_FIELDS` to allowlist field names server-side. Legacy `WAGTAIL_BLOCKS_EXCHANGE_BODY_FIELD` is treated as a one-item allowlist.

## Install

```bash
pip install django-wagtail-blocks-exchange
# or from a checkout:
pip install /path/to/django-wagtail-blocks-exchange
```

```python
INSTALLED_APPS = [
    # ...
    "wagtail",
    "wagtail_blocks_exchange",
]
```

Run `collectstatic` in production so admin CSS/JS are served.

## Admin API

Under the Wagtail admin prefix at `blocks-exchange/`:

| Endpoint | Method | Body |
|----------|--------|------|
| `eligible-pages/` | POST JSON | `source_page_id`, `block_type`, optional `source_stream_field_name` |
| `copy-block/` | POST form or JSON | `target_page_ids`, `target_stream_field_names`, block payload |

Responses include per-page `stream_fields` when listing eligible pages.

## Develop & test

```bash
pip install -e ".[dev]"
PYTHONPATH=. DJANGO_SETTINGS_MODULE=tests_project.settings python -m django test wagtail_blocks_exchange
```

Uses `tests_project/` (`BlocksExchangeTestPage`). See [wagtail_blocks_exchange/README.md](wagtail_blocks_exchange/README.md) for workflow, security, and i18n.

## Related

- **django-wagtail-ai-generation** — AI-assisted stream content on the same editor.
- **django-wagtail-icon-chooser** — Lucide fields copied as string values.

## License

MIT — see [LICENSE](LICENSE).