Skip to content

Commit b1a96c6

Browse files
committed
revise dexterity_2_talk
1 parent 298002a commit b1a96c6

3 files changed

Lines changed: 142 additions & 113 deletions

File tree

docs/mastering-plone/dexterity_2_talk.md

Lines changed: 127 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ myst:
1212
# Content types II: Talk
1313

1414
```{card}
15-
In this part you will:
16-
17-
Create a content type 'talk' to store all the data required for a talk.
15+
In this part you will create a content type "Talk" to store all the data required for a talk.
1816
1917
Tools and techniques covered:
2018
@@ -26,7 +24,7 @@ Tools and techniques covered:
2624

2725
````{card} Backend chapter
2826
29-
Checkout `ploneconf.site` at tag "initial":
27+
Check out `mastering-plone-project` at tag `initial`:
3028
3129
```shell
3230
git checkout initial
@@ -43,78 +41,109 @@ More info in {doc}`code`
4341

4442
## The type registration
4543

46-
Add a new file {file}`types.xml` to your add-on package in {file}`profiles/default/`.
47-
48-
The following lines will tell Plone that there is a new content type defined.
44+
Edit the file {file}`backend/src/ploneconf/site/profiles/default/types.xml` and add the `talk` object.
4945

5046
```xml
51-
<?xml version="1.0"?>
52-
<object name="portal_types" meta_type="Plone Types Tool">
53-
<object name="talk" meta_type="Dexterity FTI"/>
47+
<?xml version="1.0" encoding="utf-8"?>
48+
<object meta_type="Plone Types Tool"
49+
name="portal_types"
50+
>
51+
<object meta_type="Dexterity FTI"
52+
name="talk"
53+
/>
5454
</object>
5555
```
5656

57-
Plone will now expect a file {file}`profiles/default/types/talk.xml` and will register that as a new content type.
57+
Plone will now expect a file {file}`backend/src/ploneconf/site/profiles/default/types/talk.xml` and will register that as a new content type.
5858

5959
## The FTI
6060

61-
Add the file `profiles/default/types/talk.xml`.
62-
Note there is a file _types_ and a folder _types_.
61+
Add the file `backend/src/ploneconf/site/profiles/default/types/talk.xml`.
62+
Note there is a file `types.xml` and a folder `types`.
6363

64-
This is the **Factory Type Information** that holds the configuration for the content type **talk**.
64+
This is the **Factory Type Information** that holds the configuration for the content type **Talk**.
6565

