author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 15 Dec 2009 17:00:58 +0100 | |
branch | stable |
changeset 4122 | 3c3d2a102d4c |
parent 4062 | d16b2927afe6 |
child 4063 | cf7d6211d957 |
child 4128 | 8aaa5c6b9d1f |
permissions | -rw-r--r-- |
0 | 1 |
"""abstract views and templates classes for CubicWeb web client |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1756
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1756
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
1999
b9a8f5995658
obsolete methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1985
diff
changeset
|
10 |
_ = unicode |
0 | 11 |
|
12 |
from cStringIO import StringIO |
|
13 |
||
4058
b3578583b57b
properly escape arguments of user callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3973
diff
changeset
|
14 |
from simplejson import dumps |
b3578583b57b
properly escape arguments of user callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3973
diff
changeset
|
15 |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2558
diff
changeset
|
16 |
from logilab.common.deprecation import deprecated |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2217
diff
changeset
|
17 |
from logilab.mtconverter import xml_escape |
4058
b3578583b57b
properly escape arguments of user callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3973
diff
changeset
|
18 |
|
2644
100b81ba3a98
F [view] missing import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
19 |
from rql import nodes |
0 | 20 |
|
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1144
diff
changeset
|
21 |
from cubicweb import NotAnEntity |
1132 | 22 |
from cubicweb.selectors import yes, non_final_entity, nonempty_rset, none_rset |
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
633
diff
changeset
|
23 |
from cubicweb.selectors import require_group_compat, accepts_compat |
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2644
diff
changeset
|
24 |
from cubicweb.appobject import AppObject |
708
b4728112625f
move utils from cw.common to cw
sylvain.thenault@logilab.fr
parents:
707
diff
changeset
|
25 |
from cubicweb.utils import UStringIO, HTMLStream |
2217
3a8cee8f8778
explicit display_name import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2207
diff
changeset
|
26 |
from cubicweb.schema import display_name |
633 | 27 |
|
0 | 28 |
# robots control |
29 |
NOINDEX = u'<meta name="ROBOTS" content="NOINDEX" />' |
|
30 |
NOFOLLOW = u'<meta name="ROBOTS" content="NOFOLLOW" />' |
|
31 |
||
32 |
CW_XHTML_EXTENSIONS = '''[ |
|
33 |
<!ATTLIST html xmlns:cubicweb CDATA #FIXED \'http://www.logilab.org/2008/cubicweb\' > |
|
34 |
||
35 |
<!ENTITY % coreattrs |
|
522
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
497
diff
changeset
|
36 |
"id ID #IMPLIED |
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
497
diff
changeset
|
37 |
class CDATA #IMPLIED |
385ce5e0b30b
cubicweb__loadurl -> cubicweb:lazyloadurl
sylvain.thenault@logilab.fr
parents:
497
diff
changeset
|
38 |
style CDATA #IMPLIED |
0 | 39 |
title CDATA #IMPLIED |
40 |
||
3782
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
41 |
cubicweb:accesskey CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
42 |
cubicweb:actualrql CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
43 |
cubicweb:dataurl CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
44 |
cubicweb:displayactions CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
45 |
cubicweb:facetName CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
46 |
cubicweb:facetargs CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
47 |
cubicweb:fallbackvid CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
48 |
cubicweb:fname CDATA #IMPLIED |
0 | 49 |
cubicweb:initfunc CDATA #IMPLIED |
50 |
cubicweb:inputid CDATA #IMPLIED |
|
51 |
cubicweb:inputname CDATA #IMPLIED |
|
3782
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
52 |
cubicweb:limit CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
53 |
cubicweb:loadtype CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
54 |
cubicweb:loadurl CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
55 |
cubicweb:maxlength CDATA #IMPLIED |
0 | 56 |
cubicweb:required CDATA #IMPLIED |
3782
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
57 |
cubicweb:rooteid CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
58 |
cubicweb:rql CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
59 |
cubicweb:size CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
60 |
cubicweb:sortvalue CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
61 |
cubicweb:target CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
62 |
cubicweb:tindex CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
63 |
cubicweb:tlunit CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
64 |
cubicweb:type CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
65 |
cubicweb:uselabel CDATA #IMPLIED |
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
66 |
cubicweb:value CDATA #IMPLIED |
0 | 67 |
cubicweb:variables CDATA #IMPLIED |
68 |
cubicweb:vid CDATA #IMPLIED |
|
3782
c69fe7493b91
[cleanup] reorder cubicweb namespace attributes declaration
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
69 |
cubicweb:wdgtype CDATA #IMPLIED |
0 | 70 |
"> ] ''' |
71 |
||
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
72 |
TRANSITIONAL_DOCTYPE = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" %s>\n' % CW_XHTML_EXTENSIONS |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
73 |
TRANSITIONAL_DOCTYPE_NOEXT = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n' |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
74 |
STRICT_DOCTYPE = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" %s>\n' % CW_XHTML_EXTENSIONS |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
75 |
STRICT_DOCTYPE_NOEXT = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' |
0 | 76 |
|
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
77 |
# base view object ############################################################ |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
78 |
|
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2644
diff
changeset
|
79 |
class View(AppObject): |
0 | 80 |
"""abstract view class, used as base for every renderable object such |
81 |
as views, templates, some components...web |
|
82 |
||
83 |
A view is instantiated to render a [part of a] result set. View |
|
84 |
subclasses may be parametred using the following class attributes: |
|
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
85 |
|
0 | 86 |
* `templatable` indicates if the view may be embeded in a main |
87 |
template or if it has to be rendered standalone (i.e. XML for |
|
88 |
instance) |
|
89 |
* if the view is not templatable, it should set the `content_type` class |
|
90 |
attribute to the correct MIME type (text/xhtml by default) |
|
91 |
* the `category` attribute may be used in the interface to regroup related |
|
92 |
objects together |
|
93 |
||
94 |
At instantiation time, the standard `req`, `rset`, and `cursor` |
|
95 |
attributes are added and the `w` attribute will be set at rendering |
|
96 |
time to a write function to use. |
|
97 |
""" |
|
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
781
diff
changeset
|
98 |
__registry__ = 'views' |
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2644
diff
changeset
|
99 |
registered = require_group_compat(AppObject.registered) |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
100 |
|
0 | 101 |
templatable = True |
102 |
need_navigation = True |
|
103 |
# content_type = 'application/xhtml+xml' # text/xhtml' |
|
104 |
binary = False |
|
105 |
add_to_breadcrumbs = True |
|
106 |
category = 'view' |
|
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
107 |
|
1143
8d097defbf2c
change the way selected/__init__ are used for AppRsetObject
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
108 |
def __init__(self, req=None, rset=None, **kwargs): |
8d097defbf2c
change the way selected/__init__ are used for AppRsetObject
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
109 |
super(View, self).__init__(req, rset, **kwargs) |
0 | 110 |
self.w = None |
111 |
||
112 |
@property |
|
113 |
def content_type(self): |
|
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
114 |
return self.req.html_content_type() |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
115 |
|
0 | 116 |
def set_stream(self, w=None): |
117 |
if self.w is not None: |
|
118 |
return |
|
119 |
if w is None: |
|
120 |
if self.binary: |
|
121 |
self._stream = stream = StringIO() |
|
122 |
else: |
|
123 |
self._stream = stream = UStringIO() |
|
124 |
w = stream.write |
|
125 |
else: |
|
126 |
stream = None |
|
127 |
self.w = w |
|
128 |
return stream |
|
129 |
||
130 |
# main view interface ##################################################### |
|
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
131 |
|
1723 | 132 |
def render(self, w=None, **context): |
0 | 133 |
"""called to render a view object for a result set. |
134 |
||
135 |
This method is a dispatched to an actual method selected |
|
136 |
according to optional row and col parameters, which are locating |
|
137 |
a particular row or cell in the result set: |
|
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
138 |
|
1132 | 139 |
* if row is specified, `cell_call` is called |
0 | 140 |
* if none of them is supplied, the view is considered to apply on |
141 |
the whole result set (which may be None in this case), `call` is |
|
142 |
called |
|
143 |
""" |
|
1132 | 144 |
row = context.get('row') |
0 | 145 |
if row is not None: |
146 |
context.setdefault('col', 0) |
|
147 |
view_func = self.cell_call |
|
148 |
else: |
|
149 |
view_func = self.call |
|
150 |
stream = self.set_stream(w) |
|
151 |
# stream = self.set_stream(context) |
|
152 |
view_func(**context) |
|
153 |
# return stream content if we have created it |
|
154 |
if stream is not None: |
|
155 |
return self._stream.getvalue() |
|
156 |
||
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2558
diff
changeset
|
157 |
dispatch = deprecated('.dispatch is deprecated, use .render')(render) |
1723 | 158 |
|
0 | 159 |
# should default .call() method add a <div classs="section"> around each |
160 |
# rset item |
|
161 |
add_div_section = True |
|
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
162 |
|
0 | 163 |
def call(self, **kwargs): |
164 |
"""the view is called for an entire result set, by default loop |
|
165 |
other rows of the result set and call the same view on the |
|
166 |
particular row |
|
167 |
||
168 |
Views applicable on None result sets have to override this method |
|
169 |
""" |
|
170 |
rset = self.rset |
|
171 |
if rset is None: |
|
172 |
raise NotImplementedError, self |
|
173 |
wrap = self.templatable and len(rset) > 1 and self.add_div_section |
|
3973
1c09d2fd38c5
allow to override is_primary result using an argument given to object constructor (have to be given to 'initargs' argument of .render like initargs={'is_primary': False}
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3969
diff
changeset
|
174 |
# XXX propagate self.extra_kwars? |
0 | 175 |
for i in xrange(len(rset)): |
176 |
if wrap: |
|
177 |
self.w(u'<div class="section">') |
|
178 |
self.wview(self.id, rset, row=i, **kwargs) |
|
179 |
if wrap: |
|
180 |
self.w(u"</div>") |
|
181 |
||
182 |
def cell_call(self, row, col, **kwargs): |
|
183 |
"""the view is called for a particular result set cell""" |
|
184 |
raise NotImplementedError, self |
|
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
185 |
|
0 | 186 |
def linkable(self): |
187 |
"""return True if the view may be linked in a menu |
|
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
188 |
|
0 | 189 |
by default views without title are not meant to be displayed |
190 |
""" |
|
191 |
if not getattr(self, 'title', None): |
|
192 |
return False |
|
193 |
return True |
|
194 |
||
195 |
def is_primary(self): |
|
3973
1c09d2fd38c5
allow to override is_primary result using an argument given to object constructor (have to be given to 'initargs' argument of .render like initargs={'is_primary': False}
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3969
diff
changeset
|
196 |
return self.extra_kwargs.get('is_primary', self.id == 'primary') |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
197 |
|
0 | 198 |
def url(self): |
199 |
"""return the url associated with this view. Should not be |
|
200 |
necessary for non linkable views, but a default implementation |
|
201 |
is provided anyway. |
|
202 |
""" |
|
2468
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
203 |
rset = self.rset |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
204 |
if rset is None: |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
205 |
return self.build_url('view', vid=self.id) |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
206 |
coltypes = rset.column_types(0) |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
207 |
if len(coltypes) == 1: |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
208 |
etype = iter(coltypes).next() |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3326
diff
changeset
|
209 |
if not self.schema.eschema(etype).final: |
2468
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
210 |
if len(rset) == 1: |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
211 |
entity = rset.get_entity(0, 0) |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
212 |
return entity.absolute_url(vid=self.id) |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
213 |
# don't want to generate /<etype> url if there is some restriction |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
214 |
# on something else than the entity type |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
215 |
restr = rset.syntax_tree().children[0].where |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
216 |
# XXX norestriction is not correct here. For instance, in cases like |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
217 |
# "Any P,N WHERE P is Project, P name N" norestriction should equal |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
218 |
# True |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
219 |
norestriction = (isinstance(restr, nodes.Relation) and |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
220 |
restr.is_types_restriction()) |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
221 |
if norestriction: |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
222 |
return self.build_url(etype.lower(), vid=self.id) |
93853b6f3bad
move all view.url() logic in a single implementation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2418
diff
changeset
|
223 |
return self.build_url('view', rql=rset.printable_rql(), vid=self.id) |
0 | 224 |
|
225 |
def set_request_content_type(self): |
|
226 |
"""set the content type returned by this view""" |
|
227 |
self.req.set_content_type(self.content_type) |
|
228 |
||
229 |
# view utilities ########################################################## |
|
1433 | 230 |
|
1985
9c1db4e06095
move view method's logic on the registry, so it's easier to call it from outside an appobject. Also make rset argument optional
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
231 |
def wview(self, __vid, rset=None, __fallback_vid=None, **kwargs): |
0 | 232 |
"""shortcut to self.view method automatically passing self.w as argument |
233 |
""" |
|
234 |
self.view(__vid, rset, __fallback_vid, w=self.w, **kwargs) |
|
1433 | 235 |
|
819 | 236 |
# XXX Template bw compat |
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2558
diff
changeset
|
237 |
template = deprecated('.template is deprecated, use .view')(wview) |
0 | 238 |
|
239 |
def whead(self, data): |
|
240 |
self.req.html_headers.write(data) |
|
241 |
||
242 |
def wdata(self, data): |
|
243 |
"""simple helper that escapes `data` and writes into `self.w`""" |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2217
diff
changeset
|
244 |
self.w(xml_escape(data)) |
0 | 245 |
|
246 |
def html_headers(self): |
|
247 |
"""return a list of html headers (eg something to be inserted between |
|
248 |
<head> and </head> of the returned page |
|
249 |
||
250 |
by default return a meta tag to disable robot indexation of the page |
|
251 |
""" |
|
252 |
return [NOINDEX] |
|
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
253 |
|
0 | 254 |
def page_title(self): |
255 |
"""returns a title according to the result set - used for the |
|
256 |
title in the HTML header |
|
257 |
""" |
|
258 |
vtitle = self.req.form.get('vtitle') |
|
259 |
if vtitle: |
|
260 |
return self.req._(vtitle) |
|
261 |
# class defined title will only be used if the resulting title doesn't |
|
262 |
# seem clear enough |
|
263 |
vtitle = getattr(self, 'title', None) or u'' |
|
264 |
if vtitle: |
|
265 |
vtitle = self.req._(vtitle) |
|
266 |
rset = self.rset |
|
267 |
if rset and rset.rowcount: |
|
268 |
if rset.rowcount == 1: |
|
269 |
try: |
|
270 |
entity = self.complete_entity(0) |
|
271 |
# use long_title to get context information if any |
|
272 |
clabel = entity.dc_long_title() |
|
273 |
except NotAnEntity: |
|
274 |
clabel = display_name(self.req, rset.description[0][0]) |
|
275 |
clabel = u'%s (%s)' % (clabel, vtitle) |
|
276 |
else : |
|
277 |
etypes = rset.column_types(0) |
|
278 |
if len(etypes) == 1: |
|
279 |
etype = iter(etypes).next() |
|
280 |
clabel = display_name(self.req, etype, 'plural') |
|
281 |
else : |
|
282 |
clabel = u'#[*] (%s)' % vtitle |
|
283 |
else: |
|
284 |
clabel = vtitle |
|
285 |
return u'%s (%s)' % (clabel, self.req.property_value('ui.site-title')) |
|
286 |
||
287 |
def output_url_builder( self, name, url, args ): |
|
288 |
self.w(u'<script language="JavaScript"><!--\n' \ |
|
289 |
u'function %s( %s ) {\n' % (name, ','.join(args) ) ) |
|
290 |
url_parts = url.split("%s") |
|
291 |
self.w(u' url="%s"' % url_parts[0] ) |
|
292 |
for arg, part in zip(args, url_parts[1:]): |
|
293 |
self.w(u'+str(%s)' % arg ) |
|
294 |
if part: |
|
295 |
self.w(u'+"%s"' % part) |
|
296 |
self.w('\n document.window.href=url;\n') |
|
297 |
self.w('}\n-->\n</script>\n') |
|
298 |
||
299 |
def create_url(self, etype, **kwargs): |
|
3809
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
300 |
"""return the url of the entity creation form for a given entity type""" |
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
301 |
return self.req.build_url('add/%s' % etype, **kwargs) |
0 | 302 |
|
3809
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
303 |
def field(self, label, value, row=True, show_label=True, w=None, tr=True, table=False): |
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
304 |
"""read-only field""" |
0 | 305 |
if w is None: |
306 |
w = self.w |
|
3809
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
307 |
if table: |
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
308 |
w(u'<tr class="entityfield">') |
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
309 |
else: |
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
310 |
w(u'<div class="entityfield">') |
3326
e3089ceee1ea
don't show label if no label given
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3010
diff
changeset
|
311 |
if show_label and label: |
0 | 312 |
if tr: |
313 |
label = display_name(self.req, label) |
|
3809
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
314 |
if table: |
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
315 |
w(u'<th>%s</th>' % label) |
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
316 |
else: |
3839
84c9aab84d8c
missing space between label and value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3809
diff
changeset
|
317 |
w(u'<span>%s</span> ' % label) |
3809
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
318 |
if table: |
3969
970a748684b5
when fields are displayed in a table and label should'nt be displayed, set colspan to 2 on the field value cell
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3839
diff
changeset
|
319 |
if not (show_label and label): |
970a748684b5
when fields are displayed in a table and label should'nt be displayed, set colspan to 2 on the field value cell
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3839
diff
changeset
|
320 |
w(u'<td colspan="2">%s</td></tr>' % value) |
970a748684b5
when fields are displayed in a table and label should'nt be displayed, set colspan to 2 on the field value cell
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3839
diff
changeset
|
321 |
else: |
970a748684b5
when fields are displayed in a table and label should'nt be displayed, set colspan to 2 on the field value cell
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3839
diff
changeset
|
322 |
w(u'<td>%s</td></tr>' % value) |
3809
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
323 |
else: |
1b9b51ee543e
[web ui] PrimaryView.render_attributes now uses a table
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3782
diff
changeset
|
324 |
w(u'<span>%s</span></div>' % value) |
1433 | 325 |
|
0 | 326 |
|
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
327 |
|
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
635
diff
changeset
|
328 |
# concrete views base classes ################################################# |
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
635
diff
changeset
|
329 |
|
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
635
diff
changeset
|
330 |
class EntityView(View): |
843 | 331 |
"""base class for views applying on an entity (i.e. uniform result set)""" |
781
323656dd85a9
fix import, use non_final_entity instead of implements('Any')
sylvain.thenault@logilab.fr
parents:
757
diff
changeset
|
332 |
__select__ = non_final_entity() |
757
01740274e774
remove explicit access to .im_func when overriding `registered`
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
719
diff
changeset
|
333 |
registered = accepts_compat(View.registered) |
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
635
diff
changeset
|
334 |
|
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
635
diff
changeset
|
335 |
category = 'entityview' |
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
635
diff
changeset
|
336 |
|
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
635
diff
changeset
|
337 |
|
0 | 338 |
class StartupView(View): |
843 | 339 |
"""base class for views which doesn't need a particular result set to be |
340 |
displayed (so they can always be displayed !) |
|
0 | 341 |
""" |
707 | 342 |
__select__ = none_rset() |
757
01740274e774
remove explicit access to .im_func when overriding `registered`
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
719
diff
changeset
|
343 |
registered = require_group_compat(View.registered) |
1433 | 344 |
|
0 | 345 |
category = 'startupview' |
1433 | 346 |
|
0 | 347 |
def html_headers(self): |
348 |
"""return a list of html headers (eg something to be inserted between |
|
349 |
<head> and </head> of the returned page |
|
350 |
||
351 |
by default startup views are indexed |
|
352 |
""" |
|
353 |
return [] |
|
354 |
||
355 |
||
356 |
class EntityStartupView(EntityView): |
|
357 |
"""base class for entity views which may also be applied to None |
|
358 |
result set (usually a default rql is provided by the view class) |
|
359 |
""" |
|
781
323656dd85a9
fix import, use non_final_entity instead of implements('Any')
sylvain.thenault@logilab.fr
parents:
757
diff
changeset
|
360 |
__select__ = none_rset() | non_final_entity() |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
361 |
|
0 | 362 |
default_rql = None |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
363 |
|
2418
8f06e4f02733
optional rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
364 |
def __init__(self, req, rset=None, **kwargs): |
1143
8d097defbf2c
change the way selected/__init__ are used for AppRsetObject
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
365 |
super(EntityStartupView, self).__init__(req, rset, **kwargs) |
0 | 366 |
if rset is None: |
367 |
# this instance is not in the "entityview" category |
|
368 |
self.category = 'startupview' |
|
369 |
||
370 |
def startup_rql(self): |
|
873 | 371 |
"""return some rql to be executed if the result set is None""" |
0 | 372 |
return self.default_rql |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
373 |
|
0 | 374 |
def call(self, **kwargs): |
873 | 375 |
"""override call to execute rql returned by the .startup_rql method if |
376 |
necessary |
|
0 | 377 |
""" |
378 |
if self.rset is None: |
|
379 |
self.rset = self.req.execute(self.startup_rql()) |
|
380 |
rset = self.rset |
|
381 |
for i in xrange(len(rset)): |
|
382 |
self.wview(self.id, rset, row=i, **kwargs) |
|
383 |
||
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
384 |
|
0 | 385 |
class AnyRsetView(View): |
386 |
"""base class for views applying on any non empty result sets""" |
|
707 | 387 |
__select__ = nonempty_rset() |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
388 |
|
0 | 389 |
category = 'anyrsetview' |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
390 |
|
2203
efdd3a9f9028
update to new rql get_description api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1999
diff
changeset
|
391 |
def columns_labels(self, mainindex=0, tr=True): |
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
392 |
if tr: |
2207
5fad58e603f4
fix translate argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2203
diff
changeset
|
393 |
translate = lambda val, req=self.req: display_name(req, val) |
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
394 |
else: |
2207
5fad58e603f4
fix translate argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2203
diff
changeset
|
395 |
translate = lambda val: val |
2203
efdd3a9f9028
update to new rql get_description api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1999
diff
changeset
|
396 |
# XXX [0] because of missing Union support |
efdd3a9f9028
update to new rql get_description api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1999
diff
changeset
|
397 |
rqlstdescr = self.rset.syntax_tree().get_description(mainindex, |
efdd3a9f9028
update to new rql get_description api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1999
diff
changeset
|
398 |
translate)[0] |
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
361
diff
changeset
|
399 |
labels = [] |
2203
efdd3a9f9028
update to new rql get_description api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1999
diff
changeset
|
400 |
for colindex, label in enumerate(rqlstdescr): |
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
361
diff
changeset
|
401 |
# compute column header |
2203
efdd3a9f9028
update to new rql get_description api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1999
diff
changeset
|
402 |
if label == 'Any': # find a better label |
2207
5fad58e603f4
fix translate argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2203
diff
changeset
|
403 |
label = ','.join(translate(et) |
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
361
diff
changeset
|
404 |
for et in self.rset.column_types(colindex)) |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
361
diff
changeset
|
405 |
labels.append(label) |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
361
diff
changeset
|
406 |
return labels |
543
c0f2b6378f70
simplification of lazy tabs mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
522
diff
changeset
|
407 |
|
1433 | 408 |
|
0 | 409 |
# concrete template base classes ############################################## |
410 |
||
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
781
diff
changeset
|
411 |
class MainTemplate(View): |
0 | 412 |
"""main template are primary access point to render a full HTML page. |
413 |
There is usually at least a regular main template and a simple fallback |
|
414 |
one to display error if the first one failed |
|
415 |
""" |
|
816
9cd49a910fce
kill Template class and 'templates' registry
sylvain.thenault@logilab.fr
parents:
781
diff
changeset
|
416 |
registered = require_group_compat(View.registered) |
0 | 417 |
|
418 |
@property |
|
419 |
def doctype(self): |
|
2558
81c8b5312f9c
move test on force-html-content-type to xhtml_browser method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2555
diff
changeset
|
420 |
if self.req.xhtml_browser(): |
1421
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
421 |
return STRICT_DOCTYPE |
77ee26df178f
doc type handling refactoring: do the ext substitution at the module level
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
422 |
return STRICT_DOCTYPE_NOEXT |
0 | 423 |
|
1424 | 424 |
def set_stream(self, w=None): |
425 |
if self.w is not None: |
|
0 | 426 |
return |
427 |
if w is None: |
|
428 |
if self.binary: |
|
429 |
self._stream = stream = StringIO() |
|
430 |
else: |
|
431 |
self._stream = stream = HTMLStream(self.req) |
|
432 |
w = stream.write |
|
433 |
else: |
|
434 |
stream = None |
|
435 |
self.w = w |
|
436 |
return stream |
|
437 |
||
438 |
def write_doctype(self, xmldecl=True): |
|
439 |
assert isinstance(self._stream, HTMLStream) |
|
440 |
self._stream.doctype = self.doctype |
|
441 |
if not xmldecl: |
|
442 |
self._stream.xmldecl = u'' |
|
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
443 |
|
822 | 444 |
def linkable(self): |
445 |
return False |
|
1433 | 446 |
|
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
447 |
# concrete component base classes ############################################# |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
448 |
|
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
449 |
class ReloadableMixIn(object): |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
450 |
"""simple mixin for reloadable parts of UI""" |
1433 | 451 |
|
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
452 |
def user_callback(self, cb, args, msg=None, nonify=False): |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
453 |
"""register the given user callback and return an url to call it ready to be |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
454 |
inserted in html |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
455 |
""" |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
456 |
self.req.add_js('cubicweb.ajax.js') |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
457 |
if nonify: |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
458 |
_cb = cb |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
459 |
def cb(*args): |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
460 |
_cb(*args) |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
461 |
cbname = self.req.register_onetime_callback(cb, *args) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2217
diff
changeset
|
462 |
return self.build_js(cbname, xml_escape(msg or '')) |
1433 | 463 |
|
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
464 |
def build_update_js_call(self, cbname, msg): |
4060
4067cd36718f
should not xml_escape rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4058
diff
changeset
|
465 |
rql = self.rset.printable_rql() |
4058
b3578583b57b
properly escape arguments of user callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3973
diff
changeset
|
466 |
return "javascript:userCallbackThenUpdateUI('%s', '%s', %s, %s, '%s', '%s')" % ( |
b3578583b57b
properly escape arguments of user callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3973
diff
changeset
|
467 |
cbname, self.__regid__, dumps(rql), dumps(msg), |
b3578583b57b
properly escape arguments of user callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3973
diff
changeset
|
468 |
self.__registry__, self.div_id()) |
1433 | 469 |
|
4062
d16b2927afe6
oops, bad indent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4060
diff
changeset
|
470 |
def build_reload_js_call(self, cbname, msg): |
d16b2927afe6
oops, bad indent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4060
diff
changeset
|
471 |
return "javascript:userCallbackThenReloadPage('%s', %s)" % (cbname, dumps(msg)) |
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
472 |
|
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
473 |
build_js = build_update_js_call # expect updatable component by default |
1433 | 474 |
|
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
475 |
def div_id(self): |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
476 |
return '' |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
477 |
|
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
478 |
|
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
479 |
class Component(ReloadableMixIn, View): |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
480 |
"""base class for components""" |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
481 |
__registry__ = 'components' |
707 | 482 |
__select__ = yes() |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
483 |
property_defs = {} |
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
484 |
|
3010
684a0c546774
[ui props] drop htmlclass as a persistent property, this is definitly useless/unusable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
485 |
# XXX huummm, much probably useless |
684a0c546774
[ui props] drop htmlclass as a persistent property, this is definitly useless/unusable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
486 |
htmlclass = 'mainRelated' |
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
487 |
def div_class(self): |
3010
684a0c546774
[ui props] drop htmlclass as a persistent property, this is definitly useless/unusable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
488 |
return '%s %s' % (self.htmlclass, self.id) |
684a0c546774
[ui props] drop htmlclass as a persistent property, this is definitly useless/unusable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
489 |
# XXX a generic '%s%s' % (self.id, self.__registry__.capitalize()) would probably be nicer |
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
490 |
def div_id(self): |
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
491 |
return '%sComponent' % self.id |