author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 21 Oct 2009 10:35:19 +0200 | |
branch | stable |
changeset 3768 | 8c85a2f7f5ad |
parent 3710 | 5bfdb591050a |
child 3720 | 5376aaadd16b |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
"""CubicWeb is a generic framework to quickly build applications which describes |
2 |
relations between entitites. |
|
3 |
||
4 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1030
2ead2111cfab
update license, specify which the version of LGPL under which the code is provided
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1022
diff
changeset
|
7 |
:license: Library General Public License version 2 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
10 |
from cubicweb.__pkginfo__ import version as __version__ |
|
11 |
||
12 |
import __builtin__ |
|
13 |
# '_' is available in builtins to mark internationalized string but should |
|
14 |
# not be used to do the actual translation |
|
15 |
if not hasattr(__builtin__, '_'): |
|
16 |
__builtin__._ = unicode |
|
17 |
||
18 |
CW_SOFTWARE_ROOT = __path__[0] |
|
19 |
||
20 |
import sys, os, logging |
|
21 |
from StringIO import StringIO |
|
22 |
from urllib import quote as urlquote, unquote as urlunquote |
|
23 |
||
24 |
from logilab.common.decorators import cached |
|
1741 | 25 |
from logilab.common.logging_ext import set_log_methods |
0 | 26 |
|
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
27 |
|
0 | 28 |
if os.environ.get('APYCOT_ROOT'): |
29 |
logging.basicConfig(level=logging.CRITICAL) |
|
30 |
else: |
|
31 |
logging.basicConfig() |
|
32 |
||
33 |
||
34 |
set_log_methods(sys.modules[__name__], logging.getLogger('cubicweb')) |
|
35 |
||
36 |
# make all exceptions accessible from the package |
|
37 |
from cubicweb._exceptions import * |
|
38 |
||
39 |
# convert eid to the right type, raise ValueError if it's not a valid eid |
|
40 |
typed_eid = int |
|
41 |
||
42 |
||
43 |
#def log_thread(f, w, a): |
|
44 |
# print f.f_code.co_filename, f.f_code.co_name |
|
45 |
#import threading |
|
46 |
#threading.settrace(log_thread) |
|
47 |
||
48 |
class Binary(StringIO): |
|
49 |
"""customize StringIO to make sure we don't use unicode""" |
|
1954 | 50 |
def __init__(self, buf=''): |
0 | 51 |
assert isinstance(buf, (str, buffer)), \ |
52 |
"Binary objects must use raw strings, not %s" % buf.__class__ |
|
53 |
StringIO.__init__(self, buf) |
|
54 |
||
55 |
def write(self, data): |
|
56 |
assert isinstance(data, (str, buffer)), \ |
|
57 |
"Binary objects must use raw strings, not %s" % data.__class__ |
|
58 |
StringIO.write(self, data) |
|
59 |
||
60 |
||
61 |
class RequestSessionMixIn(object): |
|
62 |
"""mixin class containing stuff shared by server session and web request |
|
63 |
""" |
|
64 |
def __init__(self, vreg): |
|
65 |
self.vreg = vreg |
|
66 |
try: |
|
67 |
encoding = vreg.property_value('ui.encoding') |
|
68 |
except: # no vreg or property not registered |
|
69 |
encoding = 'utf-8' |
|
70 |
self.encoding = encoding |
|
71 |
# cache result of execution for (rql expr / eids), |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
72 |
# should be emptied on commit/rollback of the server session / web |
0 | 73 |
# connection |
74 |
self.local_perm_cache = {} |
|
75 |
||
76 |
def property_value(self, key): |
|
77 |
if self.user: |
|
78 |
return self.user.property_value(key) |
|
79 |
return self.vreg.property_value(key) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
80 |
|
0 | 81 |
def etype_rset(self, etype, size=1): |
82 |
"""return a fake result set for a particular entity type""" |
|
83 |
from cubicweb.rset import ResultSet |
|
84 |
rset = ResultSet([('A',)]*size, '%s X' % etype, |
|
85 |
description=[(etype,)]*size) |
|
1132 | 86 |
def get_entity(row, col=0, etype=etype, req=self, rset=rset): |
87 |
return req.vreg.etype_class(etype)(req, rset, row, col) |
|
0 | 88 |
rset.get_entity = get_entity |
89 |
return self.decorate_rset(rset) |
|
90 |
||
91 |
def eid_rset(self, eid, etype=None): |
|
92 |
"""return a result set for the given eid without doing actual query |
|
93 |
(we have the eid, we can suppose it exists and user has access to the |
|
94 |
entity) |
|
95 |
""" |
|
96 |
from cubicweb.rset import ResultSet |
|
97 |
eid = typed_eid(eid) |
|
98 |
if etype is None: |
|
99 |
etype = self.describe(eid)[0] |
|
100 |
rset = ResultSet([(eid,)], 'Any X WHERE X eid %(x)s', {'x': eid}, |
|
101 |
[(etype,)]) |
|
102 |
return self.decorate_rset(rset) |
|
103 |
||
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
104 |
def empty_rset(self): |
3651
633b8971c95a
fixed cut and pasted docstring
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3634
diff
changeset
|
105 |
"""return an empty result set. This is used e.g. to substitute |
633b8971c95a
fixed cut and pasted docstring
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3634
diff
changeset
|
106 |
to a real result set if the user doesn't have permission to |
633b8971c95a
fixed cut and pasted docstring
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3634
diff
changeset
|
107 |
access the results of a query. |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
108 |
""" |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
109 |
from cubicweb.rset import ResultSet |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
110 |
return self.decorate_rset(ResultSet([], 'Any X WHERE X eid -1')) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
111 |
|
0 | 112 |
def entity_from_eid(self, eid, etype=None): |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
113 |
try: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
114 |
return self.entity_cache(eid) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
115 |
except KeyError: |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
116 |
rset = self.eid_rset(eid, etype) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
117 |
entity = rset.get_entity(0, 0) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
118 |
self.set_entity_cache(entity) |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
119 |
return entity |
0 | 120 |
|
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
121 |
def entity_cache(self, eid): |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
122 |
raise KeyError |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
123 |
def set_entity_cache(self, entity): |
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
124 |
pass |
2919
662f35236d1c
new create_entity method, temporarily on base request (later on cw entity manager or as factory method)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
125 |
|
3684
c0a854810942
support _cw_unsafe as set_attributes/set_relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
126 |
def create_entity(self, etype, _cw_unsafe=False, **kwargs): |
3601
d77025be6f06
[doc] added an example of use of create_entity in a shell session
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3111
diff
changeset
|
127 |
"""add a new entity of the given type |
3684
c0a854810942
support _cw_unsafe as set_attributes/set_relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
128 |
|
3601
d77025be6f06
[doc] added an example of use of create_entity in a shell session
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3111
diff
changeset
|
129 |
Example (in a shell session): |
d77025be6f06
[doc] added an example of use of create_entity in a shell session
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3111
diff
changeset
|
130 |
|
3667
3a8caefec1fc
use unicode in the example of create_entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3651
diff
changeset
|
131 |
c = create_entity('Company', name=u'Logilab') |
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
132 |
create_entity('Person', works_for=c, firstname=u'John', lastname=u'Doe') |
3601
d77025be6f06
[doc] added an example of use of create_entity in a shell session
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3111
diff
changeset
|
133 |
|
d77025be6f06
[doc] added an example of use of create_entity in a shell session
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
3111
diff
changeset
|
134 |
""" |
3684
c0a854810942
support _cw_unsafe as set_attributes/set_relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
135 |
if _cw_unsafe: |
c0a854810942
support _cw_unsafe as set_attributes/set_relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
136 |
execute = self.unsafe_execute |
c0a854810942
support _cw_unsafe as set_attributes/set_relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
137 |
else: |
c0a854810942
support _cw_unsafe as set_attributes/set_relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
138 |
execute = self.execute |
2919
662f35236d1c
new create_entity method, temporarily on base request (later on cw entity manager or as factory method)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
139 |
rql = 'INSERT %s X' % etype |
662f35236d1c
new create_entity method, temporarily on base request (later on cw entity manager or as factory method)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
140 |
relations = [] |
3634
a2d00ff6eb68
don't duplicates restrictions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3601
diff
changeset
|
141 |
restrictions = set() |
2919
662f35236d1c
new create_entity method, temporarily on base request (later on cw entity manager or as factory method)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
142 |
cachekey = [] |
3670
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
143 |
pending_relations = [] |
3710
5bfdb591050a
should remove entities from kwargs (won't go through pyro)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3684
diff
changeset
|
144 |
for attr, value in kwargs.items(): |
3670
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
145 |
if isinstance(value, (tuple, list, set, frozenset)): |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
146 |
if len(value) == 1: |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
147 |
value = iter(value).next() |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
148 |
else: |
3710
5bfdb591050a
should remove entities from kwargs (won't go through pyro)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3684
diff
changeset
|
149 |
del kwargs[attr] |
3670
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
150 |
pending_relations.append( (attr, value) ) |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
151 |
continue |
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
152 |
if hasattr(value, 'eid'): # non final relation |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
153 |
rvar = attr.upper() |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
154 |
# XXX safer detection of object relation |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
155 |
if attr.startswith('reverse_'): |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
156 |
relations.append('%s %s X' % (rvar, attr[len('reverse_'):])) |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
157 |
else: |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
158 |
relations.append('X %s %s' % (attr, rvar)) |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
159 |
restriction = '%s eid %%(%s)s' % (rvar, attr) |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
160 |
if not restriction in restrictions: |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
161 |
restrictions.add(restriction) |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
162 |
cachekey.append(attr) |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
163 |
kwargs[attr] = value.eid |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
164 |
else: # attribute |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3667
diff
changeset
|
165 |
relations.append('X %s %%(%s)s' % (attr, attr)) |
2919
662f35236d1c
new create_entity method, temporarily on base request (later on cw entity manager or as factory method)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
166 |
if relations: |
662f35236d1c
new create_entity method, temporarily on base request (later on cw entity manager or as factory method)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
167 |
rql = '%s: %s' % (rql, ', '.join(relations)) |
662f35236d1c
new create_entity method, temporarily on base request (later on cw entity manager or as factory method)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
168 |
if restrictions: |
662f35236d1c
new create_entity method, temporarily on base request (later on cw entity manager or as factory method)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
169 |
rql = '%s WHERE %s' % (rql, ', '.join(restrictions)) |
3684
c0a854810942
support _cw_unsafe as set_attributes/set_relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
170 |
created = execute(rql, kwargs, cachekey).get_entity(0, 0) |
3670
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
171 |
for attr, values in pending_relations: |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
172 |
if attr.startswith('reverse_'): |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
173 |
restr = 'Y %s X' % attr[len('reverse_'):] |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
174 |
else: |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
175 |
restr = 'X %s Y' % attr |
3684
c0a854810942
support _cw_unsafe as set_attributes/set_relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
176 |
execute('SET %s WHERE X eid %%(x)s, Y eid IN (%s)' % ( |
3670
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
177 |
restr, ','.join(str(r.eid) for r in values)), |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
178 |
{'x': created.eid}, 'x') |
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
179 |
return created |
2919
662f35236d1c
new create_entity method, temporarily on base request (later on cw entity manager or as factory method)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2705
diff
changeset
|
180 |
|
0 | 181 |
# url generation methods ################################################## |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
182 |
|
2059
af33833d7571
absolute_url / build_url refactoring to avoid potential name clash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
183 |
def build_url(self, *args, **kwargs): |
0 | 184 |
"""return an absolute URL using params dictionary key/values as URL |
185 |
parameters. Values are automatically URL quoted, and the |
|
186 |
publishing method to use may be specified or will be guessed. |
|
187 |
""" |
|
2059
af33833d7571
absolute_url / build_url refactoring to avoid potential name clash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
188 |
# use *args since we don't want first argument to be "anonymous" to |
af33833d7571
absolute_url / build_url refactoring to avoid potential name clash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
189 |
# avoid potential clash with kwargs |
af33833d7571
absolute_url / build_url refactoring to avoid potential name clash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
190 |
assert len(args) == 1, 'only 0 or 1 non-named-argument expected' |
af33833d7571
absolute_url / build_url refactoring to avoid potential name clash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
191 |
method = args[0] |
af33833d7571
absolute_url / build_url refactoring to avoid potential name clash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
192 |
base_url = kwargs.pop('base_url', None) |
0 | 193 |
if base_url is None: |
194 |
base_url = self.base_url() |
|
195 |
if '_restpath' in kwargs: |
|
196 |
assert method == 'view', method |
|
197 |
path = kwargs.pop('_restpath') |
|
198 |
else: |
|
199 |
path = method |
|
200 |
if not kwargs: |
|
201 |
return u'%s%s' % (base_url, path) |
|
202 |
return u'%s%s?%s' % (base_url, path, self.build_url_params(**kwargs)) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
203 |
|
0 | 204 |
|
205 |
def build_url_params(self, **kwargs): |
|
206 |
"""return encoded params to incorporate them in an URL""" |
|
207 |
args = [] |
|
208 |
for param, values in kwargs.items(): |
|
209 |
if not isinstance(values, (list, tuple)): |
|
210 |
values = (values,) |
|
211 |
for value in values: |
|
212 |
args.append(u'%s=%s' % (param, self.url_quote(value))) |
|
213 |
return '&'.join(args) |
|
214 |
||
215 |
def url_quote(self, value, safe=''): |
|
216 |
"""urllib.quote is not unicode safe, use this method to do the |
|
217 |
necessary encoding / decoding. Also it's designed to quote each |
|
218 |
part of a url path and so the '/' character will be encoded as well. |
|
219 |
""" |
|
220 |
if isinstance(value, unicode): |
|
221 |
quoted = urlquote(value.encode(self.encoding), safe=safe) |
|
222 |
return unicode(quoted, self.encoding) |
|
223 |
return urlquote(str(value), safe=safe) |
|
224 |
||
225 |
def url_unquote(self, quoted): |
|
226 |
"""returns a unicode unquoted string |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
227 |
|
0 | 228 |
decoding is based on `self.encoding` which is the encoding |
229 |
used in `url_quote` |
|
230 |
""" |
|
231 |
if isinstance(quoted, unicode): |
|
232 |
quoted = quoted.encode(self.encoding) |
|
233 |
try: |
|
234 |
return unicode(urlunquote(quoted), self.encoding) |
|
235 |
except UnicodeDecodeError: # might occurs on manually typed URLs |
|
236 |
return unicode(urlunquote(quoted), 'iso-8859-1') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
237 |
|
0 | 238 |
|
239 |
# session's user related methods ##################################### |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
240 |
|
0 | 241 |
@cached |
242 |
def user_data(self): |
|
243 |
"""returns a dictionnary with this user's information""" |
|
244 |
userinfo = {} |
|
245 |
if self.is_internal_session: |
|
246 |
userinfo['login'] = "cubicweb" |
|
247 |
userinfo['name'] = "cubicweb" |
|
248 |
userinfo['email'] = "" |
|
249 |
return userinfo |
|
250 |
user = self.actual_session().user |
|
251 |
userinfo['login'] = user.login |
|
3111
7b405bb305ab
[notification] can't see valid reason for this...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2919
diff
changeset
|
252 |
userinfo['name'] = user.name() |
7b405bb305ab
[notification] can't see valid reason for this...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2919
diff
changeset
|
253 |
userinfo['email'] = user.get_email() |
0 | 254 |
return userinfo |
255 |
||
256 |
def is_internal_session(self): |
|
257 |
"""overrided on the server-side""" |
|
258 |
return False |
|
259 |
||
260 |
# abstract methods to override according to the web front-end ############# |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
261 |
|
0 | 262 |
def base_url(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
263 |
"""return the root url of the instance""" |
0 | 264 |
raise NotImplementedError |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
265 |
|
0 | 266 |
def decorate_rset(self, rset): |
267 |
"""add vreg/req (at least) attributes to the given result set """ |
|
268 |
raise NotImplementedError |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
269 |
|
0 | 270 |
def describe(self, eid): |
271 |
"""return a tuple (type, sourceuri, extid) for the entity with id <eid>""" |
|
272 |
raise NotImplementedError |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
273 |
|
0 | 274 |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
275 |
# XXX 2.45 is allowing nicer entity type names, use this map for bw compat |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
276 |
ETYPE_NAME_MAP = {# 3.2 migration |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
277 |
'ECache': 'CWCache', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
278 |
'EUser': 'CWUser', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
279 |
'EGroup': 'CWGroup', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
280 |
'EProperty': 'CWProperty', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
281 |
'EFRDef': 'CWAttribute', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
282 |
'ENFRDef': 'CWRelation', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
283 |
'ERType': 'CWRType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
284 |
'EEType': 'CWEType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
285 |
'EConstraintType': 'CWConstraintType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
286 |
'EConstraint': 'CWConstraint', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
287 |
'EPermission': 'CWPermission', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
288 |
# 2.45 migration |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
289 |
'Eetype': 'CWEType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
290 |
'Ertype': 'CWRType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
291 |
'Efrdef': 'CWAttribute', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
292 |
'Enfrdef': 'CWRelation', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
293 |
'Econstraint': 'CWConstraint', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
294 |
'Econstrainttype': 'CWConstraintType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
295 |
'Epermission': 'CWPermission', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
296 |
'Egroup': 'CWGroup', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
297 |
'Euser': 'CWUser', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
298 |
'Eproperty': 'CWProperty', |
0 | 299 |
'Emailaddress': 'EmailAddress', |
300 |
'Rqlexpression': 'RQLExpression', |
|
301 |
'Trinfo': 'TrInfo', |
|
302 |
} |
|
303 |
||
304 |
||
305 |
||
306 |
# XXX cubic web cube migration map |
|
307 |
CW_MIGRATION_MAP = {'erudi': 'cubicweb', |
|
308 |
||
309 |
'eaddressbook': 'addressbook', |
|
310 |
'ebasket': 'basket', |
|
311 |
'eblog': 'blog', |
|
312 |
'ebook': 'book', |
|
313 |
'ecomment': 'comment', |
|
314 |
'ecompany': 'company', |
|
315 |
'econference': 'conference', |
|
316 |
'eemail': 'email', |
|
317 |
'eevent': 'event', |
|
318 |
'eexpense': 'expense', |
|
319 |
'efile': 'file', |
|
320 |
'einvoice': 'invoice', |
|
321 |
'elink': 'link', |
|
322 |
'emailinglist': 'mailinglist', |
|
323 |
'eperson': 'person', |
|
324 |
'eshopcart': 'shopcart', |
|
325 |
'eskillmat': 'skillmat', |
|
326 |
'etask': 'task', |
|
327 |
'eworkcase': 'workcase', |
|
328 |
'eworkorder': 'workorder', |
|
329 |
'ezone': 'zone', |
|
330 |
'i18ncontent': 'i18ncontent', |
|
331 |
'svnfile': 'vcsfile', |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
332 |
|
0 | 333 |
'eclassschemes': 'keyword', |
334 |
'eclassfolders': 'folder', |
|
335 |
'eclasstags': 'tag', |
|
336 |
||
337 |
'jpl': 'jpl', |
|
338 |
'jplintra': 'jplintra', |
|
339 |
'jplextra': 'jplextra', |
|
340 |
'jplorg': 'jplorg', |
|
341 |
'jplrecia': 'jplrecia', |
|
342 |
'crm': 'crm', |
|
343 |
'agueol': 'agueol', |
|
344 |
'docaster': 'docaster', |
|
345 |
'asteretud': 'asteretud', |
|
346 |
} |
|
231
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
347 |
|
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
348 |
def neg_role(role): |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
349 |
if role == 'subject': |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
350 |
return 'object' |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
351 |
return 'subject' |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
352 |
|
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
353 |
def role(obj): |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
354 |
try: |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
355 |
return obj.role |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
356 |
except AttributeError: |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
357 |
return neg_role(obj.target) |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
358 |
|
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
359 |
def target(obj): |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
360 |
try: |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
361 |
return obj.target |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
362 |
except AttributeError: |
d740f5f55d30
some mini function to ease role (subject/object) manipulation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
363 |
return neg_role(obj.role) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
364 |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
365 |
def underline_title(title, car='-'): |
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
366 |
return title+'\n'+(car*len(title)) |
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
367 |
|
2683
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
368 |
|
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
369 |
class CubicWebEventManager(object): |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
370 |
"""simple event / callback manager. |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
371 |
|
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
372 |
Typical usage to register a callback:: |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
373 |
|
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
374 |
>>> from cubicweb import CW_EVENT_MANAGER |
2705
30bcdbd92820
[events] renamed source-reload into registry-reload to avoid potential confusions with datasources
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2689
diff
changeset
|
375 |
>>> CW_EVENT_MANAGER.bind('after-registry-reload', mycallback) |
2683
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
376 |
|
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
377 |
Typical usage to emit an event:: |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
378 |
|
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
379 |
>>> from cubicweb import CW_EVENT_MANAGER |
2705
30bcdbd92820
[events] renamed source-reload into registry-reload to avoid potential confusions with datasources
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2689
diff
changeset
|
380 |
>>> CW_EVENT_MANAGER.emit('after-registry-reload') |
2683
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
381 |
|
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
382 |
emit() accepts an additional context parameter that will be passed |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
383 |
to the callback if specified (and only in that case) |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
384 |
""" |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
385 |
def __init__(self): |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
386 |
self.callbacks = {} |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
387 |
|
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
388 |
def bind(self, event, callback, *args, **kwargs): |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
389 |
self.callbacks.setdefault(event, []).append( (callback, args, kwargs) ) |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
390 |
|
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
391 |
def emit(self, event, context=None): |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
392 |
for callback, args, kwargs in self.callbacks.get(event, ()): |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
393 |
if context is None: |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
394 |
callback(*args, **kwargs) |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
395 |
else: |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
396 |
callback(context, *args, **kwargs) |
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
397 |
|
52b1a86c1913
introduce a new CubicwebEventManager
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2647
diff
changeset
|
398 |
CW_EVENT_MANAGER = CubicWebEventManager() |
2689
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
399 |
|
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
400 |
def onevent(event): |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
401 |
"""decorator to ease event / callback binding |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
402 |
|
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
403 |
>>> from cubicweb import onevent |
2705
30bcdbd92820
[events] renamed source-reload into registry-reload to avoid potential confusions with datasources
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2689
diff
changeset
|
404 |
>>> @onevent('before-registry-reload') |
2689
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
405 |
... def mycallback(): |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
406 |
... print 'hello' |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
407 |
... |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
408 |
>>> |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
409 |
""" |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
410 |
def _decorator(func): |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
411 |
CW_EVENT_MANAGER.bind(event, func) |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
412 |
return func |
44f041222d0f
[autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2683
diff
changeset
|
413 |
return _decorator |