author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 07 Oct 2011 11:59:20 +0200 | |
changeset 7920 | 5146c63e8e34 |
parent 6614 | 4b9a785df0f7 |
child 7990 | a673d1d9a738 |
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 |
6106
1e6d93f70d14
[selectors] fix match_transition & introduce new edited_attribute selector
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5940
diff
changeset
|
31 |
from cubicweb.uilib import eid_param |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5713
diff
changeset
|
32 |
|
6614
4b9a785df0f7
[web] proper error when no json module available
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6106
diff
changeset
|
33 |
assert json_dumps is not None, 'no json module installed' |
4b9a785df0f7
[web] proper error when no json module available
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6106
diff
changeset
|
34 |
dumps = deprecated('[3.9] use cubicweb.utils.json_dumps instead of dumps')( |
4b9a785df0f7
[web] proper error when no json module available
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6106
diff
changeset
|
35 |
json_dumps) |
0 | 36 |
|
37 |
INTERNAL_FIELD_VALUE = '__cubicweb_internal_field__' |
|
38 |
||
39 |
||
40 |
class stdmsgs(object): |
|
41 |
"""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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
YES = (_('yes'), None) |
414bb8439002
[web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3758
diff
changeset
|
47 |
NO = (_('no'), None) |
0 | 48 |
|
49 |
||
50 |
from logging import getLogger |
|
51 |
LOGGER = getLogger('cubicweb.web') |
|
52 |
||
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
53 |
# XXX deprecated |
0 | 54 |
FACETTES = set() |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
55 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
56 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
57 |
def jsonize(function): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
58 |
def newfunc(*args, **kwargs): |
3758
d43c9709434d
yet another brain fart
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3741
diff
changeset
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
return json_dumps(repr(value)) |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
64 |
return newfunc |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
65 |
|
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
|
66 |
@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
|
67 |
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
|
68 |
"""builds a replacePageChunk-like url |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
69 |
>>> ajax_replace_url('foo', 'Person P') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
70 |
"javascript: replacePageChunk('foo', 'Person%20P');" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
71 |
>>> ajax_replace_url('foo', 'Person P', 'oneline') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
72 |
"javascript: replacePageChunk('foo', 'Person%20P', 'oneline');" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
73 |
>>> 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
|
74 |
"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
|
75 |
>>> 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
|
76 |
"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
|
77 |
""" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
78 |
params = [repr(nodeid), repr(urlquote(rql))] |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
79 |
if extraparams and not vid: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
80 |
params.append("'null'") |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
81 |
elif vid: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
82 |
params.append(repr(vid)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
83 |
if extraparams: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
84 |
params.append(json_dumps(extraparams)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
85 |
if swap: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
86 |
params.append('true') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
87 |
return "javascript: replacePageChunk(%s);" % ', '.join(params) |