1 """CubicWeb web client core. You'll need a apache-modpython or twisted |
1 """CubicWeb web client core. You'll need a apache-modpython or twisted |
2 publisher to get a full CubicWeb web application |
2 publisher to get a full CubicWeb web application |
3 |
3 |
4 |
4 |
5 :organization: Logilab |
5 :organization: Logilab |
6 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
6 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
7 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8 """ |
8 """ |
9 __docformat__ = "restructuredtext en" |
9 __docformat__ = "restructuredtext en" |
|
10 _ = unicode |
10 |
11 |
11 from cubicweb.web._exceptions import * |
12 from decimal import Decimal |
|
13 from datetime import datetime, date, timedelta |
|
14 from simplejson import dumps |
12 |
15 |
13 _ = unicode |
16 from logilab.common.deprecation import obsolete |
|
17 |
|
18 from cubicweb.common.uilib import urlquote |
|
19 from cubicweb.web._exceptions import * |
|
20 |
14 |
21 |
15 INTERNAL_FIELD_VALUE = '__cubicweb_internal_field__' |
22 INTERNAL_FIELD_VALUE = '__cubicweb_internal_field__' |
16 |
23 |
17 |
24 |
18 class stdmsgs(object): |
25 class stdmsgs(object): |
33 |
40 |
34 |
41 |
35 from logging import getLogger |
42 from logging import getLogger |
36 LOGGER = getLogger('cubicweb.web') |
43 LOGGER = getLogger('cubicweb.web') |
37 |
44 |
|
45 # XXX deprecated |
38 FACETTES = set() |
46 FACETTES = set() |
39 |
47 |
40 |
48 |
41 ## FACETTES = set( ( |
49 |
42 ## # (relation, role, target's attribute) |
50 def json_dumps(value): |
43 ## ('created_by', 'subject', 'login'), |
51 if isinstance(value, Decimal): |
44 ## ('in_group', 'subject', 'name'), |
52 value = float(value) |
45 ## ('in_state', 'subject', 'name'), |
53 elif isinstance(value, (date, datetime)): |
46 ## )) |
54 value = value.strftime('%Y-%m-%d %H:%M') |
|
55 elif isinstance(value, timedelta): |
|
56 value = (value.days * 24*60*60) + value.seconds |
|
57 try: |
|
58 return dumps(value) |
|
59 except TypeError: |
|
60 return dumps(repr(value)) |
|
61 |
|
62 def jsonize(function): |
|
63 def newfunc(*args, **kwargs): |
|
64 return json_dumps(function(*args, **kwargs)) |
|
65 return newfunc |
|
66 |
|
67 @obsolete('use req.build_ajax_replace_url() instead') |
|
68 def ajax_replace_url(nodeid, rql, vid=None, swap=False, **extraparams): |
|
69 """builds a replacePageChunk-like url |
|
70 >>> ajax_replace_url('foo', 'Person P') |
|
71 "javascript: replacePageChunk('foo', 'Person%20P');" |
|
72 >>> ajax_replace_url('foo', 'Person P', 'oneline') |
|
73 "javascript: replacePageChunk('foo', 'Person%20P', 'oneline');" |
|
74 >>> ajax_replace_url('foo', 'Person P', 'oneline', name='bar', age=12) |
|
75 "javascript: replacePageChunk('foo', 'Person%20P', 'oneline', {'age':12, 'name':'bar'});" |
|
76 >>> ajax_replace_url('foo', 'Person P', name='bar', age=12) |
|
77 "javascript: replacePageChunk('foo', 'Person%20P', 'null', {'age':12, 'name':'bar'});" |
|
78 """ |
|
79 params = [repr(nodeid), repr(urlquote(rql))] |
|
80 if extraparams and not vid: |
|
81 params.append("'null'") |
|
82 elif vid: |
|
83 params.append(repr(vid)) |
|
84 if extraparams: |
|
85 params.append(json_dumps(extraparams)) |
|
86 if swap: |
|
87 params.append('true') |
|
88 return "javascript: replacePageChunk(%s);" % ', '.join(params) |