author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 26 Mar 2010 08:32:32 +0100 | |
branch | stable |
changeset 5032 | e3fa27fc0d9a |
parent 4719 | aaed3f813ef8 |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
0 | 1 |
"""xbel views |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2312
diff
changeset
|
4 |
:copyright: 2001-2010 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:
1653
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
_ = unicode |
|
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 |
|
731
ac4a94e50b60
some more s/__selectors__/__select__ but still more to come
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
13 |
from cubicweb.selectors import implements |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
731
diff
changeset
|
14 |
from cubicweb.view import EntityView |
1653 | 15 |
from cubicweb.web.views.xmlrss import XMLView |
0 | 16 |
|
17 |
||
1653 | 18 |
class XbelView(XMLView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
19 |
__regid__ = 'xbel' |
0 | 20 |
title = _('xbel') |
21 |
templatable = False |
|
1653 | 22 |
content_type = 'text/xml' #application/xbel+xml |
23 |
||
0 | 24 |
def cell_call(self, row, col): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
25 |
self.wview('xbelitem', self.cw_rset, row=row, col=col) |
1653 | 26 |
|
0 | 27 |
def call(self): |
28 |
"""display a list of entities by calling their <item_vid> view""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
29 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding) |
0 | 30 |
self.w(u'<!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML" "http://www.python.org/topics/xml/dtds/xbel-1.0.dtd">') |
31 |
self.w(u'<xbel version="1.0">') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
32 |
self.w(u'<title>%s</title>' % self._cw._('bookmarks')) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
33 |
for i in xrange(self.cw_rset.rowcount): |
0 | 34 |
self.cell_call(i, 0) |
35 |
self.w(u"</xbel>") |
|
1653 | 36 |
|
0 | 37 |
|
38 |
class XbelItemView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
39 |
__regid__ = 'xbelitem' |
0 | 40 |
|
41 |
def cell_call(self, row, col): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
42 |
entity = self.cw_rset.complete_entity(row, col) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
43 |
self.w(u'<bookmark href="%s">' % xml_escape(self.url(entity))) |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
44 |
self.w(u' <title>%s</title>' % xml_escape(entity.dc_title())) |
0 | 45 |
self.w(u'</bookmark>') |
46 |
||
47 |
def url(self, entity): |
|
48 |
return entity.absolute_url() |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
731
diff
changeset
|
49 |
|
1653 | 50 |
|
0 | 51 |
class XbelItemBookmarkView(XbelItemView): |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
52 |
__select__ = implements('Bookmark') |
0 | 53 |
|
54 |
def url(self, entity): |
|
55 |
return entity.actual_url() |
|
1653 | 56 |