6666
```{code-block} xml
6767
:linenos:
6868
69-
<?xml version="1.0"?>
70-
<object name="talk" meta_type="Dexterity FTI" i18n:domain="plone"
71-
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
72-
<property name="title" i18n:translate="">Talk</property>
73-
<property name="description" i18n:translate=""></property>
74-
<property name="icon_expr">string:${portal_url}/document_icon.png</property>
75-
<property name="factory">talk</property>
76-
<property name="add_view_expr">string:${folder_url}/++add++talk</property>
77-
<property name="link_target"></property>
78-
<property name="immediate_view">view</property>
79-
<property name="global_allow">True</property>
80-
<property name="filter_content_types">True</property>
81-
<property name="allowed_content_types"/>
82-
<property name="allow_discussion">False</property>
83-
<property name="default_view">view</property>
84-
<property name="view_methods">
85-
<element value="view"/>
86-
</property>
87-
<property name="default_view_fallback">False</property>
88-
<property name="add_permission">cmf.AddPortalContent</property>
89-
<property name="klass">ploneconf.site.content.talk.Talk</property>
90-
<property name="schema">ploneconf.site.content.talk.ITalk</property>
91-
<property name="behaviors">
92-
<element value="plone.dublincore"/>
93-
<element value="plone.namefromtitle"/>
94-
<element value="plone.versioning" />
95-
</property>
96-
<property name="model_source"></property>
97-
<property name="model_file"></property>
98-
<property name="schema_policy">dexterity</property>
99-
<alias from="(Default)" to="(dynamic view)"/>
100-
<alias from="edit" to="@@edit"/>
101-
<alias from="sharing" to="@@sharing"/>
102-
<alias from="view" to="(selected layout)"/>
103-
<action title="View" action_id="view" category="object" condition_expr=""
104-
description="" icon_expr="" link_target="" url_expr="string:${object_url}"
105-
visible="True">
106-
<permission value="View"/>
107-
</action>
108-
<action title="Edit" action_id="edit" category="object" condition_expr=""
109-
description="" icon_expr="" link_target=""
110-
url_expr="string:${object_url}/edit" visible="True">
111-
<permission value="Modify portal content"/>
112-
</action>
69+
<?xml version="1.0" encoding="utf-8"?>
70+
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n"
71+
meta_type="Dexterity FTI"
72+
name="talk"
73+
i18n:domain="plone"
74+
>
75+
<property name="title"
76+
i18n:translate=""
77+
>Talk</property>
78+
<property name="description"
79+
i18n:translate=""
80+
/>
81+
<property name="icon_expr">string:${portal_url}/document_icon.png</property>
82+
<property name="factory">talk</property>
83+
<property name="add_view_expr">string:${folder_url}/++add++talk</property>
84+
<property name="link_target" />
85+
<property name="immediate_view">view</property>
86+
<property name="global_allow">True</property>
87+
<property name="filter_content_types">True</property>
88+
<property name="allowed_content_types" />
89+
<property name="allow_discussion">False</property>
90+
<property name="default_view">view</property>
91+
<property name="view_methods">
92+
<element value="view" />
93+
</property>
94+
<property name="default_view_fallback">False</property>
95+
<property name="add_permission">cmf.AddPortalContent</property>
96+
<property name="klass">ploneconf.site.content.talk.Talk</property>
97+
<property name="schema">ploneconf.site.content.talk.ITalk</property>
98+
<property name="behaviors">
99+
<element value="plone.dublincore" />
100+
<element value="plone.namefromtitle" />
101+
<element value="plone.versioning" />
102+
</property>
103+
<property name="model_source" />
104+
<property name="model_file" />
105+
<property name="schema_policy">dexterity</property>
106+
<alias from="(Default)"
107+
to="(dynamic view)"
108+
/>
109+
<alias from="edit"
110+
to="@@edit"
111+
/>
112+
<alias from="sharing"
113+
to="@@sharing"
114+
/>
115+
<alias from="view"
116+
to="(selected layout)"
117+
/>
118+
<action action_id="view"
119+
category="object"
120+
condition_expr=""
121+
description=""
122+
icon_expr=""
123+
link_target=""
124+
title="View"
125+
url_expr="string:${object_url}"
126+
visible="True"
127+
>
128+
<permission value="View" />
129+
</action>
130+
<action action_id="edit"
131+
category="object"
132+
condition_expr=""
133+
description=""
134+
icon_expr=""
135+
link_target=""
136+
title="Edit"
137+
url_expr="string:${object_url}/edit"
138+
visible="True"
139+
>
140+
<permission value="Modify portal content" />
141+
</action>
113142
</object>
114143
```
115144

116145
Now our package has a new configuration for Generic Setup.
117-
Generic Setup loads a lot of different types of configuration for the site from folder {file}`profiles/`.
146+
Generic Setup loads a lot of different types of configuration for the site from the folder {file}`profiles/`.
118147
This configuration is applied to your site upon installing the package.
119148
This also means that you will need to re-install the package once we are finished with the talk.
120149

@@ -128,11 +157,10 @@ It is also the place where you would add widget options per field to control the
128157

129158
In the FTI we referenced the Python path `ploneconf.site.content.talk.ITalk`.
130159

131-
The module {py:mod}`content` does not exist.
132-
Create a folder {file}`content` and add an empty {file}`__init__.py` in it.
133-
From the training root that is {file}`backend/sources/ploneconf.site/src/ploneconf/site/content/__init__.py`.
160+
The package {py:mod}`ploneconf.site.content` already exists.
161+
Find it in at this path: {file}`backend/src/ploneconf/site/content`.
134162

