author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 18 Jun 2009 09:38:32 +0200 | |
branch | stable |
changeset 2115 | c48ff1d0acc4 |
parent 1977 | 606923dff11b |
child 2312 | af4d8f75c5db |
permissions | -rw-r--r-- |
1547 | 1 |
"""Specific views for SIOC interfaces |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1656
diff
changeset
|
4 |
:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1547 | 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:
1656
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
1547 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
from logilab.mtconverter import html_escape |
|
11 |
||
12 |
from cubicweb.view import EntityView |
|
13 |
from cubicweb.selectors import implements |
|
14 |
from cubicweb.interfaces import ISiocItem, ISiocContainer |
|
15 |
||
16 |
class SIOCView(EntityView): |
|
17 |
id = 'sioc' |
|
18 |
__select__ = EntityView.__select__ & implements(ISiocItem, ISiocContainer) |
|
19 |
title = _('sioc') |
|
20 |
templatable = False |
|
21 |
content_type = 'text/xml' |
|
22 |
||
23 |
def call(self): |
|
24 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
|
25 |
self.w(u'''<rdf:RDF |
|
26 |
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
|
27 |
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" |
|
28 |
xmlns:owl="http://www.w3.org/2002/07/owl#" |
|
29 |
xmlns:foaf="http://xmlns.com/foaf/0.1/" |
|
30 |
xmlns:sioc="http://rdfs.org/sioc/ns#" |
|
31 |
xmlns:sioctype="http://rdfs.org/sioc/types#" |
|
32 |
xmlns:dcterms="http://purl.org/dc/terms/">\n''') |
|
33 |
for i in xrange(self.rset.rowcount): |
|
34 |
self.cell_call(i, 0) |
|
35 |
self.w(u'</rdf:RDF>\n') |
|
36 |
||
37 |
def cell_call(self, row, col): |
|
38 |
self.wview('sioc_element', self.rset, row=row, col=col) |
|
39 |
||
40 |
class SIOCContainerView(EntityView): |
|
41 |
id = 'sioc_element' |
|
42 |
__select__ = EntityView.__select__ & implements(ISiocContainer) |
|
43 |
templatable = False |
|
44 |
content_type = 'text/xml' |
|
45 |
||
46 |
def cell_call(self, row, col): |
|
47 |
entity = self.complete_entity(row, col) |
|
1656 | 48 |
sioct = html_escape(entity.isioc_type()) |
49 |
self.w(u'<sioc:%s rdf:about="%s">\n' |
|
50 |
% (sioct, html_escape(entity.absolute_url()))) |
|
51 |
self.w(u'<dcterms:title>%s</dcterms:title>' |
|
52 |
% html_escape(entity.dc_title())) |
|
53 |
self.w(u'<dcterms:created>%s</dcterms:created>' |
|
54 |
% entity.creation_date) |
|
55 |
self.w(u'<dcterms:modified>%s</dcterms:modified>' |
|
56 |
% entity.modification_date) |
|
1547 | 57 |
self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items() |
1656 | 58 |
self.w(u'</sioc:%s>\n' % sioct) |
1547 | 59 |
|
60 |
||
61 |
class SIOCItemView(EntityView): |
|
62 |
id = 'sioc_element' |
|
63 |
__select__ = EntityView.__select__ & implements(ISiocItem) |
|
64 |
templatable = False |
|
65 |
content_type = 'text/xml' |
|
66 |
||
67 |
def cell_call(self, row, col): |
|
68 |
entity = self.complete_entity(row, col) |
|
1656 | 69 |
sioct = html_escape(entity.isioc_type()) |
70 |
self.w(u'<sioc:%s rdf:about="%s">\n' |
|
71 |
% (sioct, html_escape(entity.absolute_url()))) |
|
72 |
self.w(u'<dcterms:title>%s</dcterms:title>' |
|
73 |
% html_escape(entity.dc_title())) |
|
74 |
self.w(u'<dcterms:created>%s</dcterms:created>' |
|
75 |
% entity.creation_date) |
|
76 |
self.w(u'<dcterms:modified>%s</dcterms:modified>' |
|
77 |
% entity.modification_date) |
|
1547 | 78 |
if entity.content: |
1656 | 79 |
self.w(u'<sioc:content>%s</sioc:content>''' |
80 |
% html_escape(entity.isioc_content())) |
|
1547 | 81 |
if entity.related('entry_of'): |
1656 | 82 |
self.w(u'<sioc:has_container rdf:resource="%s"/>\n' |
83 |
% html_escape(entity.isioc_container().absolute_url())) |
|
1547 | 84 |
if entity.creator: |
85 |
self.w(u'<sioc:has_creator>\n') |
|
1656 | 86 |
self.w(u'<sioc:User rdf:about="%s">\n' |
87 |
% html_escape(entity.creator.absolute_url())) |
|
1547 | 88 |
self.w(entity.creator.view('foaf')) |
89 |
self.w(u'</sioc:User>\n') |
|
90 |
self.w(u'</sioc:has_creator>\n') |
|
91 |
self.w(u'<!-- FIXME : here be topics -->')#entity.isioc_topics() |
|
92 |
self.w(u'<!-- FIXME : here be replies -->')#entity.isioc_replies() |
|
1656 | 93 |
self.w(u' </sioc:%s>\n' % sioct) |
1547 | 94 |