author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 23 Feb 2010 13:19:16 +0100 | |
branch | stable |
changeset 4665 | 873ebd160954 |
parent 4252 | 6c4f109c2b03 |
child 4719 | aaed3f813ef8 |
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""" |
|
29 |
title = self.page_title() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
30 |
url = self._cw.build_url(rql=self._cw.form.get('rql', '')) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
31 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding) |
0 | 32 |
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">') |
33 |
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
|
34 |
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
|
35 |
for i in xrange(self.cw_rset.rowcount): |
0 | 36 |
self.cell_call(i, 0) |
37 |
self.w(u"</xbel>") |
|
1653 | 38 |
|
0 | 39 |
|
40 |
class XbelItemView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
41 |
__regid__ = 'xbelitem' |
0 | 42 |
|
43 |
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
|
44 |
entity = self.cw_rset.complete_entity(row, col) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
45 |
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
|
46 |
self.w(u' <title>%s</title>' % xml_escape(entity.dc_title())) |
0 | 47 |
self.w(u'</bookmark>') |
48 |
||
49 |
def url(self, entity): |
|
50 |
return entity.absolute_url() |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
731
diff
changeset
|
51 |
|
1653 | 52 |
|
0 | 53 |
class XbelItemBookmarkView(XbelItemView): |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
54 |
__select__ = implements('Bookmark') |
0 | 55 |
|
56 |
def url(self, entity): |
|
57 |
return entity.actual_url() |
|
1653 | 58 |