author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 26 Mar 2010 08:32:32 +0100 | |
branch | stable |
changeset 5032 | e3fa27fc0d9a |
parent 4252 | 6c4f109c2b03 |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
1547 | 1 |
"""Specific views for SIOC interfaces |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2312
diff
changeset
|
4 |
:copyright: 2003-2010 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): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
17 |
__regid__ = 'sioc' |
1547 | 18 |
__select__ = EntityView.__select__ & implements(ISiocItem, ISiocContainer) |
19 |
title = _('sioc') |
|
20 |
templatable = False |
|
21 |
content_type = 'text/xml' |
|
22 |
||
23 |
def call(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
24 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding) |
1547 | 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''') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
33 |
for i in xrange(self.cw_rset.rowcount): |
1547 | 34 |
self.cell_call(i, 0) |
35 |
self.w(u'</rdf:RDF>\n') |
|
36 |
||
37 |
def cell_call(self, row, col): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
38 |
self.wview('sioc_element', self.cw_rset, row=row, col=col) |
1547 | 39 |
|
40 |
class SIOCContainerView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
41 |
__regid__ = 'sioc_element' |
1547 | 42 |
__select__ = EntityView.__select__ & implements(ISiocContainer) |
43 |
templatable = False |
|
44 |
content_type = 'text/xml' |
|
45 |
||
46 |
def cell_call(self, row, col): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
47 |
entity = self.cw_rset.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): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
62 |
__regid__ = 'sioc_element' |
1547 | 63 |
__select__ = EntityView.__select__ & implements(ISiocItem) |
64 |
templatable = False |
|
65 |
content_type = 'text/xml' |
|
66 |
||
67 |
def cell_call(self, row, col): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
68 |
entity = self.cw_rset.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 |