author | Samuel Trégouët <samuel.tregouet@logilab.fr> |
Fri, 10 Jan 2014 15:02:19 +0100 | |
changeset 9391 | 5537c3b64841 |
parent 8930 | 6a02be304486 |
child 10496 | e95b559a06a2 |
permissions | -rw-r--r-- |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
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:
5315
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
18 |
""" |
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5147
diff
changeset
|
19 |
.. _appobject: |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5147
diff
changeset
|
20 |
|
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
21 |
The `AppObject` class |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
22 |
--------------------- |
0 | 23 |
|
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
24 |
The AppObject class is the base class for all dynamically loaded objects |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
25 |
(application objects) accessible through the vregistry. |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
26 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
27 |
We can find a certain number of attributes and methods defined in this class and |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
28 |
common to all the application objects. |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
29 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
30 |
.. autoclass:: AppObject |
0 | 31 |
""" |
32 |
__docformat__ = "restructuredtext en" |
|
33 |
||
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
34 |
from logging import getLogger |
0 | 35 |
|
8240
506ab2e8aeca
[vreg] restore bw compat, eg container expect to find Selector in appobject module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8190
diff
changeset
|
36 |
from logilab.common.deprecation import deprecated, class_renamed |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
37 |
from logilab.common.logging_ext import set_log_methods |
447 | 38 |
|
8664
29652410c317
[appobject] introduce RegistrableObject base class (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8654
diff
changeset
|
39 |
# first line imports for bw compat |
29652410c317
[appobject] introduce RegistrableObject base class (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8654
diff
changeset
|
40 |
from logilab.common.registry import (objectify_predicate, traced_selection, Predicate, |
29652410c317
[appobject] introduce RegistrableObject base class (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8654
diff
changeset
|
41 |
RegistrableObject, yes) |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
42 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
43 |
|
8654
7021bba2dcf2
[appobject] cleanup module (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8240
diff
changeset
|
44 |
objectify_selector = deprecated('[3.15] objectify_selector has been ' |
7021bba2dcf2
[appobject] cleanup module (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8240
diff
changeset
|
45 |
'renamed to objectify_predicates in ' |
7021bba2dcf2
[appobject] cleanup module (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8240
diff
changeset
|
46 |
'logilab.common.registry')(objectify_predicate) |
7021bba2dcf2
[appobject] cleanup module (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8240
diff
changeset
|
47 |
traced_selection = deprecated('[3.15] traced_selection has been ' |
7021bba2dcf2
[appobject] cleanup module (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8240
diff
changeset
|
48 |
'moved to logilab.common.registry')(traced_selection) |
7021bba2dcf2
[appobject] cleanup module (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8240
diff
changeset
|
49 |
Selector = class_renamed('Selector', Predicate, |
7021bba2dcf2
[appobject] cleanup module (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8240
diff
changeset
|
50 |
'[3.15] Selector has been renamed to Predicate ' |
7021bba2dcf2
[appobject] cleanup module (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8240
diff
changeset
|
51 |
'in logilab.common.registry') |
0 | 52 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
53 |
@deprecated('[3.15] lltrace decorator can now be removed') |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
54 |
def lltrace(func): |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
55 |
return func |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
56 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
57 |
# the base class for all appobjects ############################################ |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
58 |
|
8664
29652410c317
[appobject] introduce RegistrableObject base class (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8654
diff
changeset
|
59 |
class AppObject(RegistrableObject): |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
60 |
"""This is the base class for CubicWeb application objects which are |
8664
29652410c317
[appobject] introduce RegistrableObject base class (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8654
diff
changeset
|
61 |
selected in a request context. |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
62 |
|
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
63 |
The following attributes should be set on concrete appobject classes: |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
64 |
|
2825 | 65 |
At selection time, the following attributes are set on the instance: |
66 |
||
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
67 |
:attr:`_cw` |
2825 | 68 |
current request |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
69 |
:attr:`cw_extra_kwargs` |
2825 | 70 |
other received arguments |
0 | 71 |
|
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
72 |
And also the following, only if `rset` is found in arguments (in which case |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
73 |
rset/row/col will be removed from `cwextra_kwargs`): |
2825 | 74 |
|
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
75 |
:attr:`cw_rset` |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
76 |
context result set or None |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
77 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
78 |
:attr:`cw_row` |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
79 |
if a result set is set and the context is about a particular cell in the |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
80 |
result set, and not the result set as a whole, specify the row number we |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
81 |
are interested in, else None |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
82 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
83 |
:attr:`cw_col` |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
84 |
if a result set is set and the context is about a particular cell in the |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
85 |
result set, and not the result set as a whole, specify the col number we |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
86 |
are interested in, else None |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
87 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
88 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
89 |
.. Note:: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
90 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
91 |
* do not inherit directly from this class but from a more specific class |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
92 |
such as `AnyEntity`, `EntityView`, `AnyRsetView`, `Action`... |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
93 |
|
0 | 94 |
""" |
805
6e99feeba28b
set a default selector on base app objects class
sylvain.thenault@logilab.fr
parents:
802
diff
changeset
|
95 |
__select__ = yes() |
0 | 96 |
|
97 |
@classmethod |
|
2820
66b31686d92b
rename registered to __registered__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2819
diff
changeset
|
98 |
def __registered__(cls, registry): |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
99 |
"""called by the registry when the appobject has been registered. |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
100 |
|
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
101 |
It must return the object that will be actually registered (this may be |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
102 |
the right hook to create an instance for example). By default the |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
103 |
appobject is returned without any transformation. |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
104 |
""" |
7990
a673d1d9a738
[diet] drop pre 3.6 API compatibility (but attempt to keep data cmopatibility). Closes #2017916
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7879
diff
changeset
|
105 |
pdefs = getattr(cls, 'cw_property_defs', {}) |
2802
2251b4aee54a
should still call .items
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2799
diff
changeset
|
106 |
for propid, pdef in pdefs.items(): |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
107 |
pdef = pdef.copy() # may be shared |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
108 |
pdef['default'] = getattr(cls, propid, pdef['default']) |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
109 |
pdef['sitewide'] = getattr(cls, 'site_wide', pdef.get('sitewide')) |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
110 |
registry.vreg.register_property(cls._cwpropkey(propid), **pdef) |
4716
55b6a3262071
fix some pylint detected errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4568
diff
changeset
|
111 |
assert callable(cls.__select__), cls |
0 | 112 |
return cls |
1524 | 113 |
|
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
114 |
def __init__(self, req, **extra): |
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
115 |
super(AppObject, self).__init__() |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2833
diff
changeset
|
116 |
self._cw = req |
2822
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
117 |
try: |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
118 |
self.cw_rset = extra.pop('rset') |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
119 |
self.cw_row = extra.pop('row', None) |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
120 |
self.cw_col = extra.pop('col', None) |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
121 |
except KeyError: |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
122 |
pass |
f26578339214
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2821
diff
changeset
|
123 |
self.cw_extra_kwargs = extra |
1524 | 124 |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
125 |
# persistent class properties ############################################## |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
126 |
# |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
127 |
# optional `cw_property_defs` dict on a class defines available persistent |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
128 |
# properties for this class: |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
129 |
# |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
130 |
# * key: id of the property (the actual CWProperty key is build using |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
131 |
# <registry name>.<obj id>.<property id> |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
132 |
# * value: tuple (property type, vocabfunc, default value, property description) |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
133 |
# possible types are those used by `logilab.common.configuration` |
0 | 134 |
# |
135 |
# notice that when it exists multiple objects with the same id (adaptation, |
|
136 |
# overriding) only the first encountered definition is considered, so those |
|
137 |
# objects can't try to have different default values for instance. |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
138 |
# |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2811
diff
changeset
|
139 |
# you can then access to a property value using self.cw_propval, where self |
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2811
diff
changeset
|
140 |
# is an instance of class |
1524 | 141 |
|
0 | 142 |
@classmethod |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
143 |
def _cwpropkey(cls, propid): |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
144 |
"""return cw property key for the property of the given id for this |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
145 |
class |
0 | 146 |
""" |
3399
2b84f4adb6f8
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3396
diff
changeset
|
147 |
return '%s.%s.%s' % (cls.__registry__, cls.__regid__, propid) |
1524 | 148 |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
149 |
def cw_propval(self, propid): |
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
150 |
"""return cw property value associated to key |
1524 | 151 |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
152 |
<cls.__registry__>.<cls.id>.<propid> |
0 | 153 |
""" |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3399
diff
changeset
|
154 |
return self._cw.property_value(self._cwpropkey(propid)) |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
155 |
|
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6870
diff
changeset
|
156 |
# these are overridden by set_log_methods below |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6870
diff
changeset
|
157 |
# only defining here to prevent pylint from complaining |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6870
diff
changeset
|
158 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6870
diff
changeset
|
159 |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2656
diff
changeset
|
160 |
set_log_methods(AppObject, getLogger('cubicweb.appobject')) |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
161 |
|
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
162 |
# defined here to avoid warning on usage on the AppObject class |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
163 |
yes = deprecated('[3.15] yes has been moved to logilab.common.registry')(yes) |