author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 18 Mar 2010 14:06:53 +0100 | |
branch | stable |
changeset 4941 | ec27aea9632b |
parent 4863 | f6cf0fcd40ae |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
1987
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
"""Views to display bare python values |
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
|
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1987
diff
changeset
|
4 |
:copyright: 2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1987
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
""" |
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
__docformat__ = "restructuredtext en" |
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
|
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
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
|
11 |
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
|
12 |
|
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
class PyValTableView(View): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1987
diff
changeset
|
14 |
__regid__ = 'pyvaltable' |
1987
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
__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
|
16 |
|
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
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
|
18 |
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
|
19 |
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
|
20 |
w = self.w |
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
21 |
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
|
22 |
if headers: |
4863
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
23 |
w(u'<thead>') |
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
24 |
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
|
25 |
for header in headers: |
4863
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
26 |
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
|
27 |
w(u'</tr>\n') |
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
28 |
w(u'</thead>') |
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
29 |
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
|
30 |
for row in pyvalue: |
4863
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
31 |
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
|
32 |
for cell in row: |
4863
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
33 |
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
|
34 |
w(u'</tr>\n') |
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
35 |
w(u'</tbody>') |
f6cf0fcd40ae
[pyviews] add thead/tbody to pyvaltable view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
36 |
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
|
37 |
|
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
38 |
|
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
39 |
class PyValListView(View): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1987
diff
changeset
|
40 |
__regid__ = 'pyvallist' |
1987
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
41 |
__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
|
42 |
|
d495e9ce9367
basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
self.w(u'</ul>\n') |