4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 __docformat__ = "restructuredtext en" |
7 __docformat__ = "restructuredtext en" |
8 |
8 |
9 from warnings import warn |
|
10 from datetime import datetime, timedelta |
9 from datetime import datetime, timedelta |
11 |
10 |
12 from simplejson import dumps |
11 from simplejson import dumps |
13 |
12 |
14 from logilab.common.decorators import classproperty |
13 from logilab.common.decorators import classproperty |
116 |
115 |
117 def __init__(self, req=None, rset=None): |
116 def __init__(self, req=None, rset=None): |
118 super(AppRsetObject, self).__init__() |
117 super(AppRsetObject, self).__init__() |
119 self.req = req |
118 self.req = req |
120 self.rset = rset |
119 self.rset = rset |
121 |
|
122 @property |
|
123 def cursor(self): # XXX deprecate in favor of req.cursor? |
|
124 msg = '.cursor is deprecated, use req.execute (or req.cursor if necessary)' |
|
125 warn(msg, DeprecationWarning, stacklevel=2) |
|
126 return self.req.cursor |
|
127 |
120 |
128 def get_cache(self, cachename): |
121 def get_cache(self, cachename): |
129 """ |
122 """ |
130 NOTE: cachename should be dotted names as in : |
123 NOTE: cachename should be dotted names as in : |
131 - cubicweb.mycache |
124 - cubicweb.mycache |
213 not '_restpath' in kwargs: |
206 not '_restpath' in kwargs: |
214 method = self.req.relative_path(includeparams=False) or 'view' |
207 method = self.req.relative_path(includeparams=False) or 'view' |
215 return self.req.build_url(method, **kwargs) |
208 return self.req.build_url(method, **kwargs) |
216 |
209 |
217 # various resources accessors ############################################# |
210 # various resources accessors ############################################# |
218 |
|
219 def etype_rset(self, etype, size=1): |
|
220 """return a fake result set for a particular entity type""" |
|
221 msg = '.etype_rset is deprecated, use req.etype_rset' |
|
222 warn(msg, DeprecationWarning, stacklevel=2) |
|
223 return self.req.etype_rset(etype, size=1) |
|
224 |
|
225 def eid_rset(self, eid, etype=None): |
|
226 """return a result set for the given eid""" |
|
227 msg = '.eid_rset is deprecated, use req.eid_rset' |
|
228 warn(msg, DeprecationWarning, stacklevel=2) |
|
229 return self.req.eid_rset(eid, etype) |
|
230 |
211 |
231 def entity(self, row, col=0): |
212 def entity(self, row, col=0): |
232 """short cut to get an entity instance for a particular row/column |
213 """short cut to get an entity instance for a particular row/column |
233 (col default to 0) |
214 (col default to 0) |
234 """ |
215 """ |
253 def user_callback(self, cb, args, msg=None, nonify=False): |
234 def user_callback(self, cb, args, msg=None, nonify=False): |
254 """register the given user callback and return an url to call it ready to be |
235 """register the given user callback and return an url to call it ready to be |
255 inserted in html |
236 inserted in html |
256 """ |
237 """ |
257 self.req.add_js('cubicweb.ajax.js') |
238 self.req.add_js('cubicweb.ajax.js') |
258 if nonify: |
|
259 # XXX < 2.48.3 bw compat |
|
260 warn('nonify argument is deprecated', DeprecationWarning, stacklevel=2) |
|
261 _cb = cb |
|
262 def cb(*args): |
|
263 _cb(*args) |
|
264 cbname = self.req.register_onetime_callback(cb, *args) |
239 cbname = self.req.register_onetime_callback(cb, *args) |
265 msg = dumps(msg or '') |
240 msg = dumps(msg or '') |
266 return "javascript:userCallbackThenReloadPage('%s', %s)" % ( |
241 return "javascript:userCallbackThenReloadPage('%s', %s)" % ( |
267 cbname, msg) |
242 cbname, msg) |
268 |
243 |