author | sylvain.thenault@logilab.fr |
Mon, 04 May 2009 11:47:33 +0200 | |
branch | tls-sprint |
changeset 1635 | 866563e2d0fc |
parent 1181 | 620ec8e6ae19 |
child 1645 | 374586978230 |
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 |
|
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
6 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 7 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8 |
""" |
|
9 |
__docformat__ = "restructuredtext en" |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
10 |
_ = unicode |
0 | 11 |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
12 |
from simplejson import dumps |
0 | 13 |
|
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
14 |
from cubicweb.web._exceptions import * |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
15 |
|
0 | 16 |
|
17 |
INTERNAL_FIELD_VALUE = '__cubicweb_internal_field__' |
|
18 |
||
19 |
||
20 |
class stdmsgs(object): |
|
21 |
"""standard ui message (in a class for bw compat)""" |
|
22 |
BUTTON_OK = _('button_ok') |
|
23 |
BUTTON_APPLY = _('button_apply') |
|
24 |
BUTTON_CANCEL = _('button_cancel') |
|
25 |
BUTTON_DELETE = _('button_delete') |
|
26 |
YES = _('yes') |
|
27 |
NO = _('no') |
|
28 |
||
29 |
||
30 |
def eid_param(name, eid): |
|
31 |
assert eid is not None |
|
32 |
if eid is None: |
|
33 |
eid = '' |
|
34 |
return '%s:%s' % (name, eid) |
|
35 |
||
36 |
||
37 |
from logging import getLogger |
|
38 |
LOGGER = getLogger('cubicweb.web') |
|
39 |
||
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
40 |
# XXX deprecated |
0 | 41 |
FACETTES = set() |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
42 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
43 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
44 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
45 |
def json_dumps(value): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
46 |
if isinstance(value, decimal.Decimal): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
47 |
value = float(value) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
48 |
elif isinstance(value, (date, datetime)): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
49 |
value = value.strftime('%Y-%m-%d %H:%M') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
50 |
elif isinstance(value, timedelta): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
51 |
value = (value.days * 24*60*60) + value.seconds |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
52 |
try: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
53 |
return simplejson.dumps(value) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
54 |
except TypeError: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
55 |
return simplejson.dumps(repr(value)) |
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): |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
59 |
return json_dumps(function(*args, **kwargs)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
60 |
return newfunc |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
61 |
|
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
62 |
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
|
63 |
"""builds a replacePageChunk-like url |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
64 |
>>> ajax_replace_url('foo', 'Person P') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
65 |
"javascript: replacePageChunk('foo', 'Person%20P');" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
66 |
>>> ajax_replace_url('foo', 'Person P', 'oneline') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
67 |
"javascript: replacePageChunk('foo', 'Person%20P', 'oneline');" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
68 |
>>> 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
|
69 |
"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
|
70 |
>>> 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
|
71 |
"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
|
72 |
""" |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
73 |
params = [repr(nodeid), repr(urlquote(rql))] |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
74 |
if extraparams and not vid: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
75 |
params.append("'null'") |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
76 |
elif vid: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
77 |
params.append(repr(vid)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
78 |
if extraparams: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
79 |
params.append(json_dumps(extraparams)) |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
80 |
if swap: |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
81 |
params.append('true') |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1181
diff
changeset
|
82 |
return "javascript: replacePageChunk(%s);" % ', '.join(params) |