author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 18 Aug 2009 09:25:26 +0200 | |
changeset 2901 | 8f4d495c94c2 |
parent 2789 | 39712da6f397 |
child 3023 | 7864fee8b4ec |
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 |
|
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
|
13 |
# don't use AnyEntity since this may cause bug with isinstance() due to reloading |
0 | 14 |
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
|
15 |
from cubicweb.selectors import match_context_prop, one_line_rset, implements |
984 | 16 |
from cubicweb.entity import Entity |
17 |
from cubicweb.view import EntityView |
|
0 | 18 |
from cubicweb.common.uilib import cut |
19 |
from cubicweb.web.component import EntityVComponent |
|
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 |
|
0 | 26 |
|
27 |
class BreadCrumbEntityVComponent(EntityVComponent): |
|
28 |
id = 'breadcrumbs' |
|
29 |
# register msg not generated since no entity implements IPrevNext in cubicweb itself |
|
30 |
title = _('contentnavigation_breadcrumbs') |
|
31 |
help = _('contentnavigation_breadcrumbs_description') |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
731
diff
changeset
|
32 |
__select__ = (one_line_rset() & match_context_prop() & implements(IBreadCrumbs)) |
0 | 33 |
context = 'navtop' |
34 |
order = 5 |
|
35 |
visible = False |
|
36 |
separator = u' > ' |
|
37 |
||
38 |
def call(self, view=None, first_separator=True): |
|
2789
39712da6f397
R propagate deprecation of AppObject.entity()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
39 |
entity = self.rset.get_entity(0,0) |
0 | 40 |
path = entity.breadcrumbs(view) |
41 |
if path: |
|
42 |
self.w(u'<span class="pathbar">') |
|
43 |
if first_separator: |
|
44 |
self.w(self.separator) |
|
45 |
root = path.pop(0) |
|
46 |
if isinstance(root, Entity): |
|
47 |
self.w(u'<a href="%s">%s</a>' % (self.req.build_url(root.id), |
|
48 |
root.dc_type('plural'))) |
|
49 |
self.w(self.separator) |
|
50 |
self.wpath_part(root, entity, not path) |
|
51 |
for i, parent in enumerate(path): |
|
52 |
self.w(self.separator) |
|
53 |
self.w(u"\n") |
|
54 |
self.wpath_part(parent, entity, i == len(path) - 1) |
|
55 |
self.w(u'</span>') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
984
diff
changeset
|
56 |
|
0 | 57 |
def wpath_part(self, part, contextentity, last=False): |
58 |
if isinstance(part, Entity): |
|
59 |
if last and part.eid == contextentity.eid: |
|
60 |
self.w(bc_title(part)) |
|
61 |
else: |
|
62 |
part.view('breadcrumbs', w=self.w) |
|
63 |
elif isinstance(part, tuple): |
|
64 |
url, title = part |
|
65 |
textsize = self.req.property_value('navigation.short-line-size') |
|
66 |
self.w(u'<a href="%s">%s</a>' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
67 |
xml_escape(url), xml_escape(cut(title, textsize)))) |
0 | 68 |
else: |
69 |
textsize = self.req.property_value('navigation.short-line-size') |
|
70 |
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
|
71 |
|
0 | 72 |
|
73 |
class BreadCrumbComponent(BreadCrumbEntityVComponent): |
|
74 |
__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
|
75 |
__select__ = (one_line_rset() & implements(IBreadCrumbs)) |
0 | 76 |
visible = True |
77 |
||
78 |
||
79 |
class BreadCrumbView(EntityView): |
|
80 |
id = 'breadcrumbs' |
|
81 |
||
82 |
def cell_call(self, row, col): |
|
2789
39712da6f397
R propagate deprecation of AppObject.entity()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
83 |
entity = self.rset.get_entity(row, col) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
84 |
desc = xml_escape(cut(entity.dc_description(), 50)) |
1882 | 85 |
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
|
86 |
xml_escape(entity.absolute_url()), desc, bc_title(entity))) |