Skip to content

Commit 1042600

Browse files
committed
revise dexterity_reference
1 parent b1a96c6 commit 1042600

1 file changed

Lines changed: 92 additions & 111 deletions

File tree

docs/mastering-plone/dexterity_reference.md

Lines changed: 92 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ myst:
1212
# Content types reference
1313

1414
This chapter documents common fields, widgets, directives that you can use with content types.
15-
Content types are often called dexterity types which refers to the rework of the content type concept by dexterity and abandoning the Archetypes system.
15+
16+
```{note}
17+
You might see references to "Dexterity" which is the internal name of Plone's content type system.
18+
```
1619

1720

1821
## Fields included in Plone
1922

20-
This is a schema with examples for all field-types that are shipped with Plone by default. They are arranged in fieldsets:
23+
This is a schema with examples for all field types that are shipped with Plone by default.
24+
They are arranged in fieldsets:
2125

22-
Text, boolean, email
26+
Text, Boolean, Email
2327

2428
: Textline, RichText, Boolean, Email, URI
2529

@@ -68,63 +72,8 @@ from zope.interface import implementer
6872
6973
7074
class IExample(model.Schema):
71-
"""Dexterity-Schema with common field-types."""
72-
73-
# fieldset(
74-
# "default",
75-
# label="Text, Boolean, Email",
76-
# fields=(
77-
# "title",
78-
# "description",
79-
# "richtext_field",
80-
# "bool_field",
81-
# "email_field",
82-
# "uri_field",
83-
# ),
84-
# )
85-
86-
fieldset(
87-
"numberfields",
88-
label="Number",
89-
fields=("int_field", "float_field"),
90-
)
91-
92-
fieldset(
93-
"datetimefields",
94-
label="Date and time",
95-
fields=(
96-
"datetime_field",
97-
"date_field",
98-
),
99-
)
100-
101-
fieldset(
102-
"choicefields",
103-
label="Choice",
104-
fields=(
105-
"choice_field",
106-
"list_field",
107-
"tuple_field",
108-
"set_field",
109-
),
110-
)
111-
112-
fieldset(
113-
"relationfields_volto",
114-
label="Relation fields – Volto",
115-
fields=(
116-
"relationchoice_field_named_staticcatalogvocabulary",
117-
"relationlist_field_named_staticcatalogvocabulary",
118-
),
119-
)
120-
121-
fieldset(
122-
"filefields",
123-
label="File",
124-
fields=("file_field", "image_field"),
125-
)
75+
"""Dexterity schema with common field types."""
12676
127-
# Default fields
12877
primary("title")
12978
title = schema.TextLine(
13079
title="Primary Field (Textline)",
@@ -138,20 +87,6 @@ class IExample(model.Schema):
13887
required=False,
13988
)
14089
141-
# text_field = schema.Text(
142-
# title="Text Field",
143-
# description="zope.schema.Text",
144-
# required=False,
145-
# missing_value="",
146-
# default="",
147-
# )
148-
149-
# textline_field = schema.TextLine(
150-
# title="Textline field",
151-
# description="A simple input field (zope.schema.TextLine)",
152-
# required=False,
153-
# )
154-
15590
richtext_field = RichText(
15691
title="RichText field",
15792
description="This uses a richtext editor. (plone.app.textfield.RichText)",
@@ -177,7 +112,59 @@ class IExample(model.Schema):
177112
required=False,
178113
)
179114
115+
# Number fields
116+
fieldset(
117+
"numberfields",
118+
label="Number",
119+
fields=("int_field", "float_field"),
120+
)
121+
122+
int_field = schema.Int(
123+
title="Integer Field (e.g. 12)",
124+
description="zope.schema.Int",
125+
required=False,
126+
)
127+
128+
float_field = schema.Float(
129+
title="Float field, e.g. 12.7",
130+
description="zope.schema.Float",
131+
required=False,
132+
)
133+
134+
# Date and Time fields
135+
fieldset(
136+
"datetimefields",
137+
label="Date and time",
138+
fields=(
139+
"datetime_field",
140+
"date_field",
141+
),
142+
)
143+
144+
datetime_field = schema.Datetime(
145+
title="Datetime field",
146+
description="Uses a date and time picker (zope.schema.Datetime)",
147+
required=False,
148+
)
149+
150+
date_field = schema.Date(
151+
title="Date field",
152+
description="Uses a date picker (zope.schema.Date)",
153+
required=False,
154+
)
155+
180156
# Choice fields
157+
fieldset(
158+
"choicefields",
159+
label="Choice",
160+
fields=(
161+
"choice_field",
162+
"list_field",
163+
"tuple_field",
164+
"set_field",
165+
),
166+
)
167+
181168
choice_field = schema.Choice(
182169
title="Choice field",
183170
description="zope.schema.Choice",
@@ -218,39 +205,21 @@ class IExample(model.Schema):
218205
default=set(),
219206
)
220207
221-
# File and image fields
222-
image_field = NamedBlobImage(
223-
title="Image field",
224-
description="A upload field for images (plone.namedfile.field.NamedBlobImage)",
225-
required=False,
226-
)
227-
228-
file_field = NamedBlobFile(
229-
title="File field",
230-
description="A upload field for files (plone.namedfile.field.NamedBlobFile)",
231-
required=False,
232-
)
233-
234-
# Date and Time fields
235-
datetime_field = schema.Datetime(
236-
title="Datetime field",
237-
description="Uses a date and time picker (zope.schema.Datetime)",
238-
required=False,
239-
)
240-
241-
date_field = schema.Date(
242-
title="Date field",
243-
description="Uses a date picker (zope.schema.Date)",
244-
required=False,
245-
)
246-
247208
"""Relation fields like Volto likes it
248209
249210
RelationChoice and RelationList with named StaticCatalogVocabulary
250211
251212
StaticCatalogVocabulary registered with same name as field/relation.
252213
This allowes Volto relations control panel to restrict potential targets.
253214
"""
215+
fieldset(
216+
"relationfields_volto",
217+
label="Relation fields – Volto",
218+
fields=(
219+
"relationchoice_field_named_staticcatalogvocabulary",
220+
"relationlist_field_named_staticcatalogvocabulary",
221+
),
222+
)
254223
255224
relationchoice_field_named_staticcatalogvocabulary = RelationChoice(
256225
title="RelationChoice – named StaticCatalogVocabulary – Select widget",
@@ -282,16 +251,22 @@ class IExample(model.Schema):
282251
},
283252
)
284253
285-
# Number fields
286-
int_field = schema.Int(
287-
title="Integer Field (e.g. 12)",
288-
description="zope.schema.Int",
254+
# File and image fields
255+
fieldset(
256+
"filefields",
257+
label="File",
258+
fields=("file_field", "image_field"),
259+
)
260+
261+
image_field = NamedBlobImage(
262+
title="Image field",
263+
description="A upload field for images (plone.namedfile.field.NamedBlobImage)",
289264
required=False,
290265
)
291266
292-
float_field = schema.Float(
293-
title="Float field, e.g. 12.7",
294-
description="zope.schema.Float",
267+
file_field = NamedBlobFile(
268+
title="File field",
269+
description="A upload field for files (plone.namedfile.field.NamedBlobFile)",
295270
required=False,
296271
)
297272
@@ -588,7 +563,7 @@ directives.widget(
588563
specialfield = schema.TextLine(title="Field with special frontend widget")
589564
```
590565

591-
Then register your frontend widget in your apps configuration.
566+
Then register your frontend widget in your Volto configuration.
592567

593568
```jsx
594569
import { MySpecialWidget } from './components';
@@ -616,7 +591,8 @@ The props will be injected into the corresponding widget component, configuring
616591

617592
## Directives
618593

619-
Directives can be placed anywhere in the class body (annotations are made directly on the class). By convention they are kept next to the fields they apply to.
594+
Directives can be placed anywhere in the class body (annotations are made directly on the class).
595+
By convention, they are kept next to the fields they apply to.
620596

621597
For example, here is a schema that omits a field:
622598

@@ -646,7 +622,8 @@ With the directive "mode" you can set fields to 'input', 'display' or 'hidden'.
646622
directives.mode(additionalInfo='hidden')
647623
```
648624

649-
You can apply directives to certain forms only. Here we drop a field from the add-form, it will still show up in the edit-form.
625+
You can apply directives to certain forms only.
626+
Here we drop a field from the add form, but it will still show up in the edit form.
650627

651628
```python
652629
from z3c.form.interfaces import IAddForm
@@ -664,7 +641,10 @@ class ITask(model.Schema):
664641

665642
The same works for custom forms.
666643

667-
With the directive {py:meth}`widget` you can not only change the widget used for a field. With {py:data}`pattern_options` you can pass additional parameters to the widget. Here, we configure the datetime widget powered by the JavaScript library [pickadate](https://amsul.ca/pickadate.js/) by adding options that are used by it. Plone passes the options to the library.
644+
With the directive {py:meth}`widget` you can not only change the widget used for a field.
645+
With {py:data}`pattern_options` you can pass additional parameters to the widget.
646+
Here, we configure the datetime widget powered by the JavaScript library [pickadate](https://amsul.ca/pickadate.js/) by adding options that are used by it.
647+
Plone passes the options to the library.
668648

669649
```python
670650
class IMeeting(model.Schema):
@@ -712,7 +692,8 @@ class IMeeting(model.Schema):
712692

713693
Validators and defaults can also be made aware of the context (i.e. to check against the values of other fields).
714694

715-
For context aware defaults you need to use a {py:class}`IContextAwareDefaultFactory`. It will be passed the container for which the add form is being displayed:
695+
For context-aware defaults you need to use a {py:class}`IContextAwareDefaultFactory`.
696+
It will be passed the container for which the add form is being displayed:
716697

717698
```python
718699
from zope.interface import provider

0 commit comments

Comments
 (0)