Skip to content

Commit 781f956

Browse files
committed
Tidy defaults.md
1 parent cbacb72 commit 781f956

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed
Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
---
22
myst:
33
html_meta:
4-
"description": ""
5-
"property=og:description": ""
6-
"property=og:title": ""
7-
"keywords": ""
4+
"description": "Content type defaults"
5+
"property=og:description": "Content type defaults"
6+
"property=og:title": "Content type defaults"
7+
"keywords": "Plone, Content type, defaults"
88
---
99

1010
# Defaults
1111

12-
**Default values for fields on add forms**
12+
This chapter describes the default values for fields on add forms.
1313

14-
It is often useful to calculate a default value for a field. This value
15-
will be used on the add form, before the field is set.
14+
It is often useful to calculate a default value for a field.
15+
This value will be used on the add form before the field is set.
1616

17-
To continue with our conference example, let’s set the default values
18-
for the `start` and `end` dates to one week in the future and ten days
19-
in the future, respectively. We can do this by adding the following to
20-
`program.py`:
17+
To continue with our conference example, let's set the default values for the `start` and `end` dates to one week in the future and ten days in the future, respectively.
18+
We can do this by adding the following to {file}`program.py`.
2119

2220
```python
2321
import datetime
@@ -29,8 +27,7 @@ def endDefaultValue():
2927
return datetime.datetime.today() + datetime.timedelta(10)
3028
```
3129

32-
We also need to modify IProgram so the `start` and `end` fields
33-
use these functions as their `defaultFactory`:
30+
We also need to modify `IProgram` so the `start` and `end` fields use these functions as their `defaultFactory`.
3431

3532
```python
3633
class IProgram(model.Schema):
@@ -48,15 +45,12 @@ class IProgram(model.Schema):
4845
)
4946
```
5047

51-
The `defaultFactory` is a function that will be called when the add form
52-
is loaded to determine the default value.
48+
The `defaultFactory` is a function that will be called when the add form is loaded to determine the default value.
5349

54-
The value returned by the method should be a value that’s allowable for
55-
the field. In the case of `Datetime` fields, that’s a Python `datetime`
56-
object.
50+
The value returned by the method should be a value that's allowable for the field.
51+
In the case of `Datetime` fields, that's a Python `datetime` object.
5752

58-
It is also possible to write a context-aware default factory that will be
59-
passed the container for which the add form is being displayed:
53+
It is also possible to write a context-aware default factory that will be passed the container for which the add form is being displayed.
6054

6155
```python
6256
from zope.interface import provider
@@ -67,10 +61,7 @@ def getContainerId(context):
6761
return context.getId()
6862
```
6963

70-
It is possible to provide different default values depending on the type
71-
of context, a request layer, the type of form, or the type of widget
72-
used. See the [z3c.form] documentation for more details.
64+
It is possible to provide different default values depending on the type of context, a request layer, the type of form, or the type of widget used.
65+
See the [z3c.form](https://z3cform.readthedocs.io/en/latest/advanced/validator.html#look-up-value-from-default-adapter) documentation for more details.
7366

74-
We’ll cover creating custom forms later in this manual.
75-
76-
[z3c.form]: https://pypi.python.org/pypi/z3c.form#look-up-value-from-default-adapter
67+
We'll cover creating custom forms later in this manual.

0 commit comments

Comments
 (0)