author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 28 Jul 2010 14:27:28 +0200 | |
branch | stable |
changeset 6029 | aac5dba278c7 |
parent 5877 | 0c7b7b76a84f |
child 6141 | b8287e54b528 |
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
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:
5291
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5722
61d6a4caa963
[iprogress] move adapter to entities.adapters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5569
diff
changeset
|
18 |
"""breadcrumbs components definition for CubicWeb web client""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
1882 | 21 |
_ = unicode |
0 | 22 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
23 |
from warnings import warn |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
24 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
25 |
from logilab.mtconverter import xml_escape |
0 | 26 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
27 |
#from cubicweb.interfaces import IBreadCrumbs |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5722
diff
changeset
|
28 |
from cubicweb.selectors import (is_instance, one_line_rset, adaptable, |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
29 |
one_etype_rset, multi_lines_rset, any_rset) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
30 |
from cubicweb.view import EntityView, Component, EntityAdapter |
713
5adb6d8e5fa7
update imports of "cubicweb.common.entity" and use the new module path "cubicweb.entity"
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
31 |
# don't use AnyEntity since this may cause bug with isinstance() due to reloading |
984 | 32 |
from cubicweb.entity import Entity |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
33 |
from cubicweb import tags, uilib |
0 | 34 |
|
35 |
||
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
36 |
# ease bw compat |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
37 |
def ibreadcrumb_adapter(entity): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
38 |
if hasattr(entity, 'breadcrumbs'): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
39 |
warn('[3.9] breadcrumbs() method is deprecated, define a custom ' |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
40 |
'IBreadCrumbsAdapter for %s instead' % entity.__class__, |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
41 |
DeprecationWarning) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
42 |
return entity |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
43 |
return entity.cw_adapt_to('IBreadCrumbs') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
44 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
45 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
46 |
class IBreadCrumbsAdapter(EntityAdapter): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
47 |
"""adapters for entities which can be"located" on some path to display in |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
48 |
the web ui |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
49 |
""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
50 |
__regid__ = 'IBreadCrumbs' |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5722
diff
changeset
|
51 |
__select__ = is_instance('Any', accept_none=False) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
52 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
53 |
def parent_entity(self): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
54 |
if hasattr(self.entity, 'parent'): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
55 |
warn('[3.9] parent() method is deprecated, define a ' |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
56 |
'custom IBreadCrumbsAdapter/ITreeAdapter for %s instead' |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
57 |
% self.entity.__class__, DeprecationWarning) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
58 |
return self.entity.parent() |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
59 |
itree = self.entity.cw_adapt_to('ITree') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
60 |
if itree is not None: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
61 |
return itree.parent() |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
62 |
return None |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
63 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
64 |
def breadcrumbs(self, view=None, recurs=False): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
65 |
"""return a list containing some: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
66 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
67 |
* tuple (url, label) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
68 |
* entity |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
69 |
* simple label string |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
70 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
71 |
defining path from a root to the current view |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
72 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
73 |
the main view is given as argument so breadcrumbs may vary according |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
74 |
to displayed view (may be None). When recursing on a parent entity, |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
75 |
the `recurs` argument should be set to True. |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
76 |
""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
77 |
parent = self.parent_entity() |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
78 |
if parent is not None: |
5569
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
79 |
adapter = ibreadcrumb_adapter(parent) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
80 |
path = adapter.breadcrumbs(view, True) + [self.entity] |
5569
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
81 |
else: |
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
82 |
path = [self.entity] |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
83 |
if not recurs: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
84 |
if view is None: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
85 |
if 'vtitle' in self._cw.form: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
86 |
# embeding for instance |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
87 |
path.append( self._cw.form['vtitle'] ) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
88 |
elif view.__regid__ != 'primary' and hasattr(view, 'title'): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
89 |
path.append( self._cw._(view.title) ) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
90 |
return path |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
91 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
92 |
|
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
93 |
class BreadCrumbEntityVComponent(Component): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
94 |
__regid__ = 'breadcrumbs' |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
95 |
__select__ = one_line_rset() & adaptable('IBreadCrumbs') |
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
96 |
|
3407
da9cc8cc7c5f
[api] use cw_property_defs instead of deprecated property_defs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
97 |
cw_property_defs = { |
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
98 |
_('visible'): dict(type='Boolean', default=True, |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
99 |
help=_('display the component or not')), |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
100 |
} |
0 | 101 |
title = _('contentnavigation_breadcrumbs') |
102 |
help = _('contentnavigation_breadcrumbs_description') |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
103 |
separator = u' > ' |
3862
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
104 |
link_template = u'<a href="%s">%s</a>' |
0 | 105 |
|
106 |
def call(self, view=None, first_separator=True): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
107 |
entity = self.cw_rset.get_entity(0, 0) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
108 |
adapter = ibreadcrumb_adapter(entity) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
109 |
path = adapter.breadcrumbs(view) |
0 | 110 |
if path: |
3862
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
111 |
self.open_breadcrumbs() |
0 | 112 |
if first_separator: |
113 |
self.w(self.separator) |
|
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
114 |
self.render_breadcrumbs(entity, path) |
3862
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
115 |
self.close_breadcrumbs() |
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
116 |
|
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
117 |
def open_breadcrumbs(self): |
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
118 |
self.w(u'<span id="breadcrumbs" class="pathbar">') |
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
119 |
|
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
120 |
def close_breadcrumbs(self): |
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
121 |
self.w(u'</span>') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
984
diff
changeset
|
122 |
|
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
123 |
def render_breadcrumbs(self, contextentity, path): |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
124 |
root = path.pop(0) |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
125 |
if isinstance(root, Entity): |
3890
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
126 |
self.w(self.link_template % (self._cw.build_url(root.__regid__), |
3862
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
127 |
root.dc_type('plural'))) |
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
128 |
self.w(self.separator) |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
129 |
self.wpath_part(root, contextentity, not path) |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
130 |
for i, parent in enumerate(path): |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
131 |
self.w(self.separator) |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
132 |
self.w(u"\n") |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
133 |
self.wpath_part(parent, contextentity, i == len(path) - 1) |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
134 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
135 |
def wpath_part(self, part, contextentity, last=False): # XXX deprecates last argument? |
0 | 136 |
if isinstance(part, Entity): |
5291
593adaccd737
(implement #761403) The breadcrumb final element is now a link too.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4802
diff
changeset
|
137 |
self.w(part.view('breadcrumbs')) |
0 | 138 |
elif isinstance(part, tuple): |
139 |
url, title = part |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
140 |
textsize = self._cw.property_value('navigation.short-line-size') |
3862
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
141 |
self.w(self.link_template % ( |
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
142 |
xml_escape(url), xml_escape(uilib.cut(title, textsize)))) |
0 | 143 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
144 |
textsize = self._cw.property_value('navigation.short-line-size') |
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
145 |
self.w(uilib.cut(unicode(part), textsize)) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
984
diff
changeset
|
146 |
|
0 | 147 |
|
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
148 |
class BreadCrumbETypeVComponent(BreadCrumbEntityVComponent): |
4320
4efd4c306746
closes #345410: two_lines_rset, two_cols_rset, two_etypes_rset are badly named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
149 |
__select__ = multi_lines_rset() & one_etype_rset() & \ |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
150 |
adaptable('IBreadCrumbs') |
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
151 |
|
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
152 |
def render_breadcrumbs(self, contextentity, path): |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
153 |
# XXX hack: only display etype name or first non entity path part |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
154 |
root = path.pop(0) |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
155 |
if isinstance(root, Entity): |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
156 |
self.w(u'<a href="%s">%s</a>' % (self._cw.build_url(root.__regid__), |
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
157 |
root.dc_type('plural'))) |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
158 |
else: |
3030
e086df78e267
B [views] fixing breadcrumbs
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3015
diff
changeset
|
159 |
self.wpath_part(root, contextentity, not path) |
3007
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
160 |
|
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
161 |
|
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
162 |
class BreadCrumbAnyRSetVComponent(BreadCrumbEntityVComponent): |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
163 |
__select__ = any_rset() |
a15e982aa9a3
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
164 |
|
3015
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
165 |
def call(self, view=None, first_separator=True): |
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
166 |
self.w(u'<span id="breadcrumbs" class="pathbar">') |
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
167 |
if first_separator: |
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
168 |
self.w(self.separator) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
169 |
self.w(self._cw._('search')) |
3015
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
170 |
self.w(u'</span>') |
0 | 171 |
|
172 |
||
173 |
class BreadCrumbView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
174 |
__regid__ = 'breadcrumbs' |
0 | 175 |
|
4802
fa2297d6542a
[views/breadcrumbs] fix bad signature
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4320
diff
changeset
|
176 |
def cell_call(self, row, col, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
177 |
entity = self.cw_rset.get_entity(row, col) |
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
178 |
desc = xml_escape(uilib.cut(entity.dc_description(), 50)) |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
179 |
# XXX remember camember : tags.a autoescapes ! |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
180 |
self.w(tags.a(entity.view('breadcrumbtext'), |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
181 |
href=entity.absolute_url(), title=desc)) |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
182 |
|
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
183 |
|
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
184 |
class BreadCrumbTextView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
185 |
__regid__ = 'breadcrumbtext' |
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
186 |
|
4802
fa2297d6542a
[views/breadcrumbs] fix bad signature
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4320
diff
changeset
|
187 |
def cell_call(self, row, col, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
188 |
entity = self.cw_rset.get_entity(row, col) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
189 |
textsize = self._cw.property_value('navigation.short-line-size') |
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
190 |
self.w(uilib.cut(entity.dc_title(), textsize)) |