author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Tue, 22 Dec 2009 10:42:51 +0100 | |
branch | stable |
changeset 4175 | 92a10d2a09af |
parent 3862 | 4908c7156eab |
child 3890 | d7a270f50f54 |
child 4212 | ab6573088b4a |
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): |
0 | 23 |
id = '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 |
|
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
|
26 |
property_defs = { |
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' > ' |
3862
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
33 |
link_template = u'<a href="%s">%s</a>' |
0 | 34 |
|
35 |
def call(self, view=None, first_separator=True): |
|
3179
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
36 |
entity = self.rset.get_entity(0, 0) |
0 | 37 |
path = entity.breadcrumbs(view) |
38 |
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
|
39 |
self.open_breadcrumbs() |
0 | 40 |
if first_separator: |
41 |
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
|
42 |
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
|
43 |
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
|
44 |
|
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
|
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
48 |
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
|
49 |
self.w(u'</span>') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
984
diff
changeset
|
50 |
|
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
|
51 |
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
|
52 |
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
|
53 |
if isinstance(root, Entity): |
3862
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
54 |
self.w(self.link_template % (self.req.build_url(root.id), |
4908c7156eab
[breadcrumbs] make it easier to redefine html structure of breadcrumbs component
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3523
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
|
0 | 63 |
def wpath_part(self, part, contextentity, last=False): |
64 |
if isinstance(part, Entity): |
|
65 |
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
|
66 |
self.w(xml_escape(part.view('breadcrumbtext'))) |
0 | 67 |
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
|
68 |
self.w(part.view('breadcrumbs')) |
0 | 69 |
elif isinstance(part, tuple): |
70 |
url, title = part |
|
71 |
textsize = self.req.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
|
72 |
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
|
73 |
xml_escape(url), xml_escape(uilib.cut(title, textsize)))) |
0 | 74 |
else: |
75 |
textsize = self.req.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
|
76 |
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
|
77 |
|
0 | 78 |
|
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
|
79 |
class BreadCrumbETypeVComponent(BreadCrumbEntityVComponent): |
3523
16880e7ee3fa
don't accept None to avoid error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3184
diff
changeset
|
80 |
__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
|
81 |
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
|
82 |
|
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
|
83 |
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
|
84 |
# 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
|
85 |
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
|
86 |
if isinstance(root, Entity): |
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 |
self.w(u'<a href="%s">%s</a>' % (self.req.build_url(root.id), |
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 |
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
|
89 |
else: |
3030
e086df78e267
B [views] fixing breadcrumbs
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3015
diff
changeset
|
90 |
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
|
91 |
|
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
|
92 |
|
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 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
|
94 |
__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
|
95 |
|
3015
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
96 |
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
|
97 |
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
|
98 |
if first_separator: |
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
99 |
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
|
100 |
self.w(self.req._('search')) |
3015
0588e39f6743
[breadcrumb] BreadCrumbAnyRSetVComponent should implements call()
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3007
diff
changeset
|
101 |
self.w(u'</span>') |
0 | 102 |
|
103 |
||
104 |
class BreadCrumbView(EntityView): |
|
105 |
id = 'breadcrumbs' |
|
106 |
||
107 |
def cell_call(self, 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
|
108 |
entity = self.rset.get_entity(row, col) |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
109 |
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
|
110 |
# 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
|
111 |
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
|
112 |
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
|
113 |
|
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
114 |
|
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
115 |
class BreadCrumbTextView(EntityView): |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
116 |
id = 'breadcrumbtext' |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
117 |
|
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
118 |
def cell_call(self, row, col): |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
119 |
entity = self.rset.get_entity(row, col) |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
120 |
textsize = self.req.property_value('navigation.short-line-size') |
0684544f6d0d
from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3030
diff
changeset
|
121 |
self.w(uilib.cut(entity.dc_title(), textsize)) |