web/views/isioc.py
author sylvain.thenault@logilab.fr
Thu, 30 Apr 2009 12:35:49 +0200
branchtls-sprint
changeset 1576 3bfcf1e4eb26
parent 1547 cb8c15a1e140
child 1656 094c06d0cd3b
permissions -rw-r--r--
display_fields should search for name+role
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
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
"""
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
__docformat__ = "restructuredtext en"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
from logilab.mtconverter import html_escape
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
from cubicweb.view import EntityView
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    12
from cubicweb.selectors import implements
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    13
from cubicweb.interfaces import ISiocItem, ISiocContainer
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
class SIOCView(EntityView):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
    id = 'sioc'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
    __select__ = EntityView.__select__ & implements(ISiocItem, ISiocContainer)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
    title = _('sioc')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
    templatable = False
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
    content_type = 'text/xml'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
    def call(self):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
        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
    24
        self.w(u'''<rdf:RDF
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
             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
    26
             xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
             xmlns:owl="http://www.w3.org/2002/07/owl#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
             xmlns:foaf="http://xmlns.com/foaf/0.1/"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
             xmlns:sioc="http://rdfs.org/sioc/ns#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
             xmlns:sioctype="http://rdfs.org/sioc/types#"
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
             xmlns:dcterms="http://purl.org/dc/terms/">\n''')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
        for i in xrange(self.rset.rowcount):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
            self.cell_call(i, 0)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
        self.w(u'</rdf:RDF>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
    def cell_call(self, row, col):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
        self.wview('sioc_element', self.rset, row=row, col=col)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
class SIOCContainerView(EntityView):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
    id = 'sioc_element'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
    __select__ = EntityView.__select__ & implements(ISiocContainer)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
    templatable = False
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    43
    content_type = 'text/xml'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    45
    def cell_call(self, row, col):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
        entity = self.complete_entity(row, col)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    47
        self.w(u'<sioc:%s rdf:about="%s">\n' % (html_escape(entity.isioc_type()),
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
                                                html_escape(entity.absolute_url())))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    49
        self.w(u'<dcterms:title>%s</dcterms:title>' % html_escape(entity.dc_title()))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    50
        self.w(u'<dcterms:created>%s</dcterms:created>' % entity.creation_date)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    51
        self.w(u'<dcterms:modified>%s</dcterms:modified>' % entity.modification_date)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    52
        self.w(u'<!-- FIXME : here be items -->')#entity.isioc_items()
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    53
        self.w(u'</sioc:%s>\n' % entity.isioc_type())
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    54
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    55
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
class SIOCItemView(EntityView):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
    id = 'sioc_element'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    58
    __select__ = EntityView.__select__ & implements(ISiocItem)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
    templatable = False
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
    content_type = 'text/xml'
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    62
    def cell_call(self, row, col):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    63
        entity = self.complete_entity(row, col)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    64
        self.w(u'<sioc:%s rdf:about="%s">\n' %  (html_escape(entity.isioc_type()),
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
                                                 html_escape(entity.absolute_url())))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    66
        self.w(u'<dcterms:title>%s</dcterms:title>' % html_escape(entity.dc_title()))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
        self.w(u'<dcterms:created>%s</dcterms:created>' % entity.creation_date)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
        self.w(u'<dcterms:modified>%s</dcterms:modified>' % entity.modification_date)
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
        if entity.content:
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
            self.w(u'<sioc:content>%s</sioc:content>''' % html_escape(entity.isioc_content()))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
        if entity.related('entry_of'):
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
            self.w(u'<sioc:has_container rdf:resource="%s"/>\n' % html_escape(entity.isioc_container().absolute_url()))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
        if entity.creator:
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
            self.w(u'<sioc:has_creator>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
            self.w(u'<sioc:User rdf:about="%s">\n' % html_escape(entity.creator.absolute_url()))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    76
            self.w(entity.creator.view('foaf'))
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
            self.w(u'</sioc:User>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
            self.w(u'</sioc:has_creator>\n')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
        self.w(u'<!-- FIXME : here be topics -->')#entity.isioc_topics()
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
        self.w(u'<!-- FIXME : here be replies -->')#entity.isioc_replies()
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    81
        self.w(u' </sioc:%s>\n' % 'Post')
cb8c15a1e140 backport isioc view from blog
sylvain.thenault@logilab.fr
parents:
diff changeset
    82