web/views/xmlrss.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 23 Nov 2011 14:45:13 +0100
changeset 8094 bedf36fb17f1
parent 8035 f98012ec7c53
child 8190 2a3c1b787688
permissions -rw-r--r--
[tableview] fix action menu layout (closes #2099011) * on the left instead of the right of the table * remove the arrow and the bullets
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6959
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 4994
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: 5467
diff changeset
    18
"""base xml and rss views"""
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
1882
ce662160bb46 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1733
diff changeset
    21
_ = unicode
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
6959
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    23
from base64 import b64encode
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
from time import timezone
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
from logilab.mtconverter import xml_escape
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5569
diff changeset
    28
from cubicweb.selectors import (is_instance, non_final_entity, one_line_rset,
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
    29
                                appobject_selectable, adaptable)
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
    30
from cubicweb.view import EntityView, EntityAdapter, AnyRsetView, Component
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
    31
from cubicweb.view import implements_adapter_compat
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
    32
from cubicweb.uilib import simple_sgml_tag
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    33
from cubicweb.web import httpcache, component
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
6959
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    35
def encode_bytes(value):
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    36
    return '<![CDATA[%s]]>' % b64encode(value.getvalue())
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    37
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    38
# see cubicweb.sobjects.parser.DEFAULT_CONVERTERS
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    39
SERIALIZERS = {
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    40
    'String': xml_escape,
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    41
    'Bytes': encode_bytes,
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    42
    'Date': lambda x: x.strftime('%Y-%m-%d'),
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    43
    'Datetime': lambda x: x.strftime('%Y-%m-%d %H:%M:%S'),
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    44
    'Time': lambda x: x.strftime('%H:%M:%S'),
7166
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    45
    'TZDatetime': lambda x: x.strftime('%Y-%m-%d %H:%M:%S'), # XXX TZ
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6960
diff changeset
    46
    'TZTime': lambda x: x.strftime('%H:%M:%S'),
6959
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    47
    'Interval': lambda x: x.days * 60*60*24 + x.seconds,
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    48
    }
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
    49
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
    50
# base xml views ##############################################################
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    51
1652
ba0a6b4d04f7 more intuitive case
sylvain.thenault@logilab.fr
parents: 1550
diff changeset
    52
class XMLView(EntityView):
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    53
    """xml view for entities"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
    54
    __regid__ = 'xml'
8035
f98012ec7c53 [export views] uniformize titles, much nicer when listing possible views. Closes #2060944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7911
diff changeset
    55
    title = _('xml export (entities)')
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
    templatable = False
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
    content_type = 'text/xml'
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    58
    xml_root = 'rset'
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
    item_vid = 'xmlitem'
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
    60
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
    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
    62
        self.wview(self.item_vid, self.cw_rset, row=row, col=col)
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
    63
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    64
    def call(self):
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
        """display a list of entities by calling their <item_vid> view"""
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    66
        self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    67
        self.w(u'<%s size="%s">\n' % (self.xml_root, len(self.cw_rset)))
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    68
        for i in xrange(self.cw_rset.rowcount):
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
            self.cell_call(i, 0)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
        self.w(u'</%s>\n' % self.xml_root)
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
1652
ba0a6b4d04f7 more intuitive case
sylvain.thenault@logilab.fr
parents: 1550
diff changeset
    73
class XMLItemView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
    74
    __regid__ = 'xmlitem'
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
7553
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
    76
    def entity_call(self, entity):
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
    77
        """element as an item for an xml feed"""
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
    78
        entity.complete()
7534
d58a9d96aad8 [datafeed, cw.xml] xml now carry entity's source information, interpreted at the other end so that for instance when an entity from elo is seen when importing cwo, it's properly marked as coming from elo source if one exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
    79
        source = entity.cw_metainformation()['source']['uri']
d58a9d96aad8 [datafeed, cw.xml] xml now carry entity's source information, interpreted at the other end so that for instance when an entity from elo is seen when importing cwo, it's properly marked as coming from elo source if one exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
    80
        self.w(u'<%s eid="%s" cwuri="%s" cwsource="%s">\n'
d58a9d96aad8 [datafeed, cw.xml] xml now carry entity's source information, interpreted at the other end so that for instance when an entity from elo is seen when importing cwo, it's properly marked as coming from elo source if one exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
    81
               % (entity.__regid__, entity.eid, xml_escape(entity.cwuri),
d58a9d96aad8 [datafeed, cw.xml] xml now carry entity's source information, interpreted at the other end so that for instance when an entity from elo is seen when importing cwo, it's properly marked as coming from elo source if one exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
    82
                  xml_escape(source)))
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
        for rschema, attrschema in entity.e_schema.attribute_definitions():
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
            attr = rschema.type
6959
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    85
            if attr in ('eid', 'cwuri'):
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    86
                continue
4994
108bb7f2a171 dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4898
diff changeset
    87
            else:
108bb7f2a171 dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4898
diff changeset
    88
                try:
6142
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
    89
                    value = entity.cw_attr_cache[attr]
4994
108bb7f2a171 dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4898
diff changeset
    90
                except KeyError:
108bb7f2a171 dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4898
diff changeset
    91
                    # Bytes
108bb7f2a171 dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4898
diff changeset
    92
                    continue
6959
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    93
            if value is None:
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    94
                self.w(u'  <%s/>\n' % attr)
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    95
            else:
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    96
                try:
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    97
                    value = SERIALIZERS[attrschema](value)
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    98
                except KeyError:
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
    99
                    pass
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   100
                self.w(u'  <%s>%s</%s>\n' % (attr, value, attr))
6959
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   101
        for relstr in self._cw.list_form_param('relation'):
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   102
            try:
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   103
                rtype, role = relstr.split('-')
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   104
            except ValueError:
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   105
                self.error('badly formated relation name %r', relstr)
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   106
                continue
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   107
            if role == 'subject':
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   108
                getrschema = entity.e_schema.subjrels
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   109
            elif role == 'object':
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   110
                getrschema = entity.e_schema.objrels
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   111
            else:
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   112
                self.error('badly formated relation name %r', relstr)
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   113
                continue
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   114
            if not rtype in getrschema:
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   115
                self.error('unexisting relation %r', relstr)
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   116
                continue
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   117
            self.w(u'  <%s role="%s">\n' % (rtype, role))
7911
5ab88d05083f [xml/rdf views] handle case where the user hasn't read access to a relation (closes #1984598)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7553
diff changeset
   118
            self.wview('xmlrelateditem', entity.related(rtype, role, safe=True), 'null')
6959
037a0277db0a [xml] enhance default entity xml view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6864
diff changeset
   119
            self.w(u'  </%s>\n' % rtype)
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   120
        self.w(u'</%s>\n' % (entity.e_schema))
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   121
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   122
7553
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   123
class XMLRelatedItemView(EntityView):
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   124
    __regid__ = 'xmlrelateditem'
7911
5ab88d05083f [xml/rdf views] handle case where the user hasn't read access to a relation (closes #1984598)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7553
diff changeset
   125
    add_div_section = False
7553
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   126
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   127
    def entity_call(self, entity):
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   128
        # XXX put unique attributes as xml attribute, they are much probably
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   129
        # used to search existing entities in client data feed, and putting it
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   130
        # here may avoid an extra request to get those attributes values
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   131
        self.w(u'    <%s eid="%s" cwuri="%s"/>\n'
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   132
               % (entity.e_schema, entity.eid, xml_escape(entity.cwuri)))
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   133
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   134
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   135
class XMLRelatedItemStateView(XMLRelatedItemView):
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   136
    __select__ = is_instance('State')
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   137
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   138
    def entity_call(self, entity):
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   139
        self.w(u'    <%s eid="%s" cwuri="%s" name="%s"/>\n'
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   140
               % (entity.e_schema, entity.eid, xml_escape(entity.cwuri),
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   141
                  xml_escape(entity.name)))
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   142
935423529f45 [datafeed cw parser] refactor: split logic that was in the parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7534
diff changeset
   143
1652
ba0a6b4d04f7 more intuitive case
sylvain.thenault@logilab.fr
parents: 1550
diff changeset
   144
class XMLRsetView(AnyRsetView):
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   145
    """dumps raw rset as xml"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   146
    __regid__ = 'rsetxml'
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   147
    title = _('xml export')
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   148
    templatable = False
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   149
    content_type = 'text/xml'
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   150
    xml_root = 'rset'
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   151
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   152
    def call(self):
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   153
        w = self.w
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   154
        rset, descr = self.cw_rset, self.cw_rset.description
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4023
diff changeset
   155
        eschema = self._cw.vreg.schema.eschema
2205
fc1447fe94df tr is now the second argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   156
        labels = self.columns_labels(tr=False)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   157
        w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding)
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   158
        w(u'<%s query="%s">\n' % (self.xml_root, xml_escape(rset.printable_rql())))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   159
        for rowindex, row in enumerate(self.cw_rset):
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   160
            w(u' <row>\n')
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   161
            for colindex, val in enumerate(row):
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   162
                etype = descr[rowindex][colindex]
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   163
                tag = labels[colindex]
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   164
                attrs = {}
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   165
                if '(' in tag:
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   166
                    attrs['expr'] = tag
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   167
                    tag = 'funccall'
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3165
diff changeset
   168
                if val is not None and not eschema(etype).final:
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   169
                    attrs['eid'] = val
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   170
                    # csvrow.append(val) # val is eid in that case
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   171
                    val = self._cw.view('textincontext', rset,
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   172
                                        row=rowindex, col=colindex)
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   173
                else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   174
                    val = self._cw.view('final', rset, row=rowindex,
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   175
                                        col=colindex, format='text/plain')
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   176
                w(simple_sgml_tag(tag, val, **attrs))
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   177
            w(u' </row>\n')
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   178
        w(u'</%s>\n' % self.xml_root)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   179
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   180
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   181
# RSS stuff ###################################################################
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   182
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   183
class IFeedAdapter(EntityAdapter):
6864
ea95004494a2 [adapters] fix #1424467 caused by precedence of bw compat method while the adapter is concret for a given class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6142
diff changeset
   184
    __needs_bw_compat__ = True
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   185
    __regid__ = 'IFeed'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5569
