1547
|
1 |
"""Specific views for SIOC interfaces |
|
2 |
|
|
3 |
:organization: Logilab |
|
4 |
:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 |
""" |
|
7 |
__docformat__ = "restructuredtext en" |
|
8 |
|
|
9 |
from logilab.mtconverter import html_escape |
|
10 |
|
|
11 |
from cubicweb.view import EntityView |
|
12 |
from cubicweb.selectors import implements |
|
13 |
from cubicweb.interfaces import ISiocItem, ISiocContainer |
|
14 |
|
|
15 |
class SIOCView(EntityView): |
|
16 |
id = 'sioc' |
|
17 |
__select__ = EntityView.__select__ & implements(ISiocItem, ISiocContainer) |
|
18 |
title = _('sioc') |
|
19 |
templatable = False |
|
20 |
content_type = 'text/xml' |
|
21 |
|
|
22 |
def call(self): |
|
23 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
|
24 |
self.w(u'''<rdf:RDF |
|
25 |
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
|
26 |
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" |
|
27 |
xmlns:owl="http://www.w3.org/2002/07/owl#" |
|
28 |
xmlns:foaf="http://xmlns.com/foaf/0.1/" |
|
29 |
xmlns:sioc="http://rdfs.org/sioc/ns#" |
|
30 |
xmlns:sioctype="http://rdfs.org/sioc/types#" |
|
31 |
xmlns:dcterms="http://purl.org/dc/terms/">\n''') |
|
32 |
for i in xrange(self.rset.rowcount): |
|
33 |
self.cell_call(i, 0) |
|
34 |
self.w(u'</rdf:RDF>\n') |
|
35 |
|
|
36 |
def cell_call(self, row, col): |
|
37 |
self.wview('sioc_element', self.rset, row=row, col=col) |
|
38 |
|
|
39 |
class SIOCContainerView(EntityView): |
|
40 |
id = 'sioc_element' |
|
41 |
__select__ = EntityView.__select__ & implements(ISiocContainer) |
|
42 |
templatable = False |
|
43 |
content_type = 'text/xml' |
|
44 |
|
|
45 |
def cell_call(self, row, col): |
|
46 |
entity = self.complete_entity(row, col) |
|
47 |
self.w(u'<sioc:%s rdf:about="%s">\n' % (html_escape(entity.isioc_type()), |
|
48 |
html_escape(entity.absolute_url()))) |
|
49 |
self.w(u'<dcterms:title>%s</dcterms:title>' % html_escape(entity.dc_title())) |
|
50 |
self.w(u'<dcterms:created>%s</dcterms:created>' % entity.creation_date) |
|
51 |
self.w(u'<dcterms:modified>%s</dcterms:modified>' % entity.modification_date) |
|
52 |
self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items() |
|
53 |
self.w(u'</sioc:%s>\n' % entity.isioc_type()) |
|
54 |
|
|
55 |
|
|
56 |
class SIOCItemView(EntityView): |
|
57 |
id = 'sioc_element' |
|
58 |
__select__ = EntityView.__select__ & implements(ISiocItem) |
|
59 |
templatable = False |
|
60 |
content_type = 'text/xml' |
|
61 |
|
|
62 |
def cell_call(self, row, col): |
|
63 |
entity = self.complete_entity(row, col) |
|
64 |
self.w(u'<sioc:%s rdf:about="%s">\n' % (html_escape(entity.isioc_type()), |
|
65 |
html_escape(entity.absolute_url()))) |
|
66 |
self.w(u'<dcterms:title>%s</dcterms:title>' % html_escape(entity.dc_title())) |
|
67 |
self.w(u'<dcterms:created>%s</dcterms:created>' % entity.creation_date) |
|
68 |
self.w(u'<dcterms:modified>%s</dcterms:modified>' % entity.modification_date) |
|
69 |
if entity.content: |
|
70 |
self.w(u'<sioc:content>%s</sioc:content>''' % html_escape(entity.isioc_content())) |
|
71 |
if entity.related('entry_of'): |
|
72 |
self.w(u'<sioc:has_container rdf:resource="%s"/>\n' % html_escape(entity.isioc_container().absolute_url())) |
|
73 |
if entity.creator: |
|
74 |
self.w(u'<sioc:has_creator>\n') |
|
75 |
self.w(u'<sioc:User rdf:about="%s">\n' % html_escape(entity.creator.absolute_url())) |
|
76 |
self.w(entity.creator.view('foaf')) |
|
77 |
self.w(u'</sioc:User>\n') |
|
78 |
self.w(u'</sioc:has_creator>\n') |
|
79 |
self.w(u'<!-- FIXME : here be topics -->')#entity.isioc_topics() |
|
80 |
self.w(u'<!-- FIXME : here be replies -->')#entity.isioc_replies() |
|
81 |
self.w(u' </sioc:%s>\n' % 'Post') |
|
82 |
|