Metadata-Version: 2.4
Name: collective.complexrecordsproxy
Version: 2.0.0
Summary: Providing a proxy class for plone.registry allowing IObject fields to be stored as separate records using the plone.registry collection support.
Author-email: Sune Broendum Woeller <sune@woeller.dk>
License-Expression: GPL-2.0-or-later
Project-URL: PyPI, https://pypi.org/project/collective.complexrecordsproxy
Project-URL: Source, https://github.com/collective/collective.complexrecordsproxy
Project-URL: Issues, https://github.com/collective/collective.complexrecordsproxy/issues
Project-URL: Changelog, https://github.com/collective/collective.complexrecordsproxy/blob/master/CHANGES.md
Keywords: plone,configuration,registry
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Plone
Classifier: Framework :: Plone :: 6.1
Classifier: Framework :: Plone :: 6.2
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.GPL
License-File: LICENSE.md
Requires-Dist: plone.registry
Requires-Dist: zope.schema
Provides-Extra: test
Requires-Dist: zope.component; extra == "test"
Requires-Dist: zope.interface; extra == "test"
Requires-Dist: zope.testrunner; extra == "test"
Dynamic: license-file

# collective.complexrecordsproxy

[![Tests](https://github.com/collective/collective.complexrecordsproxy/actions/workflows/test-matrix.yml/badge.svg)](https://github.com/collective/collective.complexrecordsproxy/actions/workflows/test-matrix.yml)
[![Meta](https://github.com/collective/collective.complexrecordsproxy/actions/workflows/meta.yml/badge.svg)](https://github.com/collective/collective.complexrecordsproxy/actions/workflows/meta.yml)

Providing a proxy class for plone.registry allowing IObject fields to be stored as separate records using the plone.registry collection support.


## Motivation

With z3c.form it is possible to create forms allowing users to create and edit lists of complex records: a settings schema with an `Object` field, or a `Tuple` / `List` of `Object` fields.

plone.registry can't store these fields as records. Its documentation explains why:

> To avoid potentially
> breaking the registry with persistent references to symbols that may go away,
> we purposefully limit the number of fields supported.

But a complex record boils down to simple native types in the end. `ComplexRecordsProxy` stores each field of each complex record as a separate registry record, with the collection support of plone.registry, so the registry only holds native types.


## Usage

Register the simple fields of the schema as records, omitting the complex ones, and read the settings through `ComplexRecordsProxy`:

```python
from collective.complexrecordsproxy import ComplexRecordsProxy
from plone.registry.interfaces import IRegistry
from zope import schema
from zope.component import getUtility
from zope.interface import Interface


class IAddress(Interface):
    street = schema.TextLine(title="Street")
    city = schema.TextLine(title="City", required=False)


class ISettings(Interface):
    title = schema.TextLine(title="Title", required=False)
    address = schema.Object(title="Address", schema=IAddress, required=False)
    addresses = schema.Tuple(
        title="Addresses",
        value_type=schema.Object(schema=IAddress),
        required=False,
        missing_value=(),
    )


registry = getUtility(IRegistry)
registry.registerInterface(ISettings, omit=("address", "addresses"))
settings = registry.forInterface(
    ISettings, omit=("address", "addresses"), factory=ComplexRecordsProxy
)
settings.addresses = (address1, address2)  # objects providing IAddress
[address.street for address in settings.addresses]
```

- An `Object` field `address` is stored under `<IAddress identifier>/address.<field name>`.
- A `Tuple` or `List` of `Object` field `addresses` is stored under `<IAddress identifier>.addresses/r0.<field name>`, `r1`, etc. Setting the field replaces all its items.
- Reading a complex field returns `ComplexRecordsProxy` objects, not the objects that were set. A `Tuple` or `List` field returns them in a mapping values view: iterate over it, it can't be indexed. A complex field without records returns the `missing_value` of the field.

collective.autopublishing uses it for its control panel settings.


## Compatibility

Version 2.x supports Plone 6.1 and 6.2, on Python 3.10 to 3.13.

For Plone 4.3 to 6.0 and Python 2.7, use collective.complexrecordsproxy 1.1.


## Installation

Add `collective.complexrecordsproxy` to the dependencies of your package. It is a library, not an add-on: there is no ZCML to load and nothing to activate.


## Development

Requires [uv](https://docs.astral.sh/uv/). This installs the package with Plone 6.2.3 in `.venv` (use `PLONE_VERSION=6.1.6 make install` for another version) and the prek git hook. Plone is not a dependency of the package: the Makefile adds Products.CMFPlone and plone.app.contenttypes for the development instance.

```shell
make install
make start          # Plone on http://localhost:8080 (admin / admin)
make console        # Python console with the Zope application as `app`
```

### Tests

Tests run through tox, as the CI does:

```shell
make test                                   # Plone 6.2.3
uvx --with tox-uv tox -e py312-plone61      # one Plone / Python combination
make test-all                               # lint, every combination, dependencies
```

Without tox:

```shell
.venv/bin/zope-testrunner --test-path=src -s collective.complexrecordsproxy
```

### Lint

```shell
make check          # format then lint (pyupgrade, isort, black, flake8...)
```

`.editorconfig`, `.flake8`, `.gitignore`, `.pre-commit-config.yaml`, `tox.ini`,
`.github/` and the tool sections of `pyproject.toml` are generated by
[plone.meta](https://github.com/plone/meta): change `.meta.toml`, then run
`uvx --from plone.meta config-package --no-commit --branch current .`.

### Release

```shell
make release        # zest.releaser fullrelease, run through uvx
```


## Contribute

- Issue Tracker: https://github.com/collective/collective.complexrecordsproxy/issues
- Source Code: https://github.com/collective/collective.complexrecordsproxy


## License

The project is licensed under the GPLv2 or later.

# Contributors

- Sune Broendum Woeller
- Tom Gross
- Christophe Boulanger
- Laurent Lasudry

# Changelog

<!-- towncrier release notes start -->

## 2.0.0 (2026-11-23)


- Breaking: replace the `pkg_resources` namespace of `collective` with a
  PEP 420 native namespace, and move the package to a `src/` layout.
  Support Plone 6.1 and 6.2 only, on Python 3.10 to 3.13. Use 1.1 for
  Plone 4.3 to 6.0 and Python 2.7.
  [remdub]

- Add unit tests for `ComplexRecordsProxy` (the package had none), and
  list it in `__all__`.
  [remdub]

- Configure the package with plone.meta 2.12.0 (test matrix on Plone 6.2.3
  and 6.1), move its metadata to `pyproject.toml`, convert the documentation
  to Markdown and add a development environment on Plone 6.2.3 with uv.
  [remdub]


## 1.1 (2022-01-13)

- Add Python 3 & Plone 5.2 / 6.0 compatibility
  [boulch, laulaz]


## 1.0 (2016-01-29)

- Initial release
  [sunew, tomgross]
