core.elements
Elements are mini chameleon macros, usually used to render a single element. Sometimes it is useful to not just apply a macro, but to have an actual object representing that code snippet. The prime example being links.
Elements are rendered in chameleon templates by calling them with the layout object:
<tal:b replace="structure element(layout)" />
Note that no matter how quick the elements rendering is, using chameleon templates directly is faster.
This module should eventually replace the elements.py module.
Classes
Provides a way to define elements trough multiple variables. These |
|
Hidden links point to views which are not available to the public |
|
A generic link. |
|
A generic button. |
|
A button that goes back in the history. |
|
Represents a list of links. |
|
Base class for all traits. |
|
Links with a confirm link will only be triggered after a question has |
|
A block trait is a confirm variation with no way to say yes. |
|
Turns the link into an intercooler request. As a result, the link |
Module Contents
- class core.elements.Element(text: str | None = None, attrs: dict[str, Any] | None = None, traits: Iterable[Trait] | Trait = (), **props: Any)[source]
Provides a way to define elements trough multiple variables. These elements may then be rendered by the elements.pt templates.
Elements are simple, they render whatever text and attributes the get. They also carry a dictionary with properties on them, so any kind of value may be attached to an element. For example this works:
user = object() element = Element(model=user) assert element.user == user
Since we might use a complex set of attributes which need to be set in a certain way we use a traits system to avoid having to rely too heavily on class inheritance.
Basically traits are callables called with attributes which they may manipulate. For example, a trait might turn a simple argument into a set of attributes:
Element(traits=[Editor(buttons=['new', 'edit', 'delete'])])
See the link traits further down to see examples.
- normalize_attrs(attrs: dict[str, Any] | None) dict[str, Any] [source]
Before we do anything with attributes we make sure we can easily add/remove classes from them, so we use a set.
- __call__(layout: core.layout.ChameleonLayout, extra_classes: Iterable[str] | None = None) markupsafe.Markup [source]
- class core.elements.AccessMixin[source]
Hidden links point to views which are not available to the public (usually through a publication mechanism).
We mark those links with an icon. This mixin automatically does that for links which bear a model property.
- class core.elements.Link(text: str | None, url: str = '#', attrs: dict[str, Any] | None = None, traits: Iterable[Trait] | Trait = (), **props: Any)[source]
Bases:
Element
,AccessMixin
A generic link.
- class core.elements.Button(text: str | None, url: str = '#', attrs: dict[str, Any] | None = None, traits: Iterable[Trait] | Trait = (), **props: Any)[source]
Bases:
Link
A generic button.
- class core.elements.BackLink(text: str = '', **props: Any)[source]
Bases:
Link
A button that goes back in the history.
- class core.elements.LinkGroup(title: str, links: Sequence[Link], model: Any | None = None, right_side: bool = True, classes: Collection[str] | None = None, attributes: dict[str, Any] | None = None)[source]
Bases:
AccessMixin
Represents a list of links.
- class core.elements.Confirm(confirm: str, extra: str | None = None, yes: str | None = 'Yes', no: str = 'Cancel', **ignored: Any)[source]
Bases:
Trait
Links with a confirm link will only be triggered after a question has been answered with a yes:
link = Link(_("Continue"), '/last-step', traits=( Confirm( _("Do you really want to continue?"), _("This cannot be undone"), _("Yes"), _("No") ), ))
- class core.elements.Block(message: str, extra: str | None = None, no: str = 'Cancel', **ignored: Any)[source]
Bases:
Confirm
A block trait is a confirm variation with no way to say yes.