author | sylvain.thenault@logilab.fr |
Thu, 09 Apr 2009 12:40:30 +0200 | |
branch | tls-sprint |
changeset 1314 | dc5499bff1a9 |
parent 824 | a5e6acffde30 |
child 1653 | 8b82227719f0 |
permissions | -rw-r--r-- |
0 | 1 |
"""xbel views |
2 |
||
3 |
:organization: Logilab |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
731
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" |
|
8 |
_ = unicode |
|
9 |
||
10 |
from logilab.mtconverter import html_escape |
|
11 |
||
731
ac4a94e50b60
some more s/__selectors__/__select__ but still more to come
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
12 |
from cubicweb.selectors import implements |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
731
diff
changeset
|
13 |
from cubicweb.view import EntityView |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
731
diff
changeset
|
14 |
from cubicweb.web.views.xmlrss import XmlView |
0 | 15 |
|
16 |
||
17 |
class XbelView(XmlView): |
|
18 |
id = 'xbel' |
|
19 |
title = _('xbel') |
|
20 |
templatable = False |
|
21 |
content_type = 'text/xml' #application/xbel+xml |
|
22 |
||
23 |
def cell_call(self, row, col): |
|
24 |
self.wview('xbelitem', self.rset, row=row, col=col) |
|
25 |
||
26 |
def call(self): |
|
27 |
"""display a list of entities by calling their <item_vid> view""" |
|
28 |
title = self.page_title() |
|
29 |
url = self.build_url(rql=self.req.form.get('rql', '')) |
|
30 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
|
31 |
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">') |
|
32 |
self.w(u'<xbel version="1.0">') |
|
33 |
self.w(u'<title>%s</title>' % self.req._('bookmarks')) |
|
34 |
for i in xrange(self.rset.rowcount): |
|
35 |
self.cell_call(i, 0) |
|
36 |
self.w(u"</xbel>") |
|
37 |
||
38 |
||
39 |
class XbelItemView(EntityView): |
|
40 |
id = 'xbelitem' |
|
41 |
||
42 |
def cell_call(self, row, col): |
|
43 |
entity = self.complete_entity(row, col) |
|
44 |
self.w(u'<bookmark href="%s">' % html_escape(self.url(entity))) |
|
45 |
self.w(u' <title>%s</title>' % html_escape(entity.dc_title())) |
|
46 |
self.w(u'</bookmark>') |
|
47 |
||
48 |
def url(self, entity): |
|
49 |
return entity.absolute_url() |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
731
diff
changeset
|
50 |
|
0 | 51 |
|
52 |
class XbelItemBookmarkView(XbelItemView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
53 |
__select__ = implements('Bookmark') |
0 | 54 |
|
55 |
def url(self, entity): |
|
56 |
return entity.actual_url() |
|
57 |