135-
In this new folder add a file {file}`talk.py` with the following content:
163+
In this folder add a new file {file}`talk.py` with the following content:
136164

137165
```{code-block} python
138166
:linenos:
@@ -147,17 +175,15 @@ from plone.supermodel import model
147175
from z3c.form.browser.checkbox import CheckBoxFieldWidget
148176
from z3c.form.browser.radio import RadioFieldWidget
149177
from zope.interface import implementer
150-
from zope.schema.vocabulary import SimpleTerm
151-
from zope.schema.vocabulary import SimpleVocabulary
152178
153179
154180
class ITalk(model.Schema):
155-
"""Dexterity-Schema for Talks"""
181+
"""Dexterity schema for Talks"""
156182
157183
directives.widget(type_of_talk=RadioFieldWidget)
158184
type_of_talk = schema.Choice(
159185
title="Type of talk",
160-
values=["talk", "training", "keynote"],
186+
values=["Talk", "Training", "Keynote"],
161187
required=True,
162188
)
163189
@@ -172,7 +198,7 @@ class ITalk(model.Schema):
172198
audience = schema.Set(
173199
title="Audience",
174200
value_type=schema.Choice(
175-
values=['beginner', 'advanced', 'professional'],
201+
values=["Beginner", "Advanced", "Professional"],
176202
),
177203
required=False,
178204
)
@@ -190,7 +216,7 @@ class ITalk(model.Schema):
190216
191217
email = Email(
192218
title="Email",
193-
description="Email adress of the speaker",
219+
description="Email address of the speaker",
194220
required=False,
195221
)
196222
@@ -199,11 +225,6 @@ class ITalk(model.Schema):
199225
required=False,
200226
)
201227
202-
twitter = schema.TextLine(
203-
title="Twitter name",
204-
required=False,
205-
)
206-
207228
github = schema.TextLine(
208229
title="Github username",
209230
required=False,
@@ -231,27 +252,33 @@ The first class {py:class}`ITalk` is the schema for talks and defines quite a lo
231252

232253
- The fields in the schema are mostly from {py:mod}`zope.schema`.
233254
- The most basic field is `schema.TextLine` which can store text.
234-
- In the next chapter you will find a reference of all field-types available in Plone.
235-
- The widget directives can be ignored by now, as we are implementing for a frontend app.
236-
The widget directives like above do control the rendering of the fields in Plone Classic.
237-
In the rare case that you need to tweak the rendering of a field in frontend, this can be done like described in {doc}`plone6docs:volto/development/widget`
255+
- In the next chapter you will find a reference of all field types available in Plone.
256+
- The widget directives can be ignored by now, as we are implementing for a Volto frontend.
257+
The widget directives do control the rendering of the fields in Plone Blicca.
258+
In the rare case that you need to tweak the rendering of a field in the frontend, this can be done as described in {doc}`plone6docs:volto/development/widget`.
238259

239260

240261
## The instance class
241262

242263
The second class {py:class}`Talk` in {file}`talk.py` will be the class of instances for each talk.
243264
It inherits from {py:class}`Container` which is one of the default classes of dexterity.
244265
{py:class}`Container` is used for items that can contain other items.
245-
It does nothing so far but it can be useful later when we want to add methods or properties to it that can be used directly from a talk instance.
266+
It does nothing special so far, but it can be useful later when we want to add methods or properties to it that can be used directly from a talk instance.
267+
246268

247269
## Try the new type
248270

249-
Now all pieces should be in place and you can enable the new type `Talk`.
271+
Now all pieces should be in place and you can enable the new type `talk`.
250272

251-
- Restart Plone (to load the new Python code and the changed ZCML)
252-
- You do not need to restart the Volto frontend since we did not do any changes there.
253-
- Re-install the package ploneconf.site (deactivate and activate) to load the type registration and type configuration:
254-
Follow the link "SITE SETUP" in the bottom of the toolbar and switch to "Add-Ons".
273+
1. Restart Plone (to load the new Python code).
274+
You do not need to restart the Volto frontend, since we did not do any changes there.
275+
2. Reinstall the package ploneconf.site to apply the updated profile.
276+
277+
1. Go to {guilabel}`Site Setup`.
278+
2. Open the {guilabel}`Add-Ons` control panel.
279+
3. Find `PLONECONF SITE: INSTALL` in the list of installed add-ons and click to open its details.
280+
4. Click the {guilabel}`Uninstall` button.
281+
5. Find it again and click the {guilabel}`Install` button.
255282

256283
Now instances of the new type can be added.
257284
Please check that you can add a talk to your site.
@@ -260,17 +287,16 @@ Please check that you can add a talk to your site.
260287
Adding a talk in the frontend
261288
```
262289

