|
1 """xbel views |
|
2 |
|
3 :organization: Logilab |
|
4 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
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 |
|
12 from cubicweb.web.views.baseviews import XmlView, EntityView |
|
13 |
|
14 |
|
15 class XbelView(XmlView): |
|
16 id = 'xbel' |
|
17 title = _('xbel') |
|
18 templatable = False |
|
19 content_type = 'text/xml' #application/xbel+xml |
|
20 |
|
21 def cell_call(self, row, col): |
|
22 self.wview('xbelitem', self.rset, row=row, col=col) |
|
23 |
|
24 def call(self): |
|
25 """display a list of entities by calling their <item_vid> view""" |
|
26 title = self.page_title() |
|
27 url = self.build_url(rql=self.req.form.get('rql', '')) |
|
28 self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
|
29 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">') |
|
30 self.w(u'<xbel version="1.0">') |
|
31 self.w(u'<title>%s</title>' % self.req._('bookmarks')) |
|
32 for i in xrange(self.rset.rowcount): |
|
33 self.cell_call(i, 0) |
|
34 self.w(u"</xbel>") |
|
35 |
|
36 |
|
37 class XbelItemView(EntityView): |
|
38 id = 'xbelitem' |
|
39 |
|
40 def cell_call(self, row, col): |
|
41 entity = self.complete_entity(row, col) |
|
42 self.w(u'<bookmark href="%s">' % html_escape(self.url(entity))) |
|
43 self.w(u' <title>%s</title>' % html_escape(entity.dc_title())) |
|
44 self.w(u'</bookmark>') |
|
45 |
|
46 def url(self, entity): |
|
47 return entity.absolute_url() |
|
48 |
|
49 class XbelItemBookmarkView(XbelItemView): |
|
50 accepts = ('Bookmark',) |
|
51 |
|
52 def url(self, entity): |
|
53 return entity.actual_url() |
|
54 |