You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/mastering-plone/dexterity.md
+63-43Lines changed: 63 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,23 +11,27 @@ myst:
11
11
12
12
# Content types I
13
13
14
+
```{card}
14
15
In this part you will:
15
16
16
17
- Learn about content types
17
18
- Customize existing types
18
19
- Create a content type through the web
19
-
20
+
```
20
21
21
22
(dexterity1-what-label)=
22
23
23
24
## What is a content type?
24
25
25
-
A content type instance is a kind of object that can store information and is editable by users.
26
+
A content type is a kind of object that can store information and is editable by users.
26
27
We have different content types to reflect the different kinds of information about which we need to collect and display information.
27
28
28
29
Pages, events, news items, files (binary) and images are all content types.
29
30
30
-
See "Features of Plone – {ref}`features-content-types-label`" for an overview.
31
+
```{seealso}
32
+
33
+
See {ref}`features-content-types-label` for an overview of Plone's built-in content types.
34
+
```
31
35
32
36
It is common in developing a web site that you'll need customized versions of common content types, or perhaps even entirely new types.
33
37
@@ -46,28 +50,29 @@ Every Plone content type has the following parts:
46
50
47
51
Schema
48
52
49
-
: A definition of fields that comprise a content type, properties of an object.
53
+
: A definition of fields that can be stored and edited for a content item with this type.
50
54
51
-
FTI
55
+
Factory Type Information (FTI)
52
56
53
-
: The "Factory Type Information" configures the content type in Plone, assigns it a name, additional features and available views to it.
57
+
: The "Factory Type Information" is a specification stored in the `portal_types` tool which configures the content type in Plone, assigns it a name, additional features and available views to it.
54
58
55
59
Views
56
60
57
61
: A view is a representation of the object and the content of its fields that may be rendered in response to a request.
58
62
You may have _one or more_ views for an object.
59
-
Some may be _visual_ — intended for display as web pages — others may be intended to satisfy AJAX requests and render content in formats like JSON or XML.
63
+
Some may be _visual_, intended for display as web pages.
64
+
Others may be intended to satisfy AJAX requests and render content in formats like JSON or XML.
60
65
61
66
## Schemas, Fields and Values
62
67
63
68
In a schema you can model fields that are used to store data.
64
-
Plone automatically creates forms bases on the schemata of a content type to add and edit content.
69
+
Plone automatically creates forms to add and edit content based on the schemas of a content type.
65
70
66
71
Values of these fields are attributes on content objects.
67
72
68
-
Here is a example that shows how to access and modify these values in python:
73
+
Here is a example that shows how to access and modify these values in Python:
Content types can have additional schemata. These are called behaviors.
91
+
Content types can have additional schemas.
92
+
These are called behaviors.
87
93
They are meant to be used across content types to add shared functionality.
88
94
89
95
One example is the ability of most content types to allow them to be excluded from the navigation.
90
96
The field is available on all types even though it is not defined in their schema.
91
97
Instead it is provided by the behavior `plone.excludefromnavigation` that most content types use.
92
98
93
-
Each behavior schema can define fields. The values of these fields are again attributes on content objects.
99
+
Each behavior schema can define fields.
100
+
The values of these fields are again attributes on content objects.
101
+
102
+
The behavior `plone.excludefromnavigation` adds a field `exclude_from_nav` to each object.
103
+
The value is either `True` or `False` because it is a boolean field.
94
104
95
-
The behavior `plone.excludefromnavigation` adds a attribute `exclude_from_nav` to each object. The value is either `True` or `False` because it is a boolean field.
96
105
97
106
(dexterity1-modify-label)=
98
107
99
-
## Modifying existing types
108
+
## Modify an existing content type schema
100
109
101
110
For now, we will not code anything.
102
111
We will only use the Plone web interface features.
103
112
104
-
- Go to the {guilabel}`Content Types` control panel at http://localhost:3000/controlpanel/dexterity-types.
113
+
- Go to the {guilabel}`Content Types` control panel at <http://localhost:3000/controlpanel/dexterity-types>.
114
+
115
+
```{note}
116
+
"Dexterity" is the internal name of Plone's content type system.
117
+
```
105
118
106
119
- Inspect some of the existing default types.
107
120
@@ -148,32 +161,40 @@ We will only use the Plone web interface features.
148
161
149
162
(dexterity1-create-ttw-label)=
150
163
151
-
## Creating content types TTW
164
+
## Create a content type through the web
165
+
166
+
In this step we will create a content type called `Talk` and try it out.
167
+
When it's ready, we will move the code from the web to the filesystem and into our own add-on.
168
+
Later we will extend that content type.
169
+
170
+
- Go to the {guilabel}`Content Types` control panel: <http://localhost:3000/controlpanel/dexterity-types>.
171
+
- Use the add button at upper left to add a new content type "Talk".
172
+
- Edit the schema of the Talk content type and add some fields to it:
152
173
153
-
In this step we will create a content type called `Talk` and try it out. When it's ready we will move the code from the web to the file system and into our own add-on. Later we will extend that content type.
174
+
-**Type of talk**, type "Choice". Add possible values: Talk, Training, Keynote.
175
+
-**Details**, type "Rich Text" with a maximum length of 2000.
176
+
-**Audience**, type "Multiple Choice". Add possible values: Beginner, Advanced, Professional.
154
177
155
-
-Add new content type "Talk" and some fields for it:
178
+
-Save the schema.
156
179
157
-
- {guilabel}`Add new field` "Type of talk", type "Choice". Add options: talk, keynote, training.
158
-
- {guilabel}`Add new field` "Details", type "Rich Text" with a maximal length of 2000.
159
-
- {guilabel}`Add new field` "Audience", type "Multiple Choice". Add options: beginner, advanced, pro.
160
-
- Check the behaviors that are enabled: _Dublin Core metadata_, _Name from title_. Do we need them all?
180
+
- Check the behaviors that are enabled: _Dublin Core metadata_, _Name from title_. Do we need them all?
161
181
162
182
- Test the content type.
163
183
164
-
- Return to the control panel <http://localhost:8080/Plone/@@dexterity-types>
184
+
- Return to the control panel:<http://localhost:3000/controlpanel/dexterity-types>.
165
185
166
-
- Extend the new type: add the following fields:
186
+
- Extend the new type by adding the following fields:
167
187
168
-
-"Speaker", type: "Text line"
169
-
-"Email", type: "Email"
170
-
-"Image", type: "Image", not required
171
-
-"Speaker Biography", type: "Rich Text"
188
+
-**Speaker**, type: "Text line"
189
+
-**Email**, type: "Email"
190
+
-**Image**, type: "Image", not required
191
+
-**Speaker Biography**, type: "Rich Text"
172
192
173
193
- Test again.
174
194
175
195
````{note}
176
-
The schema you created through the web is stored as XML in the database. Here is the complete XML schema created by our actions:
196
+
The schema you created through the web is stored as XML in the database.
197
+
Here is the complete XML schema created by our actions:
177
198
178
199
```{code-block} xml
179
200
:linenos:
@@ -215,7 +236,7 @@ The schema you created through the web is stored as XML in the database. Here is
@@ -234,7 +255,8 @@ The schema you created through the web is stored as XML in the database. Here is
234
255
```
235
256
````
236
257
237
-
It's awesome that we can do so much through the web and great for prototyping or small projects. But it's also a dead end if we want to reuse this content type in other sites.
258
+
It's awesome that we can do so much through the web and great for prototyping or small projects.
259
+
But it's also a dead end if we want to reuse this content type in other sites.
238
260
239
261
Also, for professional development, we want to be able to use version control for our work, and we'll want to be able to add the kind of business logic that will require programming.
240
262
@@ -247,26 +269,24 @@ Using Python to define the schema gives us much more control (e.g. for validatio
247
269
248
270
### Exercise 1
249
271
250
-
Modify Pages to allow uploading an image as decoration (like News Items do).
272
+
Modify the Page content type to allow uploading an image as decoration (like News Items do).
251
273
252
274
```{dropdown} Solution
253
275
:animate: fade-in-slide-down
254
276
:icon: question
255
277
256
-
- Go to the dexterity control panel (<http://localhost:8080/Plone/@@dexterity-types>)
257
-
- Click on *Page* (<http://127.0.0.1:8080/Plone/dexterity-types/Document>)
258
-
- Select the tab *Behaviors* (<http://127.0.0.1:8080/Plone/dexterity-types/Document/@@behaviors>)
278
+
- Go to the Content Types control panel (<http://localhost:3000/controlpanel/dexterity-types>)
279
+
- Click on *Page* (<http://localhost:3000/controlpanel/dexterity-types/Document>)
280
+
- Select the tab *Behaviors*
259
281
- Check the box next to {guilabel}`Lead Image` and save.
260
282
261
283
The images are displayed above the title.
262
284
```
263
285
264
286
## Further reading
265
-
- Documentation {doc}`plone6docs:backend/fields`
266
-
-[Example content type](https://github.com/collective/example.contenttype) A Plone content type with all available fields
0 commit comments