author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 18 Aug 2009 09:25:26 +0200 | |
changeset 2901 | 8f4d495c94c2 |
parent 2808 | 497424219fb0 |
child 2968 | 0e3460341023 |
permissions | -rw-r--r-- |
0 | 1 |
"""CubicWeb web client core. You'll need a apache-modpython or twisted |
2 |
publisher to get a full CubicWeb web application |
|
3 |
||
4 |
||
5 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1801
diff
changeset
|
6 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 7 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1801
diff
changeset
|
8 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 9 |
""" |
10 |
__docformat__ = "restructuredtext en" |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
11 |
_ = unicode |
0 | 12 |
|
1645 | 13 |
from decimal import Decimal |
14 |
from datetime import datetime, date, timedelta |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
15 |
from simplejson import dumps |
2808
497424219fb0
fix urlquote imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2788
diff
changeset
|
16 |
from urllib import quote as urlquote |
0 | 17 |
|
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
18 |
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
|
19 |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
20 |
from cubicweb.web._exceptions import * |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
21 |
|
0 | 22 |
|
23 |
INTERNAL_FIELD_VALUE = '__cubicweb_internal_field__' |
|
24 |
||
25 |
||
26 |
class stdmsgs(object): |
|
27 |
"""standard ui message (in a class for bw compat)""" |
|
28 |
BUTTON_OK = _('button_ok') |
|
29 |
BUTTON_APPLY = _('button_apply') |
|
30 |
BUTTON_CANCEL = _('button_cancel') |
|
31 |
BUTTON_DELETE = _('button_delete') |
|
32 |
YES = _('yes') |
|
33 |
NO = _('no') |
|
34 |
||
35 |
||
36 |
def eid_param(name, eid): |
|
37 |
assert eid is not None |
|
38 |
if eid is None: |
|
39 |
eid = '' |
|
40 |
return '%s:%s' % (name, eid) |
|
41 |
||
42 |
||
43 |
from logging import getLogger |
|
44 |
LOGGER = getLogger('cubicweb.web') |
|
45 |
||
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
46 |
# XXX deprecated |
0 | 47 |
FACETTES = set() |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
48 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
49 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
50 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
51 |
def json_dumps(value): |
1645 | 52 |
if isinstance(value, Decimal): |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
53 |
value = float(value) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
54 |
elif isinstance(value, (date, datetime)): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
55 |
value = value.strftime('%Y-%m-%d %H:%M') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
56 |
elif isinstance(value, timedelta): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
57 |
value = (value.days * 24*60*60) + value.seconds |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
58 |
try: |
1645 | 59 |
return dumps(value) |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
60 |
except TypeError: |
1645 | 61 |
return dumps(repr(value)) |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
62 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
63 |
def jsonize(function): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
64 |
def newfunc(*args, **kwargs): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
65 |
return json_dumps(function(*args, **kwargs)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
66 |
return newfunc |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
67 |
|
2788
8d3dbe577d3a
R put version info in deprecation warnings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2613
diff
changeset
|
68 |
@deprecated('[3.4] use req.build_ajax_replace_url() instead') |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
69 |
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
|
70 |
"""builds a replacePageChunk-like url |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
71 |
>>> ajax_replace_url('foo', 'Person P') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
72 |
"javascript: replacePageChunk('foo', 'Person%20P');" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
73 |
>>> ajax_replace_url('foo', 'Person P', 'oneline') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
74 |
"javascript: replacePageChunk('foo', 'Person%20P', 'oneline');" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
75 |
>>> 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
|
76 |
"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
|
77 |
>>> 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
|
78 |
"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
|
79 |
""" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
80 |
params = [repr(nodeid), repr(urlquote(rql))] |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
81 |
if extraparams and not vid: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
82 |
params.append("'null'") |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
83 |
elif vid: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
84 |
params.append(repr(vid)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
85 |
if extraparams: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
86 |
params.append(json_dumps(extraparams)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
87 |
if swap: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
88 |
params.append('true') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
89 |
return "javascript: replacePageChunk(%s);" % ', '.join(params) |