17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """Set of base controllers, which are directly plugged into the application |
18 """Set of base controllers, which are directly plugged into the application |
19 object to handle publication. |
19 object to handle publication. |
20 """ |
20 """ |
21 |
21 |
22 |
|
23 from cubicweb import _ |
|
24 |
|
25 from warnings import warn |
|
26 |
|
27 from six import text_type |
22 from six import text_type |
28 from six.moves import http_client |
23 from six.moves import http_client |
29 |
|
30 from logilab.common.deprecation import deprecated |
|
31 |
24 |
32 from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError, |
25 from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError, |
33 AuthenticationError, UndoTransactionException, |
26 AuthenticationError, UndoTransactionException, |
34 Forbidden) |
27 Forbidden) |
35 from cubicweb.utils import json_dumps |
28 from cubicweb.utils import json_dumps |
36 from cubicweb.predicates import (authenticated_user, anonymous_user, |
29 from cubicweb.predicates import (authenticated_user, anonymous_user, |
37 match_form_params) |
30 match_form_params) |
38 from cubicweb.web import Redirect, RemoteCallFailed |
31 from cubicweb.web import Redirect |
39 from cubicweb.web.controller import Controller, append_url_params |
32 from cubicweb.web.controller import Controller |
40 from cubicweb.web.views import vid_from_rset |
33 from cubicweb.web.views import vid_from_rset |
41 import cubicweb.transaction as tx |
|
42 |
|
43 @deprecated('[3.15] jsonize is deprecated, use AjaxFunction appobjects instead') |
|
44 def jsonize(func): |
|
45 """decorator to sets correct content_type and calls `json_dumps` on |
|
46 results |
|
47 """ |
|
48 def wrapper(self, *args, **kwargs): |
|
49 self._cw.set_content_type('application/json') |
|
50 return json_dumps(func(self, *args, **kwargs)) |
|
51 wrapper.__name__ = func.__name__ |
|
52 return wrapper |
|
53 |
|
54 @deprecated('[3.15] xhtmlize is deprecated, use AjaxFunction appobjects instead') |
|
55 def xhtmlize(func): |
|
56 """decorator to sets correct content_type and calls `xmlize` on results""" |
|
57 def wrapper(self, *args, **kwargs): |
|
58 self._cw.set_content_type(self._cw.html_content_type()) |
|
59 result = func(self, *args, **kwargs) |
|
60 return ''.join((u'<div>', result.strip(), |
|
61 u'</div>')) |
|
62 wrapper.__name__ = func.__name__ |
|
63 return wrapper |
|
64 |
|
65 @deprecated('[3.15] check_pageid is deprecated, use AjaxFunction appobjects instead') |
|
66 def check_pageid(func): |
|
67 """decorator which checks the given pageid is found in the |
|
68 user's session data |
|
69 """ |
|
70 def wrapper(self, *args, **kwargs): |
|
71 data = self._cw.session.data.get(self._cw.pageid) |
|
72 if data is None: |
|
73 raise RemoteCallFailed(self._cw._('pageid-not-found')) |
|
74 return func(self, *args, **kwargs) |
|
75 return wrapper |
|
76 |
34 |
77 |
35 |
78 class LoginController(Controller): |
36 class LoginController(Controller): |
79 __regid__ = 'login' |
37 __regid__ = 'login' |
80 __select__ = anonymous_user() |
38 __select__ = anonymous_user() |
253 status, args, entity = _validate_form(self._cw, self._cw.vreg) |
211 status, args, entity = _validate_form(self._cw, self._cw.vreg) |
254 domid = self._cw.form.get('__domid', 'entityForm') |
212 domid = self._cw.form.get('__domid', 'entityForm') |
255 return self.response(domid, status, args, entity).encode(self._cw.encoding) |
213 return self.response(domid, status, args, entity).encode(self._cw.encoding) |
256 |
214 |
257 |
215 |
258 class JSonController(Controller): |
|
259 __regid__ = 'json' |
|
260 |
|
261 def publish(self, rset=None): |
|
262 warn('[3.15] JSONController is deprecated, use AjaxController instead', |
|
263 DeprecationWarning) |
|
264 ajax_controller = self._cw.vreg['controllers'].select('ajax', self._cw, appli=self.appli) |
|
265 return ajax_controller.publish(rset) |
|
266 |
|
267 |
|
268 class MailBugReportController(Controller): |
216 class MailBugReportController(Controller): |
269 __regid__ = 'reportbug' |
217 __regid__ = 'reportbug' |
270 __select__ = match_form_params('description') |
218 __select__ = match_form_params('description') |
271 |
219 |
272 def publish(self, rset=None): |
220 def publish(self, rset=None): |