web/views/isioc.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 02 Jun 2010 15:29:18 +0200
changeset 5633 879590c52679
parent 5569 cb14af012a96
child 5895 6a3f776292a5
permissions -rw-r--r--
backport stable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    18
"""Specific views for SIOC (Semantically-Interlinked Online Communities)
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    20
http://sioc-project.org
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
"""
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    22
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
__docformat__ = "restructuredtext en"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    25
from logilab.mtconverter import xml_escape
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    27
from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    28
from cubicweb.selectors import implements, adaptable
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
from cubicweb.interfaces import ISiocItem, ISiocContainer
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    31
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    32
class ISIOCItemAdapter(EntityAdapter):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    33
    """interface for entities which may be represented as an ISIOC items"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    34
    __regid__ = 'ISIOCItem'
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    35
    __select__ = implements(ISiocItem) # XXX for bw compat, should be abstract
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    36
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    37
    @implements_adapter_compat('ISIOCItem')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    38
    def isioc_content(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    39
        """return item's content"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    40
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    41
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    42
    @implements_adapter_compat('ISIOCItem')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    43
    def isioc_container(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    44
        """return container entity"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    45
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    46
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    47
    @implements_adapter_compat('ISIOCItem')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    48
    def isioc_type(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    49
        """return container type (post, BlogPost, MailMessage)"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    50
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    51
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    52
    @implements_adapter_compat('ISIOCItem')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    53
    def isioc_replies(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    54
        """return replies items"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    55
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    56
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    57
    @implements_adapter_compat('ISIOCItem')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    58
    def isioc_topics(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    59
        """return topics items"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    60
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    61
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    62
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    63
class ISIOCContainerAdapter(EntityAdapter):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    64
    """interface for entities which may be represented as an ISIOC container"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    65
    __regid__ = 'ISIOCContainer'
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    66
    __select__ = implements(ISiocContainer) # XXX for bw compat, should be abstract
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    67
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    68
    @implements_adapter_compat('ISIOCContainer')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    69
    def isioc_type(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    70
        """return container type (forum, Weblog, MailingList)"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    71
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    72
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    73
    @implements_adapter_compat('ISIOCContainer')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    74
    def isioc_items(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    75
        """return contained items"""
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    76
        raise NotImplementedError
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    77
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    78
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
class SIOCView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
    80
    __regid__ = 'sioc'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    81
    __select__ = adaptable('ISIOCItem', 'ISIOCContainer')
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
    title = _('sioc')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
    templatable = False
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
    content_type = 'text/xml'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    85
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    86
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    87
        self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding)
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    88
        self.w(u'''<rdf:RDF
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    89
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    90
             xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    91
             xmlns:owl="http://www.w3.org/2002/07/owl#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    92
             xmlns:foaf="http://xmlns.com/foaf/0.1/"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    93
             xmlns:sioc="http://rdfs.org/sioc/ns#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    94
             xmlns:sioctype="http://rdfs.org/sioc/types#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    95
             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
    96
        for i in xrange(self.cw_rset.rowcount):
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    97
            self.cell_call(i, 0)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    98
        self.w(u'</rdf:RDF>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    99
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   100
    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
   101
        self.wview('sioc_element', self.cw_rset, row=row, col=col)
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   102
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   103
class SIOCContainerView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   104
    __regid__ = 'sioc_element'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   105
    __select__ = adaptable('ISIOCContainer')
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   106
    templatable = False
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   107
    content_type = 'text/xml'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   108
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   109
    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
   110
        entity = self.cw_rset.complete_entity(row, col)
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   111
        isioc = entity.cw_adapt_to('ISIOCContainer')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   112
        isioct = isioc.isioc_type()
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   113
        self.w(u'<sioc:%s rdf:about="%s">\n'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   114
               % (isioct, xml_escape(entity.absolute_url())))
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   115
        self.w(u'<dcterms:title>%s</dcterms:title>'
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   116
               % xml_escape(entity.dc_title()))
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   117
        self.w(u'<dcterms:created>%s</dcterms:created>'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   118
               % entity.creation_date) # XXX format
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   119
        self.w(u'<dcterms:modified>%s</dcterms:modified>'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   120
               % entity.modification_date) # XXX format
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   121
        self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items()
5569
cb14af012a96 [adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   122
        self.w(u'</sioc:%s>\n' % isioct)
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   123
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   124
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   125
class SIOCItemView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
   126
    __regid__ = 'sioc_element'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   127
    __select__ = adaptable('ISIOCItem')
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   128
    templatable = False
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   129
    content_type = 'text/xml'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   130
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   131
    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
   132
        entity = self.cw_rset.complete_entity(row, col)
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   133
        isioc = entity.cw_adapt_to('ISIOCItem')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   134
        isioct = isioc.isioc_type()
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   135
        self.w(u'<sioc:%s rdf:about="%s">\n'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   136
               % (isioct, xml_escape(entity.absolute_url())))
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   137
        self.w(u'<dcterms:title>%s</dcterms:title>'
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   138
               % xml_escape(entity.dc_title()))
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   139
        self.w(u'<dcterms:created>%s</dcterms:created>'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   140
               % entity.creation_date) # XXX format
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   141
        self.w(u'<dcterms:modified>%s</dcterms:modified>'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   142
               % entity.modification_date) # XXX format
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   143
        content = isioc.isioc_content()
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   144
        if content:
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   145
            self.w(u'<sioc:content>%s</sioc:content>' % xml_escape(content))
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   146
        container = isioc.isioc_container()
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   147
        if container:
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   148
            self.w(u'<sioc:has_container rdf:resource="%s"/>\n'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   149
                   % xml_escape(container.absolute_url()))
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   150
        if entity.creator:
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   151
            self.w(u'<sioc:has_creator>\n')
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
   152
            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
   153
                   % xml_escape(entity.creator.absolute_url()))
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   154
            self.w(entity.creator.view('foaf'))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   155
            self.w(u'</sioc:User>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   156
            self.w(u'</sioc:has_creator>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   157
        self.w(u'<!-- FIXME : here be topics -->')#entity.isioc_topics()
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   158
        self.w(u'<!-- FIXME : here be replies -->')#entity.isioc_replies()
5569
cb14af012a96 [adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   159
        self.w(u' </sioc:%s>\n' % isioct)
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
   160