author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 13 Oct 2009 16:00:09 +0200 | |
changeset 3658 | d8f2ec7e91fa |
parent 3524 | a3431f4e2f40 |
child 3890 | d7a270f50f54 |
permissions | -rw-r--r-- |
0 | 1 |
"""navigation components definition for CubicWeb web client |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1882
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1882
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
1882 | 9 |
_ = unicode |
0 | 10 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
11 |
from logilab.mtconverter import xml_escape |
0 | 12 |
|
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
|
13 |
from cubicweb.interfaces import IBreadCrumbs |
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
|
14 |
from cubicweb.selectors import (one_line_rset, implements, one_etype_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
|
15 |
two_lines_rset, 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
|
16 |
from cubicweb.view import EntityView, Component |
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
|
17 |
# don't use AnyEntity since this may cause bug with isinstance() due to reloading |
984 | 18 |
from cubicweb.entity import Entity |
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
19 |
from cubicweb.common import tags, uilib |
0 | 20 |
|
21 |
||
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
|
22 |
class BreadCrumbEntityVComponent(Component): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
23 |
__regid__ = 'breadcrumbs' |
3523
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
24 |
__select__ = one_line_rset() & implements(IBreadCrumbs, accept_none=False) |
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
|
25 |
|
3407
da9cc8cc7c5f
[api] use cw_property_defs instead of deprecated property_defs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
26 |
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
|
27 |
_('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
|
28 |
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
|
29 |
} |
0 | 30 |
title = _('contentnavigation_breadcrumbs') |
31 |
help = _('contentnavigation_breadcrumbs_description') |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
32 |
separator = u' > ' |
0 | 33 |
|
34 |
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
|
35 |
entity = self.cw_rset.get_entity(0, 0) |
0 | 36 |
path = entity.breadcrumbs(view) |
37 |
if 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
|
38 |
self.w(u'<span id="breadcrumbs" class="pathbar">') |
0 | 39 |
if first_separator: |
40 |
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
|
41 |
self.render_breadcrumbs(entity, path) |
0 | 42 |
self.w(u'</span>') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
984
diff
changeset
|
43 |
|
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
|
0 | 56 |
def wpath_part(self, part, contextentity, last=False): |
57 |
if isinstance(part, Entity): |
|
58 |
if last and part.eid == contextentity.eid: |
|
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
59 |
self.w(xml_escape(part.view('breadcrumbtext'))) |
0 | 60 |
else: |
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
61 |
self.w(part.view('breadcrumbs')) |
0 | 62 |
elif isinstance(part, tuple): |
63 |
url, title = part |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
64 |
textsize = self._cw.property_value('navigation.short-line-size') |
0 | 65 |
self.w(u'<a href="%s">%s</a>' % ( |
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
66 |
xml_escape(url), xml_escape(uilib.cut(title, textsize)))) |
0 | 67 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
68 |
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
|
69 |
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
|
70 |
|
0 | 71 |
|
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
|
72 |
class BreadCrumbETypeVComponent(BreadCrumbEntityVComponent): |
3523
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
73 |
__select__ = two_lines_rset() & one_etype_rset() & \ |
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
74 |
implements(IBreadCrumbs, accept_none=False) |
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
|
75 |
|
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
|
76 |
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
|
77 |
# 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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
else: |
3030
e086df78e267
B [views] fixing breadcrumbs
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3015
diff
changeset
|
83 |
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
|
84 |
|
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
|
85 |
|
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
|
86 |
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
|
87 |
__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
|
88 |
|
3015
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
if first_separator: |
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
92 |
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
|
93 |
self.w(self._cw._('search')) |
3015
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
94 |
self.w(u'</span>') |
0 | 95 |
|
96 |
||
97 |
class BreadCrumbView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
98 |
__regid__ = 'breadcrumbs' |
0 | 99 |
|
100 |
def cell_call(self, row, col): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
# 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
|
104 |
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
|
105 |
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
|
106 |
|
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
107 |
|
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
108 |
class BreadCrumbTextView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
109 |
__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
|
110 |
|
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
111 |
def cell_call(self, row, col): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
self.w(uilib.cut(entity.dc_title(), textsize)) |