annotate piecrust/data/linker.py @ 1071:7f94407d037d 3.0.0

cm: Regenerate the CHANGELOG.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 13 Feb 2018 23:48:18 -0800
parents f6b975db2545
children 00a0a65d08e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
172
4fc1d306046b linker: Actually implement the `Linker` class, and use it in the page data.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
1 import logging
440
32c7c2d219d2 performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents: 411
diff changeset
2 from piecrust.data.paginationdata import PaginationData
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
3 from piecrust.sources.base import (
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
4 REL_PARENT_GROUP, REL_LOGICAL_PARENT_ITEM, REL_LOGICAl_CHILD_GROUP)
172
4fc1d306046b linker: Actually implement the `Linker` class, and use it in the page data.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
5
4fc1d306046b linker: Actually implement the `Linker` class, and use it in the page data.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
6
4fc1d306046b linker: Actually implement the `Linker` class, and use it in the page data.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
7 logger = logging.getLogger(__name__)
4fc1d306046b linker: Actually implement the `Linker` class, and use it in the page data.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
8
4fc1d306046b linker: Actually implement the `Linker` class, and use it in the page data.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
9
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
10 _unloaded = object()
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
11
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
12
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
13 class Linker:
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
14 """ A template-exposed data class that lets the user navigate the
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
15 logical hierarchy of pages in a page source.
247
d9d5c5de02a8 data: Add a top level wrapper for `Linker`.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
16 """
408
fd8e39254da0 debug: Better debug info output for iterators, providers, and linkers.
Ludovic Chabant <ludovic@chabant.com>
parents: 404
diff changeset
17 debug_render = ['parent', 'ancestors', 'siblings', 'children', 'root',
fd8e39254da0 debug: Better debug info output for iterators, providers, and linkers.
Ludovic Chabant <ludovic@chabant.com>
parents: 404
diff changeset
18 'forpath']
590
3cca1f6bd610 debug: Fix how the linker shows children/siblings/etc. in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents: 518
diff changeset
19 debug_render_invoke = ['parent', 'ancestors', 'siblings', 'children',
3cca1f6bd610 debug: Fix how the linker shows children/siblings/etc. in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents: 518
diff changeset
20 'root']
3cca1f6bd610 debug: Fix how the linker shows children/siblings/etc. in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents: 518
diff changeset
21 debug_render_redirect = {
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 590
diff changeset
22 'ancestors': '_debugRenderAncestors',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 590
diff changeset
23 'siblings': '_debugRenderSiblings',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 590
diff changeset
24 'children': '_debugRenderChildren',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 590
diff changeset
25 'root': '_debugRenderRoot'}
408
fd8e39254da0 debug: Better debug info output for iterators, providers, and linkers.
Ludovic Chabant <ludovic@chabant.com>
parents: 404
diff changeset
26
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
27 def __init__(self, source, content_item):
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
28 self._source = source
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
29 self._content_item = content_item
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
30
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
31 self._parent_group = _unloaded
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
32 self._ancestors = None
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
33 self._siblings = None
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
34 self._children = None
404
27b10024f8d8 linker: Add ability to return the parent and ancestors of a page.
Ludovic Chabant <ludovic@chabant.com>
parents: 402
diff changeset
35
27b10024f8d8 linker: Add ability to return the parent and ancestors of a page.
Ludovic Chabant <ludovic@chabant.com>
parents: 402
diff changeset
36 @property
27b10024f8d8 linker: Add ability to return the parent and ancestors of a page.
Ludovic Chabant <ludovic@chabant.com>
parents: 402
diff changeset
37 def parent(self):
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
38 a = self.ancestors
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
39 if a:
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
40 return a[0]
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
41 return None
404
27b10024f8d8 linker: Add ability to return the parent and ancestors of a page.
Ludovic Chabant <ludovic@chabant.com>
parents: 402
diff changeset
42
27b10024f8d8 linker: Add ability to return the parent and ancestors of a page.
Ludovic Chabant <ludovic@chabant.com>
parents: 402
diff changeset
43 @property
1055
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
44 def root(self):
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
45 a = self.ancestors
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
46 if a:
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
47 return a[-1]
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
48 return self.myself
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
49
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
50 @property
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
51 def myself(self):
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
52 page = self._source.app.getPage(self._source, self._content_item)
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
53 return self._makePageData(page)
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
54
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
55 @property
404
27b10024f8d8 linker: Add ability to return the parent and ancestors of a page.
Ludovic Chabant <ludovic@chabant.com>
parents: 402
diff changeset
56 def ancestors(self):
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
57 if self._ancestors is None:
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
58 src = self._source
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
59 app = src.app
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
60
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
61 self._ancestors = []
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
62 cur_group = self._getParentGroup()
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
63 while cur_group:
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
64 pi = src.getRelatedContents(cur_group,
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
65 REL_LOGICAL_PARENT_ITEM)
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
66 if pi is not None:
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
67 pipage = app.getPage(src, pi)
1055
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
68 self._ancestors.append(self._makePageData(pipage))
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
69 cur_group = src.getRelatedContents(
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
70 pi, REL_PARENT_GROUP)
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
71 else:
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
72 break
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 853
diff changeset
73 return self._ancestors
247
d9d5c5de02a8 data: Add a top level wrapper for `Linker`.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
74
d9d5c5de02a8 data: Add a top level wrapper for `Linker`.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
75 @property
d9d5c5de02a8 data: Add a top level wrapper for `Linker`.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
76 def siblings(self):
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
77 src = self._source
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
78 app = src.app
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
79 sibs = []
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
80 for i in self._getAllSiblings():
979
45ad976712ec tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents: 977
diff changeset
81 if not i.is_group:
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
82 ipage = app.getPage(src, i)
1055
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
83 ipage_data = self._makePageData(ipage)
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
84 sibs.append(ipage_data)
1055
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
85 else:
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
86 sibs.append(self._makeGroupData(i))
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
87 return sibs
1055
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
88
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
89 @property
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
90 def has_children(self):
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
91 return bool(self.children)
247
d9d5c5de02a8 data: Add a top level wrapper for `Linker`.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
92
d9d5c5de02a8 data: Add a top level wrapper for `Linker`.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
93 @property
d9d5c5de02a8 data: Add a top level wrapper for `Linker`.
Ludovic Chabant <ludovic@chabant.com>
parents: 242
diff changeset
94 def children(self):
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
95 src = self._source
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
96 app = src.app
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
97 childs = []
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
98 for i in self._getAllChildren():
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
99 if not i.is_group:
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
100 ipage = app.getPage(src, i)
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
101 childs.append(self._makePageData(ipage))
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
102 return childs
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
103
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
104 @property
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
105 def children_and_groups(self):
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
106 src = self._source
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
107 app = src.app
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
108 childs = []
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
109 for i in self._getAllChildren():
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
110 if not i.is_group:
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
111 ipage = app.getPage(src, i)
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
112 childs.append(self._makePageData(ipage))
1055
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
113 else:
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
114 childs.append(self._makeGroupData(i))
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
115 return childs
404
27b10024f8d8 linker: Add ability to return the parent and ancestors of a page.
Ludovic Chabant <ludovic@chabant.com>
parents: 402
diff changeset
116
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
117 def forpath(self, path):
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
118 # TODO: generalize this for sources that aren't file-system based.
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
119 item = self._source.findContentFromRoute({'slug': path})
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
120 return Linker(self._source, item)
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
121
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
122 def childrenof(self, path, with_groups=False):
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
123 # TODO: generalize this for sources that aren't file-system based.
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
124 src = self._source
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
125 app = src.app
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
126 item = src.findContentFromRoute({'slug': path})
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
127 if item is None:
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
128 raise ValueError("No such content: %s" % path)
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
129
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
130 group = self._source.getRelatedContents(item,
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
131 REL_LOGICAL_CHILD_GROUP)
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
132 if group is not None:
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
133 childs = []
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
134 for i in src.getContents(group):
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
135 if not i.is_group:
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
136 ipage = app.getPage(src, i)
1058
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
137 childs.append(self._makePageData(ipage))
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
138 elif with_groups:
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
139 childs.append(self._makeGroupData(i))
f6b975db2545 data: Make `family` properties return lists instead of generators.
Ludovic Chabant <ludovic@chabant.com>
parents: 1055
diff changeset
140 return childs
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
141 return None
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
142
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
143 def _getAllSiblings(self):
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
144 if self._siblings is None:
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
145 self._siblings = list(self._source.getContents(
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
146 self._getParentGroup()))
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
147 return self._siblings
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
148
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
149 def _getAllChildren(self):
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
150 if self._children is None:
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
151 child_group = self._source.getRelatedContents(
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
152 self._content_item, REL_LOGICAl_CHILD_GROUP)
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
153 if child_group is not None:
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
154 self._children = list(
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
155 self._source.getContents(child_group))
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
156 else:
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
157 self._children = []
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
158 return self._children
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
159
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
160 def _getParentGroup(self):
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
161 if self._parent_group is _unloaded:
977
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
162 self._parent_group = self._source.getRelatedContents(
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
163 self._content_item, REL_PARENT_GROUP)
84fc72a17f7a sources: Changes in related contents management.
Ludovic Chabant <ludovic@chabant.com>
parents: 866
diff changeset
164 return self._parent_group
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
165
1055
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
166 def _makePageData(self, page):
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
167 return _PageData(self, page)
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
168
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
169 def _makeGroupData(self, group):
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
170 return _GroupData(self._source, group)
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
171
590
3cca1f6bd610 debug: Fix how the linker shows children/siblings/etc. in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents: 518
diff changeset
172 def _debugRenderAncestors(self):
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
173 return [i.title for i in self.ancestors]
590
3cca1f6bd610 debug: Fix how the linker shows children/siblings/etc. in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents: 518
diff changeset
174
3cca1f6bd610 debug: Fix how the linker shows children/siblings/etc. in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents: 518
diff changeset
175 def _debugRenderSiblings(self):
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
176 return [i.title for i in self.siblings]
590
3cca1f6bd610 debug: Fix how the linker shows children/siblings/etc. in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents: 518
diff changeset
177
3cca1f6bd610 debug: Fix how the linker shows children/siblings/etc. in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents: 518
diff changeset
178 def _debugRenderChildren(self):
866
d9059257743c refactor: Make the linker work again.
Ludovic Chabant <ludovic@chabant.com>
parents: 862
diff changeset
179 return [i.title for i in self.children]
590
3cca1f6bd610 debug: Fix how the linker shows children/siblings/etc. in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents: 518
diff changeset
180
1055
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
181
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
182 class _PageData(PaginationData):
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
183 def __init__(self, linker, page):
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
184 super().__init__(page)
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
185 self._linker = linker
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
186
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
187 def _load(self):
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
188 super()._load()
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
189 self._mapValue('is_page', True)
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
190 self._mapValue(
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
191 'is_self',
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
192 self._page.content_spec == self._linker._content_item.spec)
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
193
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
194 self._mapLoader('is_dir', lambda d, n: self._linker.has_children)
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
195 self._mapLoader('is_group', lambda d, n: self._linker.has_children)
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
196
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
197
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
198 class _GroupData:
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
199 def __init__(self, source, group_item):
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
200 self._source = source
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
201 self._group_item = group_item
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
202 self.is_page = False
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
203 self.is_dir = True
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
204 self.is_group = True
7e4742a60d14 data: Add new properties and folder support to the `family` data endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 989
diff changeset
205 self.family = Linker(source, group_item)