263-
- Test the type by adding a talk. Add some values in the fields, save it, look at the view and edit it again.
290+
- Test the type by adding a talk. Add some values in the fields, save it, look at the view, and edit it again.
264291
- Compare all the fields you see to the code in the schema.
265-
- You can also make changes in the schema. After restarting the backend these changes are effective immediately.
266-
- Find the tool `portal_types` in the ZMI http://localhost:8080/manage.
292+
- You can also make changes in the schema. After restarting the backend, these changes are effective immediately.
293+
- Find the tool `portal_types` in the ZMI: <http://localhost:8080/manage>.
267294
Look at the FTI for type `talk` and inspect the configuration taken from the FTI.
268-
269-
You can make changes to the FTI here.
270-
- A part of the configuration is also available in Plone control panels (SITE SETUP).
271-
For example the content types control panel `http://localhost:3000/controlpanel/dexterity-types` allows to add behaviors to content types.
272-
Please be aware that these changes are done on your site instance.
273-
You can use the browser UI, but it's the add-on package where you configure your content types.
295+
You can make changes to the FTI here.
296+
- A part of the configuration is also available in Site Setup.
297+
For example the [Content Types control panel](http://localhost:3000/controlpanel/dexterity-types) allows to add behaviors to content types.
298+
Please be aware that these changes are done in your site database, but not on the filesystem.
299+
You can use the browser UI, but then the configuration can get out of sync with your filesystem add-on package.
274300

275301
The field values of your talk instance are listed.
276302
In one of the next chapters we will create a custom view for the new type.
@@ -280,12 +306,15 @@ In one of the next chapters we will create a custom view for the new type.
280306

281307
- You created a custom content type.
282308
- You can now control the data that will be stored for talks.
283-
- You can reuse and adapt these examples to model data for your own use-cases.
309+
- You can reuse and adapt these examples to model data for your own use cases.
284310
- Next up: After looking at even more fields that are available in Plone, you will learn to change how talks are displayed.
285311

286312

287313
```{seealso}
288-
- Documentation {doc}`plone6docs:backend/fields`
289-
- [Example content type](https://github.com/collective/example.contenttype/tree/training-mastering-plone-development)
290-
A Plone content type with all available fields
291-
```
314+
- Plone documentation about
315+
- {doc}`plone6docs:backend/content-types/index`
316+
- {doc}`plone6docs:backend/schemas`
317+
- {doc}`plone6docs:backend/fields`
318+
- {doc}`plone6docs:backend/behaviors`
319+
- [Example content type](https://github.com/collective/example.contenttype) - A Plone content type with all available fields
320+
```

docs/mastering-plone/dexterity_reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ myst:
33
html_meta:
44
"description": "Fields and widgets"
55
"property=og:description": "Fields and widgets"
6-
"property=og:title": "Content types: Reference"
6+
"property=og:title": "Content types reference"
77
"keywords": "field, widget, schema"
88
---
99

1010
(dexterity-reference-label)=
1111

12-
# Content types: Reference
12+
# Content types reference
1313

1414
This chapter documents common fields, widgets, directives that you can use with content types.
1515
Content types are often called dexterity types which refers to the rework of the content type concept by dexterity and abandoning the Archetypes system.

0 commit comments

Comments
 (0)