Metadata-Version: 2.4
Name: collective.behavior.talcondition
Version: 2.0.0
Summary: This package contains a Dexterity behavior to add a TAL condition on a content type.
Author-email: IMIO <dev@imio.be>
License-Expression: GPL-2.0-only
Project-URL: PyPI, https://pypi.org/project/collective.behavior.talcondition
Project-URL: Source, https://github.com/collective/collective.behavior.talcondition
Project-URL: Issues, https://github.com/collective/collective.behavior.talcondition/issues
Project-URL: Changelog, https://github.com/collective/collective.behavior.talcondition/blob/master/CHANGES.md
Keywords: Python,Zope,Plone
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Plone
Classifier: Framework :: Plone :: 6.2
Classifier: Framework :: Plone :: Addon
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
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.GPL
License-File: LICENSE.md
Requires-Dist: Products.CMFCore
Requires-Dist: Products.GenericSetup
Requires-Dist: Zope
Requires-Dist: plone.api
Requires-Dist: plone.app.dexterity
Requires-Dist: plone.app.vocabularies
Requires-Dist: plone.autoform
Requires-Dist: plone.behavior
Requires-Dist: plone.dexterity
Requires-Dist: plone.supermodel
Requires-Dist: z3c.form
Provides-Extra: test
Requires-Dist: plone.app.contenttypes; extra == "test"
Requires-Dist: plone.app.testing; extra == "test"
Requires-Dist: plone.base; extra == "test"
Requires-Dist: plone.browserlayer; extra == "test"
Requires-Dist: plone.testing; extra == "test"
Requires-Dist: zest.releaser[recommended]; extra == "test"
Requires-Dist: zestreleaser.towncrier; extra == "test"
Requires-Dist: zope.testrunner; extra == "test"
Dynamic: license-file

# collective.behavior.talcondition

