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
"description": "Explaining the concepts of traversal and acquisition in Zope/Plone"
5
-
"property=og:description": ""
6
-
"property=og:title": ""
7
-
"keywords": ""
4
+
"description": "Traversal and acquisition in Zope and Plone"
5
+
"property=og:description": "Traversal and acquisition in Zope and Plone"
6
+
"property=og:title": "Traversal and acquisition in Zope and Plone"
7
+
"keywords": "Plone, traversal, acquisition, Zope"
8
8
---
9
9
10
10
(traversal-and-acquisition-label)=
11
11
12
12
# Traversal and Acquisition
13
13
14
-
# Traversal
14
+
This chapter describes the concepts of {term}`traversal` and {term}`acquisition`.
15
15
16
-
(backend-traversing-label)=
17
16
18
-
In Zope and Plone, traversal is the process of determining the object that is the target of a request by examining the URL path of the request or in code and looking up objects in the object hierarchy.
17
+
(backend-traversal-label)=
18
+
19
+
## Traversal
20
+
21
+
In Zope and Plone, {term}`traversal` is the process of determining the object that is the target of a request by examining the URL path of the request or in code, and looking up objects in the object hierarchy.
19
22
The object hierarchy in Zope is made up of "containers" and "item" objects.
20
23
Containers can contain other objects, while item objects cannot.
21
24
This is to some degree like the tree structure of a filesystem with folders, subfolders, and files.
22
25
23
-
When a request is made to the server, it examines the URL path of the request and starts at the root of the object hierarchy.
26
+
When a request is made to the server, it examines the URL path of the request, and starts at the root of the object hierarchy.
24
27
It then looks up each element of the URL path, starting with the first element in the current container, and if it finds an object with a matching name, it sets that object as the current container and continues to the next element of the URL path.
25
28
This process continues until the final element of the URL path is reached, at which point the server has determined the target object of the request.
26
29
If not explicitly given, at the end a default view is looked up.
27
-
This can be a registered page template, a callable view class, or a RestAPI endpoint.
30
+
This can be a registered page template, a callable view class, or a REST API endpoint.
28
31
29
32
```{seealso}
30
33
{ref}`Chapter Views <classic-ui-views-label>`
@@ -35,54 +38,52 @@ While request traversal and `restrictedTraverse` always include security checks,
35
38
The developer has more control over the traversal process and can access objects without the normal security restrictions, but security restrictions have to be implemented by the developer accordingly.
36
39
37
40
38
-
# Acquisition
39
-
40
41
(backend-qcquisition-label)=
41
42
42
-
In Zope, "acquisition" is a mechanism that allows objects to inherit attributes from their parent objects in the object hierarchy.
43
+
## Acquisition
44
+
45
+
In Zope, {term}`acquisition` is a mechanism that allows objects to inherit attributes from their parent objects in the object hierarchy.
43
46
This enables objects to "acquire" attributes from their parent objects, rather than having to define all attributes themselves.
44
47
45
-
For example, if object A contains object B, and object A has an attribute "x", then object B can access the attribute x via acquisition, without having to define the attribute itself.
48
+
For example, if object A contains object `B`, and object `A` has an attribute `x`, then object `B` can access the attribute `x` via acquisition, without having to define the attribute itself.
46
49
47
-
## Influences on traversal
50
+
51
+
### Influences on traversal
48
52
49
53
This concept influences traversal in Zope because it allows objects to be accessed on traversal by acquisition in the object hierarchy, rather than having to know the exact location of an object.
50
-
For example, if an object "C" is located at the path "/A/B/C", it can also be accessed by traversing the hierarchy starting from object E in the path "/A/B/D/E" with "E.C", because it is acquiring attributes of objects D, B and A along the way.
54
+
For example, if an object `C` is located at the path `/A/B/C`, it can also be accessed by traversing the hierarchy starting from object `E` in the path `/A/B/D/E` with `E.C`, because it is acquiring attributes of objects `D`, `B`, and `A` along the way.
51
55
This makes it at the same time easier and more confusing to find and access objects in a large, complex object hierarchy.
52
56
53
57
54
-
## Explicit vs Implicit Acquisition
58
+
###Explicit versus implicit acquisition
55
59
56
60
In Zope, acquisition can be either explicit or implicit.
57
61
58
62
Explicit acquisition refers to the ability of an object to specifically request attributes from its parent object.
59
-
This is done by using the "Acquire" or "aq_acquire" method to acquire a specific attribute from a parent object.
60
-
For example, if object A contains object B, and object A has an attribute "x", object B can explicitly acquire attribute x by calling `B.aq_acquire("x")`.
63
+
This is done by using the `Acquire` or `aq_acquire` method to acquire a specific attribute from a parent object.
64
+
For example, if object `A` contains object `B`, and object `A` has an attribute `x`, object `B` can explicitly acquire attribute x by calling `B.aq_acquire("x")`.
61
65
62
66
Implicit acquisition refers to the automatic inheritance of attributes from parent objects without the need for explicit requests.
63
67
This is the default behavior in Zope, where objects automatically inherit attributes from their parent objects if they don't have the property defined themselves.
64
-
For example, if object A contains object B, and object A has a property "x", object B can implicitly acquire property x by simply accessing the property x without calling the acquire method: `B.x`.
68
+
For example, if object `A` contains object `B`, and object `A` has a property `x`, object `B` can implicitly acquire property `x` by accessing the property `x` via `B.x`without calling the `acquire` method.
65
69
66
-
The attribute is always acquired from its nearest parent and if it does not exist there it looks at the next parent up the hierarchy.
67
-
If the root is reached and no such attribute was found an `AttributeError` is raised.
70
+
The attribute is always acquired from its nearest parent, and if it does not exist there, then it looks at the next parent up the hierarchy.
71
+
If the root is reached and no such attribute was found, an `AttributeError` is raised.
68
72
69
-
A common use of implicit acquisition in Plone is to access tools like the `portal_catalog` from deep within the object hierarchy.
73
+
A common use of implicit acquisition in Plone is to access tools such as the `portal_catalog` from deep within the object hierarchy.
70
74
This is done by calling methods on the tool, such as `context.portal_catalog.searchResults(**query)`, where `context` is a content object located deep within the hierarchy.
71
75
This works because the `portal_catalog` tool is a child object of the Plone portal root, and is automatically acquired by objects further down the hierarchy.
72
76
This allows developers to access the tool without having to know its exact location within the hierarchy.
73
77
However, getting tools this way is discouraged, as this includes extra processing overhead.
74
78
75
79
In general, implicit acquisition is more commonly used in Zope, as it allows for a more natural and less verbose way of working with objects and their attributes.
76
80
On the other hand, implicit acquisition needs to be blocked to be sure to not acquire attributes using the `aq_base` method.
77
-
For example, if object A contains object B, and object A has a property "x", and the question is whether an attribute x exists on object B or not, then `getattr(B.aq_base, 'x', _marker)` avoids acquisition from A.
78
-
81
+
For example, if object `A` contains object `B`, and object `A` has a property `x`, and the question is whether an attribute `x` exists on object `B` or not, then `getattr(B.aq_base, "x", _marker)` avoids acquisition from `A`.
79
82
80
-
# Further Reading
81
83
82
-
```{seealso}
83
-
About traversal: [Zope Developers Handbook, Chapter Object Publishing](https://zope.readthedocs.io/en/latest/zdgbook/ObjectPublishing.html)
84
-
```
84
+
## Further Reading
85
85
86
86
```{seealso}
87
-
About Acquisition: [Zope Developers Handbook, Chapter Acquisition](https://zope.readthedocs.io/en/latest/zdgbook/Acquisition.html)
87
+
- About traversal: [Zope Developers Handbook, Chapter Object Publishing](https://zope.readthedocs.io/en/latest/zdgbook/ObjectPublishing.html)
88
+
- About acquisition: [Zope Developers Handbook, Chapter Acquisition](https://zope.readthedocs.io/en/latest/zdgbook/Acquisition.html)
Copy file name to clipboardExpand all lines: docs/classic-ui/views.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -413,7 +413,7 @@ And then in the template call:
413
413
The Python constructor method of the view, `__init__()`, is special.
414
414
You should almost never try to put your code there. Instead, use the `_call__()` method or further helper methods called from it.
415
415
416
-
The `__init__()` method of the view might not have an {ref}`acquisition chain <backend-traversing-label>` available, meaning that it does not know where is its parent or hierarchy.
416
+
The `__init__()` method of the view might not have an {ref}`acquisition chain <backend-traversal-label>` available, meaning that it does not know where is its parent or hierarchy.
417
417
This also means that you don't have user information and permissions for the view.
418
418
419
419
This information is set after the constructor has been run.
Copy file name to clipboardExpand all lines: docs/glossary.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -629,4 +629,10 @@ view
629
629
A view is the basic element of modern Python web frameworks.
630
630
A view runs code to set up Python variables for a rendering template.
631
631
The output is not limited to HTML pages and snippets, but may contain {term}`JSON`, file download payloads, or other data formats.
632
+
633
+
traversal
634
+
Traversal is the process of determining the object that is the target of a request by examining the URL path of the request or in code, and looking up objects in the object hierarchy.
635
+
636
+
acquisition
637
+
Acquisition is a mechanism that allows objects to inherit attributes from their parent objects in the object hierarchy.
0 commit comments