15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """CubicWeb web client core. You'll need a apache-modpython or twisted |
18 """CubicWeb web client core. You'll need a apache-modpython or twisted |
19 publisher to get a full CubicWeb web application |
19 publisher to get a full CubicWeb web application |
|
20 """ |
20 |
21 |
21 |
|
22 """ |
|
23 __docformat__ = "restructuredtext en" |
22 __docformat__ = "restructuredtext en" |
24 _ = unicode |
23 _ = unicode |
25 |
|
26 import sys |
|
27 if sys.version_info < (2,6): |
|
28 import simplejson as json |
|
29 else: |
|
30 import json |
|
31 |
|
32 dumps = json.dumps |
|
33 |
24 |
34 from urllib import quote as urlquote |
25 from urllib import quote as urlquote |
35 |
26 |
36 from logilab.common.deprecation import deprecated |
27 from logilab.common.deprecation import deprecated |
37 |
28 |
38 from cubicweb.web._exceptions import * |
29 from cubicweb.web._exceptions import * |
39 from cubicweb.utils import CubicWebJsonEncoder |
30 from cubicweb.utils import json_dumps |
|
31 from cubicweb.uilib import eid_param |
|
32 |
|
33 dumps = deprecated('[3.9] use cubicweb.utils.json_dumps instead of dumps')(json_dumps) |
40 |
34 |
41 INTERNAL_FIELD_VALUE = '__cubicweb_internal_field__' |
35 INTERNAL_FIELD_VALUE = '__cubicweb_internal_field__' |
42 |
36 |
43 |
37 |
44 class stdmsgs(object): |
38 class stdmsgs(object): |
49 BUTTON_DELETE = (_('button_delete'), 'TRASH_ICON') |
43 BUTTON_DELETE = (_('button_delete'), 'TRASH_ICON') |
50 YES = (_('yes'), None) |
44 YES = (_('yes'), None) |
51 NO = (_('no'), None) |
45 NO = (_('no'), None) |
52 |
46 |
53 |
47 |
54 def eid_param(name, eid): |
|
55 assert eid is not None |
|
56 if eid is None: |
|
57 eid = '' |
|
58 return '%s:%s' % (name, eid) |
|
59 |
|
60 |
|
61 from logging import getLogger |
48 from logging import getLogger |
62 LOGGER = getLogger('cubicweb.web') |
49 LOGGER = getLogger('cubicweb.web') |
63 |
50 |
64 # XXX deprecated |
51 # XXX deprecated |
65 FACETTES = set() |
52 FACETTES = set() |
66 |
53 |
67 |
|
68 def json_dumps(value): |
|
69 return dumps(value, cls=CubicWebJsonEncoder) |
|
70 |
54 |
71 def jsonize(function): |
55 def jsonize(function): |
72 def newfunc(*args, **kwargs): |
56 def newfunc(*args, **kwargs): |
73 value = function(*args, **kwargs) |
57 value = function(*args, **kwargs) |
74 try: |
58 try: |
75 return json_dumps(value) |
59 return json_dumps(value) |
76 except TypeError: |
60 except TypeError: |
77 return json_dumps(repr(value)) |
61 return json_dumps(repr(value)) |
78 return newfunc |
62 return newfunc |
79 |
63 |
80 @deprecated('[3.4] use req.build_ajax_replace_url() instead') |
64 @deprecated('[3.4] use req.ajax_replace_url() instead') |
81 def ajax_replace_url(nodeid, rql, vid=None, swap=False, **extraparams): |
65 def ajax_replace_url(nodeid, rql, vid=None, swap=False, **extraparams): |
82 """builds a replacePageChunk-like url |
66 """builds a replacePageChunk-like url |
83 >>> ajax_replace_url('foo', 'Person P') |
67 >>> ajax_replace_url('foo', 'Person P') |
84 "javascript: replacePageChunk('foo', 'Person%20P');" |
68 "javascript: replacePageChunk('foo', 'Person%20P');" |
85 >>> ajax_replace_url('foo', 'Person P', 'oneline') |
69 >>> ajax_replace_url('foo', 'Person P', 'oneline') |