author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 12 Jul 2010 12:25:19 +0200 | |
changeset 5955 | 67dfe437bf25 |
parent 5940 | 0e3ae19b181a |
child 6106 | 1e6d93f70d14 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5389
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""CubicWeb web client core. You'll need a apache-modpython or twisted |
19 |
publisher to get a full CubicWeb web application |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
20 |
""" |
0 | 21 |
|
22 |
__docformat__ = "restructuredtext en" |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
23 |
_ = unicode |
0 | 24 |
|
2808
497424219fb0
fix urlquote imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2788
diff
changeset
|
25 |
from urllib import quote as urlquote |
0 | 26 |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
27 |
from logilab.common.deprecation import deprecated |
1801
672acc730ce5
ajax_replace_url becomes obsolete, req.build_ajax_replace_url should be used instead
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1645
diff
changeset
|
28 |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
29 |
from cubicweb.web._exceptions import * |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5713
diff
changeset
|
30 |
from cubicweb.utils import json_dumps |
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5713
diff
changeset
|
31 |
|
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5713
diff
changeset
|
32 |
dumps = deprecated('[3.9] use cubicweb.utils.json_dumps instead of dumps')(json_dumps) |
0 | 33 |
|
34 |
INTERNAL_FIELD_VALUE = '__cubicweb_internal_field__' |
|
35 |
||
36 |
||
37 |
class stdmsgs(object): |
|
38 |
"""standard ui message (in a class for bw compat)""" |
|
3803
414bb8439002
[web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3758
diff
changeset
|
39 |
BUTTON_OK = (_('button_ok'), 'OK_ICON') |
414bb8439002
[web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3758
diff
changeset
|
40 |
BUTTON_APPLY = (_('button_apply'), 'APPLY_ICON') |
414bb8439002
[web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3758
diff
changeset
|
41 |
BUTTON_CANCEL = (_('button_cancel'), 'CANCEL_ICON') |
414bb8439002
[web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3758
diff
changeset
|
42 |
BUTTON_DELETE = (_('button_delete'), 'TRASH_ICON') |
414bb8439002
[web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3758
diff
changeset
|
43 |
YES = (_('yes'), None) |
414bb8439002
[web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3758
diff
changeset
|
44 |
NO = (_('no'), None) |
0 | 45 |
|
46 |
||
47 |
def eid_param(name, eid): |
|
48 |
assert eid is not None |
|
49 |
if eid is None: |
|
50 |
eid = '' |
|
51 |
return '%s:%s' % (name, eid) |
|
52 |
||
53 |
||
54 |
from logging import getLogger |
|
55 |
LOGGER = getLogger('cubicweb.web') |
|
56 |
||
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
57 |
# XXX deprecated |
0 | 58 |
FACETTES = set() |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
59 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
60 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
61 |
def jsonize(function): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
62 |
def newfunc(*args, **kwargs): |
3758
d43c9709434d
yet another brain fart
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3741
diff
changeset
|
63 |
value = function(*args, **kwargs) |
3741
3864c7dfddf0
use cuibicweb json encoder for json_dumps, still catch the TypeError in the request-less jsonize
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2934
diff
changeset
|
64 |
try: |
3864c7dfddf0
use cuibicweb json encoder for json_dumps, still catch the TypeError in the request-less jsonize
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2934
diff
changeset
|
65 |
return json_dumps(value) |
3864c7dfddf0
use cuibicweb json encoder for json_dumps, still catch the TypeError in the request-less jsonize
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2934
diff
changeset
|
66 |
except TypeError: |
3864c7dfddf0
use cuibicweb json encoder for json_dumps, still catch the TypeError in the request-less jsonize
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2934
diff
changeset
|
67 |
return json_dumps(repr(value)) |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
68 |
return newfunc |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
69 |
|
5713
605f571198eb
[web] ajax_replace_url superseed build_ajax_replace_url, more generic and relying on the json controller (closes #750090)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
70 |
@deprecated('[3.4] use req.ajax_replace_url() instead') |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
71 |
def ajax_replace_url(nodeid, rql, vid=None, swap=False, **extraparams): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
72 |
"""builds a replacePageChunk-like url |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
73 |
>>> ajax_replace_url('foo', 'Person P') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
74 |
"javascript: replacePageChunk('foo', 'Person%20P');" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
75 |
>>> ajax_replace_url('foo', 'Person P', 'oneline') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
76 |
"javascript: replacePageChunk('foo', 'Person%20P', 'oneline');" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
77 |
>>> ajax_replace_url('foo', 'Person P', 'oneline', name='bar', age=12) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
78 |
"javascript: replacePageChunk('foo', 'Person%20P', 'oneline', {'age':12, 'name':'bar'});" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
79 |
>>> ajax_replace_url('foo', 'Person P', name='bar', age=12) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
80 |
"javascript: replacePageChunk('foo', 'Person%20P', 'null', {'age':12, 'name':'bar'});" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
81 |
""" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
82 |
params = [repr(nodeid), repr(urlquote(rql))] |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
83 |
if extraparams and not vid: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
84 |
params.append("'null'") |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
85 |
elif vid: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
86 |
params.append(repr(vid)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
87 |
if extraparams: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
88 |
params.append(json_dumps(extraparams)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
89 |
if swap: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
90 |
params.append('true') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
91 |
return "javascript: replacePageChunk(%s);" % ', '.join(params) |