author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Wed, 09 Jun 2010 09:42:52 +0200 | |
changeset 5691 | ba2347050144 |
parent 5569 | cb14af012a96 |
child 5718 | 8d246203730a |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5309
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5309
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4719
diff
changeset
|
18 |
"""mixins of entity/views organized somewhat in a graph or tree structure""" |
0 | 19 |
__docformat__ = "restructuredtext en" |
20 |
||
4401
4d973c834eb3
missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4395
diff
changeset
|
21 |
from itertools import chain |
4d973c834eb3
missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4395
diff
changeset
|
22 |
|
0 | 23 |
from logilab.common.decorators import cached |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
24 |
from logilab.common.deprecation import deprecated, class_deprecated |
0 | 25 |
|
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
471
diff
changeset
|
26 |
from cubicweb.selectors import implements |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
27 |
from cubicweb.interfaces import ITree |
0 | 28 |
|
29 |
||
30 |
class TreeMixIn(object): |
|
5309
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4719
diff
changeset
|
31 |
"""base tree-mixin implementing the tree interface |
0 | 32 |
|
33 |
This mixin has to be inherited explicitly and configured using the |
|
34 |
tree_attribute, parent_target and children_target class attribute to |
|
35 |
benefit from this default implementation |
|
36 |
""" |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
37 |
__metaclass__ = class_deprecated |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
38 |
__deprecation_warning__ = '[3.9] TreeMixIn is deprecated, use/override ITreeAdapter instead' |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
39 |
|
0 | 40 |
tree_attribute = None |
41 |
# XXX misnamed |
|
42 |
parent_target = 'subject' |
|
43 |
children_target = 'object' |
|
1451 | 44 |
|
0 | 45 |
def different_type_children(self, entities=True): |
46 |
"""return children entities of different type as this entity. |
|
1451 | 47 |
|
0 | 48 |
according to the `entities` parameter, return entity objects or the |
49 |
equivalent result set |
|
50 |
""" |
|
51 |
res = self.related(self.tree_attribute, self.children_target, |
|
52 |
entities=entities) |
|
53 |
if entities: |
|
54 |
return [e for e in res if e.e_schema != self.e_schema] |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3426
diff
changeset
|
55 |
return res.filtered_rset(lambda x: x.e_schema != self.e_schema, self.cw_col) |
0 | 56 |
|
57 |
def same_type_children(self, entities=True): |
|
58 |
"""return children entities of the same type as this entity. |
|
1451 | 59 |
|
0 | 60 |
according to the `entities` parameter, return entity objects or the |
61 |
equivalent result set |
|
62 |
""" |
|
63 |
res = self.related(self.tree_attribute, self.children_target, |
|
64 |
entities=entities) |
|
65 |
if entities: |
|
66 |
return [e for e in res if e.e_schema == self.e_schema] |
|
4395 | 67 |
return res.filtered_rset(lambda x: x.e_schema is self.e_schema, self.cw_col) |
1451 | 68 |
|
0 | 69 |
def iterchildren(self, _done=None): |
70 |
if _done is None: |
|
71 |
_done = set() |
|
72 |
for child in self.children(): |
|
73 |
if child.eid in _done: |
|
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
74 |
self.error('loop in %s tree', self.__regid__.lower()) |
0 | 75 |
continue |
76 |
yield child |
|
77 |
_done.add(child.eid) |
|
78 |
||
79 |
def prefixiter(self, _done=None): |
|
80 |
if _done is None: |
|
81 |
_done = set() |
|
82 |
if self.eid in _done: |
|
83 |
return |
|
4383
e62a9efdd90a
it seems that prefixiter is expected to return child *folder* but was relying on a specific .children implementation, fix this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4351
diff
changeset
|
84 |
_done.add(self.eid) |
0 | 85 |
yield self |
4383
e62a9efdd90a
it seems that prefixiter is expected to return child *folder* but was relying on a specific .children implementation, fix this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4351
diff
changeset
|
86 |
for child in self.same_type_children(): |
e62a9efdd90a
it seems that prefixiter is expected to return child *folder* but was relying on a specific .children implementation, fix this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4351
diff
changeset
|
87 |
for entity in child.prefixiter(_done): |
e62a9efdd90a
it seems that prefixiter is expected to return child *folder* but was relying on a specific .children implementation, fix this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4351
diff
changeset
|
88 |
yield entity |
1451 | 89 |
|
0 | 90 |
@cached |
91 |
def path(self): |
|
92 |
"""returns the list of eids from the root object to this object""" |
|
93 |
path = [] |
|
94 |
parent = self |
|
95 |
while parent: |
|
96 |
if parent.eid in path: |
|
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
97 |
self.error('loop in %s tree', self.__regid__.lower()) |
0 | 98 |
break |
99 |
path.append(parent.eid) |
|
100 |
try: |
|
101 |
# check we are not leaving the tree |
|
102 |
if (parent.tree_attribute != self.tree_attribute or |
|
103 |
parent.parent_target != self.parent_target): |
|
104 |
break |
|
105 |
parent = parent.parent() |
|
106 |
except AttributeError: |
|
107 |
break |
|
108 |
||
109 |
path.reverse() |
|
110 |
return path |
|
1451 | 111 |
|
4351
619c7f9302fc
get back iterparents implementation from folder cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
112 |
def iterparents(self, strict=True): |
173
a4a9e1a7e40f
TreeMixin : provide an iterator on the parents
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
62
diff
changeset
|
113 |
def _uptoroot(self): |
a4a9e1a7e40f
TreeMixin : provide an iterator on the parents
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
62
diff
changeset
|
114 |
curr = self |
a4a9e1a7e40f
TreeMixin : provide an iterator on the parents
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
62
diff
changeset
|
115 |
while True: |
a4a9e1a7e40f
TreeMixin : provide an iterator on the parents
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
62
diff
changeset
|
116 |
curr = curr.parent() |
a4a9e1a7e40f
TreeMixin : provide an iterator on the parents
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
62
diff
changeset
|
117 |
if curr is None: |
a4a9e1a7e40f
TreeMixin : provide an iterator on the parents
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
62
diff
changeset
|
118 |
break |
a4a9e1a7e40f
TreeMixin : provide an iterator on the parents
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
62
diff
changeset
|
119 |
yield curr |
4351
619c7f9302fc
get back iterparents implementation from folder cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
120 |
if not strict: |
619c7f9302fc
get back iterparents implementation from folder cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
121 |
return chain([self], _uptoroot(self)) |
173
a4a9e1a7e40f
TreeMixin : provide an iterator on the parents
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
62
diff
changeset
|
122 |
return _uptoroot(self) |
a4a9e1a7e40f
TreeMixin : provide an iterator on the parents
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
62
diff
changeset
|
123 |
|
0 | 124 |
## ITree interface ######################################################## |
125 |
def parent(self): |
|
126 |
"""return the parent entity if any, else None (e.g. if we are on the |
|
127 |
root |
|
128 |
""" |
|
129 |
try: |
|
130 |
return self.related(self.tree_attribute, self.parent_target, |
|
131 |
entities=True)[0] |
|
132 |
except (KeyError, IndexError): |
|
133 |
return None |
|
134 |
||
135 |
def children(self, entities=True, sametype=False): |
|
136 |
"""return children entities |
|
137 |
||
138 |
according to the `entities` parameter, return entity objects or the |
|
139 |
equivalent result set |
|
140 |
""" |
|
141 |
if sametype: |
|
142 |
return self.same_type_children(entities) |
|
143 |
else: |
|
144 |
return self.related(self.tree_attribute, self.children_target, |
|
145 |
entities=entities) |
|
146 |
||
147 |
def children_rql(self): |
|
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
148 |
return self.cw_related_rql(self.tree_attribute, self.children_target) |
1451 | 149 |
|
0 | 150 |
def is_leaf(self): |
151 |
return len(self.children()) == 0 |
|
152 |
||
153 |
def is_root(self): |
|
154 |
return self.parent() is None |
|
155 |
||
156 |
def root(self): |
|
157 |
"""return the root object""" |
|
3426
6ea4a2ff01c9
[api] use cw_*
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3023
diff
changeset
|
158 |
return self._cw.entity_from_eid(self.path()[0]) |
0 | 159 |
|
160 |
||
161 |
class EmailableMixIn(object): |
|
162 |
"""base mixin providing the default get_email() method used by |
|
163 |
the massmailing view |
|
164 |
||
165 |
NOTE: The default implementation is based on the |
|
166 |
primary_email / use_email scheme |
|
167 |
""" |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
168 |
@deprecated("[3.9] use entity.cw_adapt_to('IEmailable').get_email()") |
0 | 169 |
def get_email(self): |
170 |
if getattr(self, 'primary_email', None): |
|
171 |
return self.primary_email[0].address |
|
172 |
if getattr(self, 'use_email', None): |
|
173 |
return self.use_email[0].address |
|
174 |
return None |
|
175 |
||
176 |
||
3926 | 177 |
"""pluggable mixins system: plug classes registered in MI_REL_TRIGGERS on entity |
178 |
classes which have the relation described by the dict's key. |
|
1451 | 179 |
|
3926 | 180 |
NOTE: pluggable mixins can't override any method of the 'explicit' user classes tree |
181 |
(eg without plugged classes). This includes bases Entity and AnyEntity classes. |
|
182 |
""" |
|
0 | 183 |
MI_REL_TRIGGERS = { |
184 |
('primary_email', 'subject'): EmailableMixIn, |
|
185 |
('use_email', 'subject'): EmailableMixIn, |
|
186 |
} |
|
187 |
||
188 |
||
5569
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
189 |
# XXX move to cubicweb.web.views.treeview once we delete usage from this file |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
190 |
def _done_init(done, view, row, col): |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
191 |
"""handle an infinite recursion safety belt""" |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
192 |
if done is None: |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
193 |
done = set() |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
194 |
entity = view.cw_rset.get_entity(row, col) |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
195 |
if entity.eid in done: |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
196 |
msg = entity._cw._('loop in %(rel)s relation (%(eid)s)') % { |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
197 |
'rel': entity.tree_attribute, |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
198 |
'eid': entity.eid |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
199 |
} |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
200 |
return None, msg |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
201 |
done.add(entity.eid) |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
202 |
return done, entity |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
203 |
|
0 | 204 |
|
205 |
class TreeViewMixIn(object): |
|
206 |
"""a recursive tree view""" |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
207 |
__metaclass__ = class_deprecated |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
208 |
__deprecation_warning__ = '[3.9] TreeViewMixIn is deprecated, use/override BaseTreeView instead' |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
209 |
|
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
210 |
__regid__ = 'tree' |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
211 |
__select__ = implements(ITree) |
0 | 212 |
item_vid = 'treeitem' |
213 |
||
214 |
def call(self, done=None, **kwargs): |
|
215 |
if done is None: |
|
216 |
done = set() |
|
217 |
super(TreeViewMixIn, self).call(done=done, **kwargs) |
|
1451 | 218 |
|
0 | 219 |
def cell_call(self, row, col=0, vid=None, done=None, **kwargs): |
220 |
done, entity = _done_init(done, self, row, col) |
|
221 |
if done is None: |
|
222 |
# entity is actually an error message |
|
223 |
self.w(u'<li class="badcontent">%s</li>' % entity) |
|
224 |
return |
|
225 |
self.open_item(entity) |
|
226 |
entity.view(vid or self.item_vid, w=self.w, **kwargs) |
|
227 |
relatedrset = entity.children(entities=False) |
|
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
228 |
self.wview(self.__regid__, relatedrset, 'null', done=done, **kwargs) |
0 | 229 |
self.close_item(entity) |
230 |
||
231 |
def open_item(self, entity): |
|
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
232 |
self.w(u'<li class="%s">\n' % entity.__regid__.lower()) |
0 | 233 |
def close_item(self, entity): |
234 |
self.w(u'</li>\n') |
|
235 |
||
236 |
||
237 |
class TreePathMixIn(object): |
|
238 |
"""a recursive path view""" |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
239 |
__metaclass__ = class_deprecated |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
240 |
__deprecation_warning__ = '[3.9] TreePathMixIn is deprecated, use/override TreePathView instead' |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3426
diff
changeset
|
241 |
__regid__ = 'path' |
0 | 242 |
item_vid = 'oneline' |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2748
diff
changeset
|
243 |
separator = u' > ' |
0 | 244 |
|
245 |
def call(self, **kwargs): |
|
246 |
self.w(u'<div class="pathbar">') |
|
247 |
super(TreePathMixIn, self).call(**kwargs) |
|
248 |
self.w(u'</div>') |
|
1451 | 249 |
|
0 | 250 |
def cell_call(self, row, col=0, vid=None, done=None, **kwargs): |
251 |
done, entity = _done_init(done, self, row, col) |
|
252 |
if done is None: |
|
253 |
# entity is actually an error message |
|
254 |
self.w(u'<span class="badcontent">%s</span>' % entity) |
|
255 |
return |
|
256 |
parent = entity.parent() |
|
257 |
if parent: |
|
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
258 |
parent.view(self.__regid__, w=self.w, done=done) |
0 | 259 |
self.w(self.separator) |
260 |
entity.view(vid or self.item_vid, w=self.w) |
|
261 |
||
262 |
||
263 |
class ProgressMixIn(object): |
|
5309
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4719
diff
changeset
|
264 |
"""provide a default implementations for IProgress interface methods""" |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
265 |
__metaclass__ = class_deprecated |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
266 |
__deprecation_warning__ = '[3.9] ProgressMixIn is deprecated, use/override IProgressAdapter instead' |
0 | 267 |
|
268 |
@property |
|
269 |
def cost(self): |
|
270 |
return self.progress_info()['estimated'] |
|
271 |
||
272 |
@property |
|
273 |
def revised_cost(self): |
|
274 |
return self.progress_info().get('estimatedcorrected', self.cost) |
|
275 |
||
276 |
@property |
|
277 |
def done(self): |
|
278 |
return self.progress_info()['done'] |
|
279 |
||
280 |
@property |
|
281 |
def todo(self): |
|
282 |
return self.progress_info()['todo'] |
|
283 |
||
284 |
@cached |
|
285 |
def progress_info(self): |
|
286 |
raise NotImplementedError() |
|
287 |
||
288 |
def finished(self): |
|
289 |
return not self.in_progress() |
|
290 |
||
291 |
def in_progress(self): |
|
292 |
raise NotImplementedError() |
|
1451 | 293 |
|
0 | 294 |
def progress(self): |
295 |
try: |
|
296 |
return 100. * self.done / self.revised_cost |
|
297 |
except ZeroDivisionError: |
|
298 |
# total cost is 0 : if everything was estimated, task is completed |
|
961 | 299 |
if self.progress_info().get('notestimated'): |
0 | 300 |
return 0. |
301 |
return 100 |