Metadata-Version: 2.5
Name: django-wagtail-blocks-exchange
Version: 0.1.1
Summary: Copy Wagtail StreamField blocks between pages from the admin page editor
Project-URL: Homepage, https://github.com/AymaneNahji/django-wagtail-blocks-exchange
Project-URL: Documentation, https://github.com/AymaneNahji/django-wagtail-blocks-exchange#readme
Project-URL: Repository, https://github.com/AymaneNahji/django-wagtail-blocks-exchange
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

**Copy StreamField blocks between pages** from the Wagtail editor — pick target pages and which StreamFields receive the block, without leaving the admin.

Portable Django package · MIT · by [Aymane Nahji](mailto:aymanenahjidev@gmail.com)

[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
[![Django 5+](https://img.shields.io/badge/django-5%2B-092e20.svg)](https://www.djangoproject.com/)
[![Wagtail 6+](https://img.shields.io/badge/wagtail-6%2B-007d7e.svg)](https://wagtail.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

---

## Why this package

Reuse a hero, testimonial, or promo block across the site without copy-paste in JSON or duplicate drafts by hand. **Copy to pages** appears on every block in **every** StreamField on the page editor — no single `body` field baked in.

- **Zero config** — add the app; buttons show up when StreamFields render.
- **Smart targets** — only pages you can edit that already support the block type on at least one StreamField.
- **Multi-select** — many pages and many fields in one action; block is **prepended** at the top of each chosen field (new draft revision).
- **Staff-only API** — CSRF-protected JSON and form endpoints under the admin prefix.

---

## Quick start

```bash
pip install django-wagtail-blocks-exchange
```

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

```bash
python manage.py collectstatic --noinput   # production
```

Open any page with stream content, expand a block, and click **Copy to pages**.

---

## Optional allowlist

Restrict which field names get server-side copy UI:

```python
WAGTAIL_BLOCKS_EXCHANGE_STREAM_FIELDS = ["body", "footer"]
```

Legacy `WAGTAIL_BLOCKS_EXCHANGE_BODY_FIELD` is treated as a one-item allowlist. When unset, all StreamFields on the model are eligible.

---

## Editor workflow

1. Edit a page and open a block in any StreamField.
2. Click **Copy to pages**.
3. Choose target page(s), then the **StreamField(s)** on each page that should receive the block.
4. Each target saves a **draft revision** — publish when you are ready.

Deep dive (security, i18n, copying rules): **[wagtail_blocks_exchange/README.md](wagtail_blocks_exchange/README.md)**.

---

## Admin API

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

| Endpoint | Method | Purpose |
|----------|--------|---------|
| `eligible-pages/` | `POST` JSON | List editable pages that can accept the block type |
| `copy-block/` | `POST` form or JSON | Copy block payload to selected pages and fields |

`eligible-pages/` accepts `source_page_id`, `block_type`, and optional `source_stream_field_name`. Responses include `stream_fields` per page.

---

## Requirements

| Dependency | Version |
|------------|---------|
| Python | 3.11+ |
| Django | 5.0+ |
| Wagtail | 6.0+ |

Source and target page models must share the same block type key in their stream definitions. The user needs edit permission on the source and every target.

---

## Develop & test

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

Uses `tests_project/` with `BlocksExchangeTestPage`.

---

## Wagtail toolkit

| Package | Role |
|---------|------|
| [django-wagtail-ai-generation](https://github.com/AymaneNahji/django-wagtail-ai-generation) | AI-assisted stream editing on the same page UI |
| [django-wagtail-icon-chooser](https://github.com/AymaneNahji/django-wagtail-icon-chooser) | Lucide values copy as plain strings with the block |

---

## License

MIT — see [LICENSE](LICENSE).