web/views/pyviews.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 21 Oct 2009 11:34:11 +0200
branchstable
changeset 3767 03924de0014d
parent 1987 d495e9ce9367
child 3377 dd9d292b6a6d
child 4212 ab6573088b4a
permissions -rw-r--r--
reledit: stuff the value into its own div and properly hide it when necessary (but dont lump it with the landingzone div for it switches the form on when one clicks on a value to traverse it)

"""Views to display bare python values

:organization: Logilab
:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
__docformat__ = "restructuredtext en"

from cubicweb.view import View
from cubicweb.selectors import match_kwargs

class PyValTableView(View):
    id = 'pyvaltable'
    __select__ = match_kwargs('pyvalue')

    def call(self, pyvalue, headers=None):
        if headers is None:
            headers = self.req.form.get('headers')
        self.w(u'<table class="listing">\n')
        if headers:
            self.w(u'<tr>')
            for header in headers:
                self.w(u'<th>%s</th>' % header)
            self.w(u'</tr>\n')
        for row in pyvalue:
            self.w(u'<tr>')
            for cell in row:
                self.w(u'<td>%s</td>' % cell)
            self.w(u'</tr>\n')
        self.w(u'</table>\n')


class PyValListView(View):
    id = 'pyvallist'
    __select__ = match_kwargs('pyvalue')

    def call(self, pyvalue):
        self.w(u'<ul>\n')
        for line in pyvalue:
            self.w(u'<li>%s</li>\n' % line)
        self.w(u'</ul>\n')