[![Tests](https://github.com/collective/collective.behavior.talcondition/actions/workflows/test-matrix.yml/badge.svg)](https://github.com/collective/collective.behavior.talcondition/actions/workflows/test-matrix.yml)
[![Meta](https://github.com/collective/collective.behavior.talcondition/actions/workflows/meta.yml/badge.svg)](https://github.com/collective/collective.behavior.talcondition/actions/workflows/meta.yml)
[![PyPI](https://img.shields.io/pypi/v/collective.behavior.talcondition.svg)](https://pypi.org/project/collective.behavior.talcondition)

## Overview

This package provides a Dexterity behavior.

It adds two fields on a content type:

- tal_condition : enter a [TAL expression](https://zope.readthedocs.io/en/latest/zopebook/AppendixC.html) that once evaluated will return 'True' if content should be available. By default, elements 'member', 'context' and 'portal' are available for the expression but the TAL expression context may be extended using the 'extra_expr_ctx' parameter.

- roles_bypassing_talcondition : choose the different roles for which the TAL condition will not be evaluated and always considered 'True'

It's then possible to use the 'evaluate' method to test the TAL condition.


## How to use it

Activate the behavior on your content type.


## Compatibility

Version 2.x supports Plone 6.2 on Python 3.10 to 3.14. It works only with Dexterity content types.

For older Plone versions, and for the Archetypes schema extender, use collective.behavior.talcondition 1.1.3.


## Installation

Add `collective.behavior.talcondition` to the dependencies of your project
(`pyproject.toml`, or `requirements.txt` with the Plone constraints), install
it, restart Plone and activate the add-on in *Site Setup* > *Add-ons*.


## Development

Requires [uv](https://docs.astral.sh/uv/). This installs Plone 6.2.3 in `.venv`
(use `PLONE_VERSION=6.2.2 make install` for another version) and the prek
git hook:

```shell
make install
make start          # Plone on http://localhost:8080 (admin / admin)
```

Create a Classic UI site from the browser, then activate collective.behavior.talcondition.

### Tests

Tests run through tox, as the CI does:

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

Without tox:

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

### Lint

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

### Translations

```shell
make i18n           # rebuild the collective.behavior.talcondition catalog
```

`.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 .`.


## Translations

This product has been translated into

- French.

- Spanish.

You can contribute for any message missing or other new languages, join us at [Plone Collective Team](https://www.transifex.com/plone/plone-collective/) into *Transifex.net* service with all world Plone translators community.


## Contribute

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


## License

The project is licensed under the GPLv2.

# Contributors

- Leonardo J. Caballero G., leonardocaballero@gmail.com

# Changelog

<!-- towncrier release notes start -->

## 2.0.0 (2026-11-20)

- Use native namespace packages (PEP 420). Remove the `pkg_resources` namespace declarations.
  This version needs Python 3.10 or later and Plone 6.2.
  [boulch]

- Breaking: drop the Archetypes schema extender (`extender.py` and
  `utils.applyExtender`) and the code for Plone 4 and 5, including the
  `PLONE_VERSION` constant. Use 1.1.3 for older Plone versions.
  [remdub]

- Take `get_installer` from `plone.base` and the test layer helpers from
  `plone.testing.zope` instead of the aliases Plone 6.2 deprecates. Log with
  `logger.warning` instead of the deprecated `logger.warn`.
  [remdub]

- Configure the package with plone.meta 2.12.0 (test matrix on Plone 6.2.3
  with Python 3.10 to 3.14), move its metadata to `pyproject.toml`, convert
  the documentation to Markdown and run the development environment on
  Plone 6.2.3 with uv instead of buildout. Drop the buildout configuration,
  the hand-written GitHub workflow and the empty robot test setup.
  [remdub]


## 1.1.3 (2026-06-19)

- In case an error occurs, output more information to the log.
  [gbastien]


## 1.1.2 (2026-05-20)

- Added parameter `return_bool=False` to `utils.evaluateExpressionFor` and
  `utils._evaluateExpression` to ensure that returned result will always be
  a bool (`True` or `False`).
  [gbastien]


## 1.1.1 (2025-08-28)

- Added `checkPermission` from `portal_membership` to base expression context.
  [gbastien]


## 1.1.0 (2025-05-05)

- Added Plone 6.1 version in buildout.
  [sgeulette]


## 1.0.0 (2024-09-18)

- Generated universal wheel version.
  [sgeulette]


## 1.0a2 (2024-09-16)

- Fix dict iteration for Python 3
  [laulaz]
- Updated Makefile
  [sgeulette]
- Used pyenv in gha
  [sgeulette]


## 1.0a1 (2023-06-21)

- Fix deprecated import AccessControl.class_init instead of App.class_init
  (Plone6 compatibility)
  [boulch]
- Set simpler setup with Makefile
  [sgeulette]


## 0.14 (2021-06-29)

- Fix pypi broken package
  [boulch]


## 0.13 (2021-06-29)

- Add uninstall profile
  [boulch]
- Add Plone6 compatibility
  [boulch]


## 0.12 (2021-04-20)

- Add Transifex.net service integration to manage the translation process.
  [macagua]
- Add Spanish translation
  [macagua]
- Do not consider the `archetypes.schemaextender` on Plone5.
  [gbastien]
- Adapted code (except, implementer) to be Python3 compatible.
  [gbastien]
- Added parameter `trusted=False` to `utils._evaluateExpression`, this will use
  a trusted expression handler instead the restricted python default.
  [gbastien]


## 0.11 (2019-05-16)

- Added parameter `raise_on_error` to `utils.evaluateExpressionFor` to raise an
  error when an exception occurs instead returning False.
  [gbastien]
- Added method `TALCondition.complete_extra_expr_ctx` to the behavior to
  formalize the way to get `extra_expr_ctx` to avoid the `evaluate` method
  to be overridden.
  [gbastien]


## 0.10 (2018-11-20)

- Do not break if parameter `expression` passed to
  `utils._evaluateExpression` is None.
  [gbastien]


## 0.9 (2018-10-12)

- Added new parameter `error_pattern=WRONG_TAL_CONDITION` to
  `utils.evaluateExpressionFor` and underlying `utils._evaluateExpression` to
  be able to log a custom message in case an error occurs during
  expression evaluation.
  [gbastien]


## 0.8 (2018-06-12)

- Mark elements using behavior with `ITALConditionable` interface so it behaves
  like element using the AT extender.
  [gbastien]


## 0.7 (2017-03-22)

- Use CheckBoxWidget for `ITALCondition.roles_bypassing_talcondition` to ease
  selection when displaying several elements.
  [gbastien]


## 0.6 (2016-01-12)

- Added parameter `empty_expr_is_true` to utils._evaluateExpression than may be True
  or False depending that we want an empty expression to be considered True or False.
  Previous behavior is kept in utils.evaluateExpressionFor where an empty expression
  is considered True.  This avoid managing an empty expression in the caller method
  [gbastien]


## 0.5 (2015-12-17)

- Added method utils._evaluateExpression that receives an expression
  to evaluate, it is called by utils.evaluateExpressionFor.  This way, this
  method may evaluate a TAL expression without getting it from the `tal_condition`
  attribute on the context, in case we want to evaluate arbitrary expression
  [gbastien]


## 0.4 (2015-09-16)

- Make the tal_condition field larger (from 30 to 80) for the
  AT extender as well as for the DX behavior
  [gbastien]
- Added possibility to extend TAL expression context by passing
  an `extra_expr_ctx` dict to utils.evaluateExpressionFor, also
  integrated to the `evaluate` method of the DX behavior
  [gbastien]


## 0.3 (2015-07-14)

- Corrected default value
  [sgeulette]
- Little optimization
  [sgeulette]


## 0.2 (2015-06-18)

- Added field `role_bypassing_talcondition` to define who can bypass the condition
  [anuyens]
- Added translations for new field
  [gbastien]


## 0.1 (2015-06-01)

- Initial release.
  [IMIO]
