author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 23 Jul 2009 15:28:41 +0200 | |
changeset 2456 | aa25d6b244c8 |
parent 2312 | af4d8f75c5db |
child 3377 | dd9d292b6a6d |
child 4212 | ab6573088b4a |
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 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
10 |
from logilab.mtconverter import xml_escape |
1547 | 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) |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
48 |
sioct = xml_escape(entity.isioc_type()) |
1656 | 49 |
self.w(u'<sioc:%s rdf:about="%s">\n' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
50 |
% (sioct, xml_escape(entity.absolute_url()))) |
1656 | 51 |
self.w(u'<dcterms:title>%s</dcterms:title>' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
52 |
% xml_escape(entity.dc_title())) |
1656 | 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) |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
69 |
sioct = xml_escape(entity.isioc_type()) |
1656 | 70 |
self.w(u'<sioc:%s rdf:about="%s">\n' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
71 |
% (sioct, xml_escape(entity.absolute_url()))) |
1656 | 72 |
self.w(u'<dcterms:title>%s</dcterms:title>' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
73 |
% xml_escape(entity.dc_title())) |
1656 | 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>''' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
80 |
% xml_escape(entity.isioc_content())) |
1547 | 81 |
if entity.related('entry_of'): |
1656 | 82 |
self.w(u'<sioc:has_container rdf:resource="%s"/>\n' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
83 |
% xml_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' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
87 |
% xml_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 |