web/views/isioc.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 04 Aug 2009 17:02:18 +0200
changeset 2679 3fa8c0cec760
parent 2312 af4d8f75c5db
child 3377 dd9d292b6a6d
child 4212 ab6573088b4a
permissions -rw-r--r--
[reledit] refactor, split into reledit/doreledit where the former try to tell if edition *should* be done, and the later tell if edition *can* be done
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
"""Specific views for SIOC interfaces
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     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
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     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
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
"""
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
__docformat__ = "restructuredtext en"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     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
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    12
from cubicweb.view import EntityView
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    13
from cubicweb.selectors import implements
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
from cubicweb.interfaces import ISiocItem, ISiocContainer
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
class SIOCView(EntityView):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
    id = 'sioc'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
    __select__ = EntityView.__select__ & implements(ISiocItem, ISiocContainer)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
    title = _('sioc')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
    templatable = False
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
    content_type = 'text/xml'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
    def call(self):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
        self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
        self.w(u'''<rdf:RDF
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
             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
    27
             xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
             xmlns:owl="http://www.w3.org/2002/07/owl#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
             xmlns:foaf="http://xmlns.com/foaf/0.1/"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
             xmlns:sioc="http://rdfs.org/sioc/ns#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
             xmlns:sioctype="http://rdfs.org/sioc/types#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
             xmlns:dcterms="http://purl.org/dc/terms/">\n''')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
        for i in xrange(self.rset.rowcount):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
            self.cell_call(i, 0)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
        self.w(u'</rdf:RDF>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
    def cell_call(self, row, col):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
        self.wview('sioc_element', self.rset, row=row, col=col)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
class SIOCContainerView(EntityView):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
    id = 'sioc_element'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
    __select__ = EntityView.__select__ & implements(ISiocContainer)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    43
    templatable = False
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
    content_type = 'text/xml'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    45
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
    def cell_call(self, row, col):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    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
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    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
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    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
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    53
        self.w(u'<dcterms:created>%s</dcterms:created>'
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    54
               % entity.creation_date)
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    55
        self.w(u'<dcterms:modified>%s</dcterms:modified>'
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    56
               % entity.modification_date)
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
        self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items()
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    58
        self.w(u'</sioc:%s>\n' % sioct)
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
class SIOCItemView(EntityView):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    62
    id = 'sioc_element'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    63
    __select__ = EntityView.__select__ & implements(ISiocItem)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    64
    templatable = False
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
    content_type = 'text/xml'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    66
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
    def cell_call(self, row, col):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    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
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    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
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    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
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    74
        self.w(u'<dcterms:created>%s</dcterms:created>'
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    75
               % entity.creation_date)
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    76
        self.w(u'<dcterms:modified>%s</dcterms:modified>'
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    77
               % entity.modification_date)
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
        if entity.content:
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    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
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    81
        if entity.related('entry_of'):
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    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
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
        if entity.creator:
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    85
            self.w(u'<sioc:has_creator>\n')
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    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
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    88
            self.w(entity.creator.view('foaf'))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    89
            self.w(u'</sioc:User>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    90
            self.w(u'</sioc:has_creator>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    91
        self.w(u'<!-- FIXME : here be topics -->')#entity.isioc_topics()
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    92
        self.w(u'<!-- FIXME : here be replies -->')#entity.isioc_replies()
1656
094c06d0cd3b buggy sioc views
sylvain.thenault@logilab.fr
parents: 1547
diff changeset
    93
        self.w(u' </sioc:%s>\n' % sioct)
1547
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    94