web/views/pyviews.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 05 Jul 2011 10:52:34 +0200
changeset 7617 be5f68f9314e
parent 6802 ff9059e144f9
child 7903 ac658ab4c7b7
permissions -rw-r--r--
[selectors, test] remove duplicated test and add some for relation_possible selector w/ rqlst
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
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: 4863
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6088
28f49a4fe702 [doc] docstring more explicit for pyviews
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5424
diff changeset
    18
"""Basic views for python values (eg without any result set)
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
"""
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
from cubicweb.view import View
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
from cubicweb.selectors import match_kwargs
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
6088
28f49a4fe702 [doc] docstring more explicit for pyviews
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5424
diff changeset
    25
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
class PyValTableView(View):
6802
ff9059e144f9 [pyviews] document the fact that content is not xml-escaped (closes #1382038)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6088
diff changeset
    27
    """display a list of list of values into an html table.
ff9059e144f9 [pyviews] document the fact that content is not xml-escaped (closes #1382038)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6088
diff changeset
    28
ff9059e144f9 [pyviews] document the fact that content is not xml-escaped (closes #1382038)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6088
diff changeset
    29
    Take care, content is NOT xml-escaped.
ff9059e144f9 [pyviews] document the fact that content is not xml-escaped (closes #1382038)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6088
diff changeset
    30
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1987
diff changeset
    31
    __regid__ = 'pyvaltable'
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
    __select__ = match_kwargs('pyvalue')
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
    def call(self, pyvalue, headers=None):
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
        if headers is None:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    36
            headers = self._cw.form.get('headers')
4863
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    37
        w = self.w
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    38
        w(u'<table class="listing">\n')
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
        if headers:
4863
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    40
            w(u'<thead>')
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    41
            w(u'<tr>')
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
            for header in headers:
4863
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    43
                w(u'<th>%s</th>' % header)
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    44
            w(u'</tr>\n')
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    45
            w(u'</thead>')
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    46
        w(u'<tbody>')
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
        for row in pyvalue:
4863
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    48
            w(u'<tr>')
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
            for cell in row:
4863
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    50
                w(u'<td>%s</td>' % cell)
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    51
            w(u'</tr>\n')
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    52
        w(u'</tbody>')
f6cf0fcd40ae [pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    53
        w(u'</table>\n')
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    54
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    56
class PyValListView(View):
6802
ff9059e144f9 [pyviews] document the fact that content is not xml-escaped (closes #1382038)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6088
diff changeset
    57
    """display a list of values into an html list.
ff9059e144f9 [pyviews] document the fact that content is not xml-escaped (closes #1382038)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6088
diff changeset
    58
ff9059e144f9 [pyviews] document the fact that content is not xml-escaped (closes #1382038)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6088
diff changeset
    59
    Take care, content is NOT xml-escaped.
ff9059e144f9 [pyviews] document the fact that content is not xml-escaped (closes #1382038)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6088
diff changeset
    60
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1987
diff changeset
    61
    __regid__ = 'pyvallist'
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
    __select__ = match_kwargs('pyvalue')
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
    def call(self, pyvalue):
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    65
        self.w(u'<ul>\n')
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    66
        for line in pyvalue:
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    67
            self.w(u'<li>%s</li>\n' % line)
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    68
        self.w(u'</ul>\n')