author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 26 Aug 2009 10:06:17 +0200 | |
branch | stable |
changeset 3007 | a15e982aa9a3 |
parent 2996 | 866a2c135c33 |
child 3015 | 0588e39f6743 |
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 |
0 | 19 |
from cubicweb.common.uilib import cut |
20 |
||
21 |
||
22 |
def bc_title(entity): |
|
23 |
textsize = entity.req.property_value('navigation.short-line-size') |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
24 |
return xml_escape(cut(entity.dc_title(), textsize)) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
984
diff
changeset
|
25 |
|
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
|
26 |
# XXX only provides the component version |
0 | 27 |
|
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
|
28 |
class BreadCrumbEntityVComponent(Component): |
0 | 29 |
id = 'breadcrumbs' |
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
|
30 |
__select__ = one_line_rset() & implements(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
|
31 |
|
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
|
32 |
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
|
33 |
_('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
|
34 |
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
|
35 |
} |
0 | 36 |
title = _('contentnavigation_breadcrumbs') |
37 |
help = _('contentnavigation_breadcrumbs_description') |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
38 |
separator = u' > ' |
0 | 39 |
|
40 |
def call(self, view=None, first_separator=True): |
|
41 |
entity = self.entity(0) |
|
42 |
path = entity.breadcrumbs(view) |
|
43 |
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
|
44 |
self.w(u'<span id="breadcrumbs" class="pathbar">') |
0 | 45 |
if first_separator: |
46 |
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
|
47 |
self.render_breadcrumbs(entity, path) |
0 | 48 |
self.w(u'</span>') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
984
diff
changeset
|
49 |
|
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
|
0 | 62 |
def wpath_part(self, part, contextentity, last=False): |
63 |
if isinstance(part, Entity): |
|
64 |
if last and part.eid == contextentity.eid: |
|
65 |
self.w(bc_title(part)) |
|
66 |
else: |
|
67 |
part.view('breadcrumbs', w=self.w) |
|
68 |
elif isinstance(part, tuple): |
|
69 |
url, title = part |
|
70 |
textsize = self.req.property_value('navigation.short-line-size') |
|
71 |
self.w(u'<a href="%s">%s</a>' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
72 |
xml_escape(url), xml_escape(cut(title, textsize)))) |
0 | 73 |
else: |
74 |
textsize = self.req.property_value('navigation.short-line-size') |
|
75 |
self.w(cut(unicode(part), textsize)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
984
diff
changeset
|
76 |
|
0 | 77 |
|
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
|
78 |
class BreadCrumbETypeVComponent(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
|
79 |
__select__ = two_lines_rset() & one_etype_rset() & implements(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
|
80 |
|
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 |
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
|
82 |
# 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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
else: |
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 |
self.wpath_part(root, entity, 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
|
89 |
|
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
|
90 |
|
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 |
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
|
92 |
__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
|
93 |
|
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 |
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
|
95 |
self.w(self.req._('search')) |
0 | 96 |
|
97 |
||
98 |
class BreadCrumbView(EntityView): |
|
99 |
id = 'breadcrumbs' |
|
100 |
||
101 |
def cell_call(self, row, col): |
|
102 |
entity = self.entity(row, col) |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
103 |
desc = xml_escape(cut(entity.dc_description(), 50)) |
1882 | 104 |
self.w(u'<a href="%s" title="%s">%s</a>' % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
105 |
xml_escape(entity.absolute_url()), desc, bc_title(entity))) |