author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 27 May 2009 11:19:37 +0200 | |
branch | stable |
changeset 1951 | f28e7f300d3f |
parent 1882 | ce662160bb46 |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
"""navigation components definition for CubicWeb web client |
2 |
||
3 |
:organization: Logilab |
|
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
431
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
""" |
|
7 |
__docformat__ = "restructuredtext en" |
|
1882 | 8 |
_ = unicode |
0 | 9 |
|
10 |
from logilab.mtconverter import html_escape |
|
11 |
||
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
|
12 |
# don't use AnyEntity since this may cause bug with isinstance() due to reloading |
0 | 13 |
from cubicweb.interfaces import IBreadCrumbs |
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
431
diff
changeset
|
14 |
from cubicweb.selectors import match_context_prop, one_line_rset, implements |
984 | 15 |
from cubicweb.entity import Entity |
16 |
from cubicweb.view import EntityView |
|
0 | 17 |
from cubicweb.common.uilib import cut |
18 |
from cubicweb.web.component import EntityVComponent |
|
19 |
||
20 |
||
21 |
def bc_title(entity): |
|
22 |
textsize = entity.req.property_value('navigation.short-line-size') |
|
23 |
return html_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
|
24 |
|
0 | 25 |
|
26 |
class BreadCrumbEntityVComponent(EntityVComponent): |
|
27 |
id = 'breadcrumbs' |
|
28 |
# register msg not generated since no entity implements IPrevNext in cubicweb itself |
|
29 |
title = _('contentnavigation_breadcrumbs') |
|
30 |
help = _('contentnavigation_breadcrumbs_description') |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
731
diff
changeset
|
31 |
__select__ = (one_line_rset() & match_context_prop() & implements(IBreadCrumbs)) |
0 | 32 |
context = 'navtop' |
33 |
order = 5 |
|
34 |
visible = False |
|
35 |
separator = u' > ' |
|
36 |
||
37 |
def call(self, view=None, first_separator=True): |
|
38 |
entity = self.entity(0) |
|
39 |
path = entity.breadcrumbs(view) |
|
40 |
if path: |
|
41 |
self.w(u'<span class="pathbar">') |
|
42 |
if first_separator: |
|
43 |
self.w(self.separator) |
|
44 |
root = path.pop(0) |
|
45 |
if isinstance(root, Entity): |
|
46 |
self.w(u'<a href="%s">%s</a>' % (self.req.build_url(root.id), |
|
47 |
root.dc_type('plural'))) |
|
48 |
self.w(self.separator) |
|
49 |
self.wpath_part(root, entity, not path) |
|
50 |
for i, parent in enumerate(path): |
|
51 |
self.w(self.separator) |
|
52 |
self.w(u"\n") |
|
53 |
self.wpath_part(parent, entity, i == len(path) - 1) |
|
54 |
self.w(u'</span>') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
984
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: |
|
59 |
self.w(bc_title(part)) |
|
60 |
else: |
|
61 |
part.view('breadcrumbs', w=self.w) |
|
62 |
elif isinstance(part, tuple): |
|
63 |
url, title = part |
|
64 |
textsize = self.req.property_value('navigation.short-line-size') |
|
65 |
self.w(u'<a href="%s">%s</a>' % ( |
|
66 |
html_escape(url), html_escape(cut(title, textsize)))) |
|
67 |
else: |
|
68 |
textsize = self.req.property_value('navigation.short-line-size') |
|
69 |
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
|
70 |
|
0 | 71 |
|
72 |
class BreadCrumbComponent(BreadCrumbEntityVComponent): |
|
73 |
__registry__ = 'components' |
|
731
ac4a94e50b60
some more s/__selectors__/__select__ but still more to come
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
713
diff
changeset
|
74 |
__select__ = (one_line_rset() & implements(IBreadCrumbs)) |
0 | 75 |
visible = True |
76 |
||
77 |
||
78 |
class BreadCrumbView(EntityView): |
|
79 |
id = 'breadcrumbs' |
|
80 |
||
81 |
def cell_call(self, row, col): |
|
82 |
entity = self.entity(row, col) |
|
1882 | 83 |
desc = html_escape(cut(entity.dc_description(), 50)) |
84 |
self.w(u'<a href="%s" title="%s">%s</a>' % ( |
|
85 |
html_escape(entity.absolute_url()), desc, bc_title(entity))) |