diff changeset
   186
    __select__ = is_instance('Any')
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   187
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   188
    @implements_adapter_compat('IFeed')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   189
    def rss_feed_url(self):
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   190
        """return an url to the rss feed for this entity"""
5569
cb14af012a96 [adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   191
        return self.entity.absolute_url(vid='rss')
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   192
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   193
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   194
class RSSFeedURL(Component):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   195
    __regid__ = 'rss_feed_url'
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   196
    __select__ = non_final_entity()
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   197
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   198
    def feed_url(self):
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   199
        return self._cw.build_url(rql=self.cw_rset.limited_rql(), vid='rss')
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   200
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   201
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   202
class RSSEntityFeedURL(Component):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   203
    __regid__ = 'rss_feed_url'
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   204
    __select__ = one_line_rset() & adaptable('IFeed')
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   205
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   206
    def feed_url(self):
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   207
        entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5467
diff changeset
   208
        return entity.cw_adapt_to('IFeed').rss_feed_url()
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   209
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   210
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   211
class RSSIconBox(component.CtxComponent):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   212
    """just display the RSS icon on uniform result set"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   213
    __regid__ = 'rss'
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   214
    __select__ = (component.CtxComponent.__select__
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   215
                  & appobject_selectable('components', 'rss_feed_url'))
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   216
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   217
    visible = False
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   218
    order = 999
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   219
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   220
    def render(self, w, **kwargs):
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   221
        try:
5467
57372dbfd114 [https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5444
diff changeset
   222
            rss = self._cw.uiprops['RSS_LOGO']
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   223
        except KeyError:
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   224
            self.error('missing RSS_LOGO external resource')
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   225
            return
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   226
        urlgetter = self._cw.vreg['components'].select('rss_feed_url', self._cw,
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   227
                                                       rset=self.cw_rset)
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   228
        url = urlgetter.feed_url()
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5877
diff changeset
   229
        w(u'<a href="%s"><img src="%s" alt="rss"/></a>\n' % (xml_escape(url), rss))
1091
b5e253c0dd13 a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents: 824
diff changeset
   230
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   231
1652
ba0a6b4d04f7 more intuitive case
sylvain.thenault@logilab.fr
parents: 1550
diff changeset
   232
class RSSView(XMLView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   233
    __regid__ = 'rss'
8035
f98012ec7c53 [export views] uniformize titles, much nicer when listing possible views. Closes #2060944
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7911
diff changeset
   234
    title = _('rss export')
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   235
    templatable = False
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   236
    content_type = 'text/xml'
2058
7ef12c03447c nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   237
    http_cache_manager = httpcache.MaxAgeHTTPCacheManager
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   238
    cache_max_age = 60*60*2 # stay in http cache for 2 hours by default
4898
5dec0d400d08 Add a rssitem_id attribut to RSSView to easly choose the view used for items.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4785
diff changeset
   239
    item_vid = 'rssitem'
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   240
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   241
    def _open(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   242
        req = self._cw
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   243
        self.w(u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding)
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   244
        self.w(u'<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">\n')
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   245
        self.w(u'  <channel>\n')
1733
94c36d679454 use html for rss description
sylvain.thenault@logilab.fr
parents: 1652
diff changeset
   246
        self.w(u'    <title>%s RSS Feed</title>\n'
94c36d679454 use html for rss description
sylvain.thenault@logilab.fr
parents: 1652
diff changeset
   247
               % xml_escape(self.page_title()))
94c36d679454 use html for rss description
sylvain.thenault@logilab.fr
parents: 1652
diff changeset
   248
        self.w(u'    <description>%s</description>\n'
94c36d679454 use html for rss description
sylvain.thenault@logilab.fr
parents: 1652
diff changeset
   249
               % xml_escape(req.form.get('vtitle', '')))
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   250
        params = req.form.copy()
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   251
        params.pop('vid', None)
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   252
        self.w(u'    <link>%s</link>\n' % xml_escape(self._cw.build_url(**params)))
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   253
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   254
    def _close(self):
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   255
        self.w(u'  </channel>\n')
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   256
        self.w(u'</rss>')
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   257
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   258
    def call(self):
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   259
        """display a list of entities by calling their <item_vid> view"""
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   260
        self._open()
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   261
        for i in xrange(self.cw_rset.rowcount):
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   262
            self.cell_call(i, 0)
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   263
        self._close()
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   264
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   265
    def cell_call(self, row, col):
4898
5dec0d400d08 Add a rssitem_id attribut to RSSView to easly choose the view used for items.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4785
diff changeset
   266
        self.wview(self.item_vid, self.cw_rset, row=row, col=col)
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   267
1550
8260e857822b use xml_escape
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   268
1652
ba0a6b4d04f7 more intuitive case
sylvain.thenault@logilab.fr
parents: 1550
diff changeset
   269
class RSSItemView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   270
    __regid__ = 'rssitem'
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   271
    date_format = '%%Y-%%m-%%dT%%H:%%M%+03i:00' % (timezone / 3600)
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   272
    add_div_section = False
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   273
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   274
    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
   275
        entity = self.cw_rset.complete_entity(row, col)
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   276
        self.w(u'<item>\n')
1733
94c36d679454 use html for rss description
sylvain.thenault@logilab.fr
parents: 1652
diff changeset
   277
        self.w(u'<guid isPermaLink="true">%s</guid>\n'
94c36d679454 use html for rss description
sylvain.thenault@logilab.fr
parents: 1652
diff changeset
   278
               % xml_escape(entity.absolute_url()))
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   279
        self.render_title_link(entity)
4785
1fa7363c78bd add render_description method to RSSItemView to improve modularity.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4252
diff changeset
   280
        self.render_description(entity)
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   281
        self._marker('dc:date', entity.dc_date(self.date_format))
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   282
        self.render_entity_creator(entity)
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   283
        self.w(u'</item>\n')
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   284
4785
1fa7363c78bd add render_description method to RSSItemView to improve modularity.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4252
diff changeset
   285
    def render_description(self, entity):
1fa7363c78bd add render_description method to RSSItemView to improve modularity.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4252
diff changeset
   286
        self._marker('description', entity.dc_description(format='text/html'))
1fa7363c78bd add render_description method to RSSItemView to improve modularity.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4252
diff changeset
   287
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   288
    def render_title_link(self, entity):
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   289
        self._marker('title', entity.dc_long_title())
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   290
        self._marker('link', entity.absolute_url())
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   291
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   292
    def render_entity_creator(self, entity):
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   293
        if entity.creator:
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   294
            self._marker('dc:creator', entity.dc_creator())
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1135
diff changeset
   295
824
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   296
    def _marker(self, marker, value):
a5e6acffde30 merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff changeset
   297
        if value:
1550
8260e857822b use xml_escape
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   298
            self.w(u'  <%s>%s</%s>\n' % (marker, xml_escape(value), marker))