author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Fri, 29 May 2009 21:34:09 +0200 | |
changeset 2015 | 3009899e1e51 |
parent 1977 | 606923dff11b |
child 2312 | af4d8f75c5db |
permissions | -rw-r--r-- |
0 | 1 |
"""xbel views |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1653
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:
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 |
||
11 |
from logilab.mtconverter import html_escape |
|
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): |
0 | 19 |
id = 'xbel' |
20 |
title = _('xbel') |
|
21 |
templatable = False |
|
1653 | 22 |
content_type = 'text/xml' #application/xbel+xml |
23 |
||
0 | 24 |
def cell_call(self, row, col): |
25 |
self.wview('xbelitem', self.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() |
|
30 |
url = self.build_url(rql=self.req.form.get('rql', '')) |
|
31 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
|
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">') |
|
34 |
self.w(u'<title>%s</title>' % self.req._('bookmarks')) |
|
35 |
for i in xrange(self.rset.rowcount): |
|
36 |
self.cell_call(i, 0) |
|
37 |
self.w(u"</xbel>") |
|
1653 | 38 |
|
0 | 39 |
|
40 |
class XbelItemView(EntityView): |
|
41 |
id = 'xbelitem' |
|
42 |
||
43 |
def cell_call(self, row, col): |
|
44 |
entity = self.complete_entity(row, col) |
|
45 |
self.w(u'<bookmark href="%s">' % html_escape(self.url(entity))) |
|
46 |
self.w(u' <title>%s</title>' % html_escape(entity.dc_title())) |
|
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 |