author | Julien Cristau <julien.cristau@logilab.fr> |
Thu, 13 Jun 2013 12:03:59 +0200 | |
changeset 9005 | 63cf580accfc |
parent 8930 | 6a02be304486 |
child 9256 | 697a8181ba30 |
child 9926 | 93a44cf0d030 |
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
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:
5306
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
18 |
""".. RegistryStore: |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
19 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
20 |
The `RegistryStore` |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
21 |
------------------- |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
22 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
23 |
The `RegistryStore` can be seen as a two-level dictionary. It contains |
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
24 |
all dynamically loaded objects (subclasses of :ref:`appobject`) to |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
25 |
build a |cubicweb| application. Basically: |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
26 |
|
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
27 |
* the first level key returns a *registry*. This key corresponds to the |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
28 |
`__registry__` attribute of application object classes |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
29 |
|
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
30 |
* the second level key returns a list of application objects which |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
31 |
share the same identifier. This key corresponds to the `__regid__` |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
32 |
attribute of application object classes. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
33 |
|
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
34 |
A *registry* holds a specific kind of application objects. There is |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
35 |
for instance a registry for entity classes, another for views, etc... |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
36 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
37 |
The `RegistryStore` has two main responsibilities: |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
38 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
39 |
- being the access point to all registries |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
40 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
41 |
- handling the registration process at startup time, and during automatic |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
42 |
reloading in debug mode. |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
43 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
44 |
.. _AppObjectRecording: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
45 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
46 |
Details of the recording process |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
47 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
48 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
49 |
.. index:: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
50 |
vregistry: registration_callback |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
51 |
|
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
52 |
On startup, |cubicweb| loads application objects defined in its library |
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
53 |
and in cubes used by the instance. Application objects from the |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
54 |
library are loaded first, then those provided by cubes are loaded in |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
55 |
dependency order (e.g. if your cube depends on an other, objects from |
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
56 |
the dependency will be loaded first). The layout of the modules or packages |
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
57 |
in a cube is explained in :ref:`cubelayout`. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
58 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
59 |
For each module: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
60 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
61 |
* by default all objects are registered automatically |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
62 |
|
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
63 |
* if some objects have to replace other objects, or have to be |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
64 |
included only if some condition is met, you'll have to define a |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
65 |
`registration_callback(vreg)` function in your module and explicitly |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
66 |
register **all objects** in this module, using the api defined |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
67 |
below. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
68 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
69 |
.. Note:: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
70 |
Once the function `registration_callback(vreg)` is implemented in a module, |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
71 |
all the objects from this module have to be explicitly registered as it |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
72 |
disables the automatic objects registration. |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
73 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
74 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
75 |
API for objects registration |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
76 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
77 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
78 |
Here are the registration methods that you can use in the `registration_callback` |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
79 |
to register your objects to the `RegistryStore` instance given as argument (usually |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
80 |
named `vreg`): |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
81 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
82 |
.. automethod:: cubicweb.cwvreg.CWRegistryStore.register_all |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
83 |
.. automethod:: cubicweb.cwvreg.CWRegistryStore.register_and_replace |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
84 |
.. automethod:: cubicweb.cwvreg.CWRegistryStore.register |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
85 |
.. automethod:: cubicweb.cwvreg.CWRegistryStore.unregister |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
86 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
87 |
Examples: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
88 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
89 |
.. sourcecode:: python |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
90 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
91 |
# web/views/basecomponents.py |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
92 |
def registration_callback(vreg): |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
93 |
# register everything in the module except SeeAlsoComponent |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
94 |
vreg.register_all(globals().itervalues(), __name__, (SeeAlsoVComponent,)) |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
95 |
# conditionally register SeeAlsoVComponent |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
96 |
if 'see_also' in vreg.schema: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
97 |
vreg.register(SeeAlsoVComponent) |
0 | 98 |
|
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
99 |
In this example, we register all application object classes defined in the module |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
100 |
except `SeeAlsoVComponent`. This class is then registered only if the 'see_also' |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
101 |
relation type is defined in the instance'schema. |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
102 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
103 |
.. sourcecode:: python |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
104 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
105 |
# goa/appobjects/sessions.py |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
106 |
def registration_callback(vreg): |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
107 |
vreg.register(SessionsCleaner) |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
108 |
# replace AuthenticationManager by GAEAuthenticationManager |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
109 |
vreg.register_and_replace(GAEAuthenticationManager, AuthenticationManager) |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
110 |
# replace PersistentSessionManager by GAEPersistentSessionManager |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
111 |
vreg.register_and_replace(GAEPersistentSessionManager, PersistentSessionManager) |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
112 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
113 |
In this example, we explicitly register classes one by one: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
114 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
115 |
* the `SessionCleaner` class |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
116 |
* the `GAEAuthenticationManager` to replace the `AuthenticationManager` |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
117 |
* the `GAEPersistentSessionManager` to replace the `PersistentSessionManager` |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
118 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
119 |
If at some point we register a new appobject class in this module, it won't be |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
120 |
registered at all without modification to the `registration_callback` |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
121 |
implementation. The previous example will register it though, thanks to the call |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
122 |
to the `register_all` method. |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
123 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
124 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
125 |
.. _Selection: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
126 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
127 |
Runtime objects selection |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
128 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
129 |
|
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
130 |
Now that we have all application objects loaded, the question is : when |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
131 |
I want some specific object, for instance the primary view for a given |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
132 |
entity, how do I get the proper object ? This is what we call the |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
133 |
**selection mechanism**. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
134 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
135 |
As explained in the :ref:`Concepts` section: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
136 |
|
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
137 |
* each application object has a **selector**, defined by its |
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
138 |
`__select__` class attribute |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
139 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
140 |
* this selector is responsible to return a **score** for a given context |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
141 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
142 |
- 0 score means the object doesn't apply to this context |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
143 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
144 |
- else, the higher the score, the better the object suits the context |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
145 |
|
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
146 |
* the object with the highest score is selected. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
147 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
148 |
.. Note:: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
149 |
|
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
150 |
When no single object has the highest score, an exception is raised in development |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
151 |
mode to let you know that the engine was not able to identify the view to |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
152 |
apply. This error is silenced in production mode and one of the objects with |
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
153 |
the highest score is picked. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
154 |
|
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
155 |
In such cases you would need to review your design and make sure |
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
156 |
your selectors or appobjects are properly defined. Such an error is |
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
157 |
typically caused by either forgetting to change the __regid__ in a |
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
158 |
derived class, or by having copy-pasted some code. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
159 |
|
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
160 |
For instance, if you are selecting the primary (`__regid__ = |
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
161 |
'primary'`) view (`__registry__ = 'views'`) for a result set |
5306
763319a51e72
[doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5275
diff
changeset
|
162 |
containing a `Card` entity, two objects will probably be selectable: |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
163 |
|
6152
6824f8b61098
use is_instance in a number of places (esp. documentation) rather than the deprecated implements
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6046
diff
changeset
|
164 |
* the default primary view (`__select__ = is_instance('Any')`), meaning |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
165 |
that the object is selectable for any kind of entity type |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
166 |
|
6152
6824f8b61098
use is_instance in a number of places (esp. documentation) rather than the deprecated implements
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6046
diff
changeset
|
167 |
* the specific `Card` primary view (`__select__ = is_instance('Card')`, |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
168 |
meaning that the object is selectable for Card entities |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
169 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
170 |
Other primary views specific to other entity types won't be selectable in this |
6152
6824f8b61098
use is_instance in a number of places (esp. documentation) rather than the deprecated implements
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6046
diff
changeset
|
171 |
case. Among selectable objects, the `is_instance('Card')` selector will return a higher |
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
172 |
score since it's more specific, so the correct view will be selected as expected. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
173 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
174 |
.. _SelectionAPI: |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
175 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
176 |
API for objects selections |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
177 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
178 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
179 |
Here is the selection API you'll get on every registry. Some of them, as the |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
180 |
'etypes' registry, containing entity classes, extend it. In those methods, |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
181 |
`*args, **kwargs` is what we call the **context**. Those arguments are given to |
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5426
diff
changeset
|
182 |
selectors that will inspect their content and return a score accordingly. |
5147
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
183 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
184 |
.. automethod:: cubicweb.vregistry.Registry.select |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
185 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
186 |
.. automethod:: cubicweb.vregistry.Registry.select_or_none |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
187 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
188 |
.. automethod:: cubicweb.vregistry.Registry.possible_objects |
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
189 |
|
70181998897f
more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5143
diff
changeset
|
190 |
.. automethod:: cubicweb.vregistry.Registry.object_by_id |
0 | 191 |
""" |
5886 | 192 |
|
0 | 193 |
__docformat__ = "restructuredtext en" |
1769
fb91d2b8a441
fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents:
1752
diff
changeset
|
194 |
_ = unicode |
0 | 195 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
196 |
import sys |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
197 |
from os.path import join, dirname, realpath |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
198 |
from warnings import warn |
7460
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
199 |
from datetime import datetime, date, time, timedelta |
8930
6a02be304486
remove unused import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8913
diff
changeset
|
200 |
from functools import reduce |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
201 |
|
4719
aaed3f813ef8
kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
202 |
from logilab.common.decorators import cached, clear_cache |
6454
97203d0af4cb
[test/possible views] skip deprecated views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
203 |
from logilab.common.deprecation import deprecated, class_deprecated |
2684
c84691380dd4
[autoreload] remove all modules under vregistry_path() from sys.modules before reloading
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2669
diff
changeset
|
204 |
from logilab.common.modutils import cleanup_sys_modules |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
205 |
from logilab.common.registry import ( |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
206 |
RegistryStore, Registry, obj_registries, |
8930
6a02be304486
remove unused import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8913
diff
changeset
|
207 |
ObjectNotFound, RegistryNotFound) |
0 | 208 |
|
209 |
from rql import RQLHelper |
|
7460
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
210 |
from yams.constraints import BASE_CONVERTERS |
0 | 211 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
212 |
from cubicweb import (CW_SOFTWARE_ROOT, ETYPE_NAME_MAP, CW_EVENT_MANAGER, |
8701
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
213 |
onevent, Binary, UnknownProperty, UnknownEid) |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
214 |
from cubicweb.predicates import (implements, appobject_selectable, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
215 |
_reset_is_instance_cache) |
0 | 216 |
|
8701
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
217 |
|
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
218 |
@onevent('before-registry-reload') |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
219 |
def cleanup_uicfg_compat(): |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
220 |
""" backward compat: those modules are now refering to app objects in |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
221 |
cw.web.views.uicfg and import * from backward compat. On registry reload, we |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
222 |
should pop those modules from the cache so references are properly updated on |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
223 |
subsequent reload |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
224 |
""" |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
225 |
if 'cubicweb.web' in sys.modules: |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
226 |
if getattr(sys.modules['cubicweb.web'], 'uicfg', None): |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
227 |
del sys.modules['cubicweb.web'].uicfg |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
228 |
if getattr(sys.modules['cubicweb.web'], 'uihelper', None): |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
229 |
del sys.modules['cubicweb.web'].uihelper |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
230 |
sys.modules.pop('cubicweb.web.uicfg', None) |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
231 |
sys.modules.pop('cubicweb.web.uihelper', None) |
0 | 232 |
|
776 | 233 |
def use_interfaces(obj): |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
234 |
"""return interfaces required by the given object by searching for |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
235 |
`implements` predicate |
1132 | 236 |
""" |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
237 |
impl = obj.__select__.search_selector(implements) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
238 |
if impl: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
239 |
return sorted(impl.expected_ifaces) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
240 |
return () |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
241 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
242 |
def require_appobject(obj): |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
243 |
"""return appobjects required by the given object by searching for |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
244 |
`appobject_selectable` predicate |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
245 |
""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
246 |
impl = obj.__select__.search_selector(appobject_selectable) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
247 |
if impl: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
248 |
return (impl.registry, impl.regids) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
249 |
return None |
0 | 250 |
|
251 |
||
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
252 |
class CWRegistry(Registry): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
253 |
def __init__(self, vreg): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
254 |
super(CWRegistry, self).__init__(vreg.config) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
255 |
self.vreg = vreg |
2927
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
256 |
|
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
257 |
@property |
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
258 |
def schema(self): |
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
259 |
return self.vreg.schema |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
260 |
|
2805
c6d10de521bc
R deprecate CWRegistry.possible_vobjects
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2800
diff
changeset
|
261 |
def poss_visible_objects(self, *args, **kwargs): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
262 |
"""return an ordered list of possible app objects in a given registry, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
263 |
supposing they support the 'visible' and 'order' properties (as most |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
264 |
visualizable objects) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
265 |
""" |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
266 |
return sorted([x for x in self.possible_objects(*args, **kwargs) |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2815
diff
changeset
|
267 |
if x.cw_propval('visible')], |
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2815
diff
changeset
|
268 |
key=lambda x: x.cw_propval('order')) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
269 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
270 |
|
8437
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
271 |
def related_appobject(obj, appobjectattr='__appobject__'): |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
272 |
""" adapts any object to a potential appobject bound to it |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
273 |
through the __appobject__ attribute |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
274 |
""" |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
275 |
return getattr(obj, appobjectattr, obj) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
276 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
277 |
|
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
278 |
class InstancesRegistry(CWRegistry): |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
279 |
|
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
280 |
def selected(self, winner, args, kwargs): |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
281 |
"""overriden to avoid the default 'instanciation' behaviour, ie |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
282 |
winner(*args, **kwargs) |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
283 |
""" |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
284 |
return winner |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
285 |
|
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
286 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
287 |
class ETypeRegistry(CWRegistry): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
288 |
|
6795
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6742
diff
changeset
|
289 |
def clear_caches(self): |
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6742
diff
changeset
|
290 |
clear_cache(self, 'etype_class') |
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6742
diff
changeset
|
291 |
clear_cache(self, 'parent_classes') |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
292 |
_reset_is_instance_cache(self.vreg) |
6795
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6742
diff
changeset
|
293 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
294 |
def initialization_completed(self): |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
295 |
"""on registration completed, clear etype_class internal cache |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
296 |
""" |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
297 |
super(ETypeRegistry, self).initialization_completed() |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
298 |
# clear etype cache if you don't want to run into deep weirdness |
6795
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6742
diff
changeset
|
299 |
self.clear_caches() |
8913
409ea1ed9832
[vreg]Â (re)build entity classes cache after registry initialization.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8719
diff
changeset
|
300 |
# rebuild all classes to avoid potential memory fragmentation |
409ea1ed9832
[vreg]Â (re)build entity classes cache after registry initialization.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8719
diff
changeset
|
301 |
# (see #2719113) |
409ea1ed9832
[vreg]Â (re)build entity classes cache after registry initialization.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8719
diff
changeset
|
302 |
for eschema in self.vreg.schema.entities(): |
409ea1ed9832
[vreg]Â (re)build entity classes cache after registry initialization.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8719
diff
changeset
|
303 |
self.etype_class(eschema) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
304 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
305 |
def register(self, obj, **kwargs): |
8437
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
306 |
obj = related_appobject(obj) |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
307 |
oid = kwargs.get('oid') or obj.__regid__ |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
308 |
if oid != 'Any' and not oid in self.schema: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
309 |
self.error('don\'t register %s, %s type not defined in the ' |
2829
054a8805da52
turn id into __id__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2824
diff
changeset
|
310 |
'schema', obj, oid) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
311 |
return |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
312 |
kwargs['clear'] = True |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
313 |
super(ETypeRegistry, self).register(obj, **kwargs) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
314 |
|
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7031
diff
changeset
|
315 |
def iter_classes(self): |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7031
diff
changeset
|
316 |
for etype in self.vreg.schema.entities(): |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7031
diff
changeset
|
317 |
yield self.etype_class(etype) |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7031
diff
changeset
|
318 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
319 |
@cached |
2824
3455f72010fe
better as a method of the etypes registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
320 |
def parent_classes(self, etype): |
2894
4b720d82a1e4
take care in case Any is given
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2829
diff
changeset
|
321 |
if etype == 'Any': |
6046
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6037
diff
changeset
|
322 |
return (), self.etype_class('Any') |
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6037
diff
changeset
|
323 |
parents = tuple(self.etype_class(e.type) |
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6037
diff
changeset
|
324 |
for e in self.schema.eschema(etype).ancestors()) |
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6037
diff
changeset
|
325 |
return parents, self.etype_class('Any') |
2824
3455f72010fe
better as a method of the etypes registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
326 |
|
3455f72010fe
better as a method of the etypes registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
327 |
@cached |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
328 |
def etype_class(self, etype): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
329 |
"""return an entity class for the given entity type. |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
330 |
|
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
331 |
Try to find out a specific class for this kind of entity or default to a |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
332 |
dump of the nearest parent class (in yams inheritance) registered. |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
333 |
|
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
334 |
Fall back to 'Any' if not yams parent class found. |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
335 |
""" |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
336 |
etype = str(etype) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
337 |
if etype == 'Any': |
4149
ecde9f78a080
etype_class('Any') should return bare 'Any' class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
338 |
objects = self['Any'] |
ecde9f78a080
etype_class('Any') should return bare 'Any' class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
339 |
assert len(objects) == 1, objects |
ecde9f78a080
etype_class('Any') should return bare 'Any' class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
340 |
return objects[0] |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
341 |
eschema = self.schema.eschema(etype) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
342 |
baseschemas = [eschema] + eschema.ancestors() |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
343 |
# browse ancestors from most specific to most generic and try to find an |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
344 |
# associated custom entity class |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
345 |
for baseschema in baseschemas: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
346 |
try: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
347 |
btype = ETYPE_NAME_MAP[baseschema] |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
348 |
except KeyError: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
349 |
btype = str(baseschema) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
350 |
try: |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
351 |
objects = self[btype] |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
352 |
assert len(objects) == 1, objects |
3137
5598bec9be7f
fix so that we ensure issubclass(etype_class('SubNote'), etype_class('Note'))
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
353 |
if btype == etype: |
3172
9341ab8f1d1a
[vreg] we must ensure that parent classes are initialiazed first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3057
diff
changeset
|
354 |
cls = objects[0] |
3137
5598bec9be7f
fix so that we ensure issubclass(etype_class('SubNote'), etype_class('Note'))
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
355 |
else: |
5598bec9be7f
fix so that we ensure issubclass(etype_class('SubNote'), etype_class('Note'))
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
356 |
# recurse to ensure issubclass(etype_class('Child'), |
5598bec9be7f
fix so that we ensure issubclass(etype_class('SubNote'), etype_class('Note'))
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
357 |
# etype_class('Parent')) |
5598bec9be7f
fix so that we ensure issubclass(etype_class('SubNote'), etype_class('Note'))
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3071
diff
changeset
|
358 |
cls = self.etype_class(btype) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
359 |
break |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
360 |
except ObjectNotFound: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
361 |
pass |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
362 |
else: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
363 |
# no entity class for any of the ancestors, fallback to the default |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
364 |
# one |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
365 |
objects = self['Any'] |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
366 |
assert len(objects) == 1, objects |
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
367 |
cls = objects[0] |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
368 |
# make a copy event if cls.__regid__ == etype, else we may have pb for |
3035 | 369 |
# client application using multiple connections to different |
370 |
# repositories (eg shingouz) |
|
7423
598a4f051259
[cwvreg] inline function dump_class()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7304
diff
changeset
|
371 |
# __autogenerated__ attribute is just a marker |
598a4f051259
[cwvreg] inline function dump_class()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7304
diff
changeset
|
372 |
cls = type(str(etype), (cls,), {'__autogenerated__': True, |
598a4f051259
[cwvreg] inline function dump_class()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7304
diff
changeset
|
373 |
'__doc__': cls.__doc__, |
598a4f051259
[cwvreg] inline function dump_class()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7304
diff
changeset
|
374 |
'__module__': cls.__module__}) |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
375 |
cls.__regid__ = etype |
2807
696ff03f9a58
__initialize__ needs the schema as argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2804
diff
changeset
|
376 |
cls.__initialize__(self.schema) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
377 |
return cls |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
378 |
|
7302
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
379 |
def fetch_attrs(self, targettypes): |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
380 |
"""return intersection of fetch_attrs of each entity type in |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
381 |
`targettypes` |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
382 |
""" |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
383 |
fetchattrs_list = [] |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
384 |
for ttype in targettypes: |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
385 |
etypecls = self.etype_class(ttype) |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
386 |
fetchattrs_list.append(set(etypecls.fetch_attrs)) |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
387 |
return reduce(set.intersection, fetchattrs_list) |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7206
diff
changeset
|
388 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
389 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
390 |
class ViewsRegistry(CWRegistry): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
391 |
|
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
392 |
def main_template(self, req, oid='main-template', rset=None, **kwargs): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
393 |
"""display query by calling the given template (default to main), |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
394 |
and returning the output as a string instead of requiring the [w]rite |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
395 |
method as argument |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
396 |
""" |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
397 |
obj = self.select(oid, req, rset=rset, **kwargs) |
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
398 |
res = obj.render(**kwargs) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
399 |
if isinstance(res, unicode): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
400 |
return res.encode(req.encoding) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
401 |
assert isinstance(res, str) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
402 |
return res |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
403 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
404 |
def possible_views(self, req, rset=None, **kwargs): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
405 |
"""return an iterator on possible views for this result set |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
406 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
407 |
views returned are classes, not instances |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
408 |
""" |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
409 |
for vid, views in self.items(): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
410 |
if vid[0] == '_': |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
411 |
continue |
6454
97203d0af4cb
[test/possible views] skip deprecated views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
412 |
views = [view for view in views |
97203d0af4cb
[test/possible views] skip deprecated views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
413 |
if not isinstance(view, class_deprecated)] |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
414 |
try: |
2770
356e9d7c356d
R propagate registry API changes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2705
diff
changeset
|
415 |
view = self._select_best(views, req, rset=rset, **kwargs) |
7272
771f594c12a2
[vreg] vregistry._select_best was needlessly instanciating NoSelectableObject (closes #1626708)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7206
diff
changeset
|
416 |
if view is not None and view.linkable(): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
417 |
yield view |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
418 |
except Exception: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
419 |
self.exception('error while trying to select %s view for %s', |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
420 |
vid, rset) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
421 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
422 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
423 |
class ActionsRegistry(CWRegistry): |
5246
3246b1f88a18
[web] stop having actions configurable through cwproperties: this clutter site management and .po files for a useless fonctionnality (which, where and how actions are displayed is handled by code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
424 |
def poss_visible_objects(self, *args, **kwargs): |
3246b1f88a18
[web] stop having actions configurable through cwproperties: this clutter site management and .po files for a useless fonctionnality (which, where and how actions are displayed is handled by code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
425 |
"""return an ordered list of possible actions""" |
3246b1f88a18
[web] stop having actions configurable through cwproperties: this clutter site management and .po files for a useless fonctionnality (which, where and how actions are displayed is handled by code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
426 |
return sorted(self.possible_objects(*args, **kwargs), |
3246b1f88a18
[web] stop having actions configurable through cwproperties: this clutter site management and .po files for a useless fonctionnality (which, where and how actions are displayed is handled by code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5174
diff
changeset
|
427 |
key=lambda x: x.order) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
428 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
429 |
def possible_actions(self, req, rset=None, **kwargs): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
430 |
if rset is None: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3376
diff
changeset
|
431 |
actions = self.poss_visible_objects(req, rset=rset, **kwargs) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
432 |
else: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
433 |
actions = rset.possible_actions(**kwargs) # cached implementation |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
434 |
result = {} |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
435 |
for action in actions: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
436 |
result.setdefault(action.category, []).append(action) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
437 |
return result |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
438 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
439 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
440 |
class CtxComponentsRegistry(CWRegistry): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
441 |
def poss_visible_objects(self, *args, **kwargs): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
442 |
"""return an ordered list of possible components""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
443 |
context = kwargs.pop('context') |
6925
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
444 |
if '__cache' in kwargs: |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
445 |
cache = kwargs.pop('__cache') |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
446 |
elif kwargs.get('rset') is None: |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
447 |
cache = args[0] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
448 |
else: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
449 |
cache = kwargs['rset'] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
450 |
try: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
451 |
cached = cache.__components_cache |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
452 |
except AttributeError: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
453 |
ctxcomps = super(CtxComponentsRegistry, self).poss_visible_objects( |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
454 |
*args, **kwargs) |
6925
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
455 |
if cache is None: |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
456 |
components = [] |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
457 |
for component in ctxcomps: |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
458 |
cctx = component.cw_propval('context') |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
459 |
if cctx == context: |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
460 |
component.cw_extra_kwargs['context'] = cctx |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
461 |
components.append(component) |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
462 |
return components |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
463 |
cached = cache.__components_cache = {} |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
464 |
for component in ctxcomps: |
6925
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
465 |
cctx = component.cw_propval('context') |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
466 |
component.cw_extra_kwargs['context'] = cctx |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
467 |
cached.setdefault(cctx, []).append(component) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
468 |
thisctxcomps = cached.get(context, ()) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
469 |
# XXX set context for bw compat (should now be taken by comp.render()) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
470 |
for component in thisctxcomps: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
471 |
component.cw_extra_kwargs['context'] = context |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
472 |
return thisctxcomps |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
473 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
474 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
475 |
class BwCompatCWRegistry(object): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
476 |
def __init__(self, vreg, oldreg, redirecttoreg): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
477 |
self.vreg = vreg |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
478 |
self.oldreg = oldreg |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
479 |
self.redirecto = redirecttoreg |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
480 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
481 |
def __getattr__(self, attr): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
482 |
warn('[3.10] you should now use the %s registry instead of the %s registry' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
483 |
% (self.redirecto, self.oldreg), DeprecationWarning, stacklevel=2) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
484 |
return getattr(self.vreg[self.redirecto], attr) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
485 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
486 |
def clear(self): pass |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
487 |
def initialization_completed(self): pass |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
488 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
489 |
|
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
490 |
class CWRegistryStore(RegistryStore): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
491 |
"""Central registry for the cubicweb instance, extending the generic |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
492 |
RegistryStore with some cubicweb specific stuff. |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
493 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
494 |
This is one of the central object in cubicweb instance, coupling |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
495 |
dynamically loaded objects with the schema and the configuration objects. |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
496 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
497 |
It specializes the RegistryStore by adding some convenience methods to access to |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
498 |
stored objects. Currently we have the following registries of objects known |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
499 |
by the web instance (library may use some others additional registries): |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
500 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
501 |
* 'etypes', entity type classes |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
502 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
503 |
* 'views', views and templates (e.g. layout views) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
504 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
505 |
* 'components', non contextual components, like magic search, url evaluators |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
506 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
507 |
* 'ctxcomponents', contextual components like boxes and dynamic section |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
508 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
509 |
* 'actions', contextual actions, eg links to display in predefined places in |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
510 |
the ui |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
511 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
512 |
* 'forms', describing logic of HTML form |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
513 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
514 |
* 'formrenderers', rendering forms to html |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
515 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
516 |
* 'controllers', primary objects to handle request publishing, directly |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
517 |
plugged into the application |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
518 |
""" |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
519 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
520 |
REGISTRY_FACTORY = {None: CWRegistry, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
521 |
'etypes': ETypeRegistry, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
522 |
'views': ViewsRegistry, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
523 |
'actions': ActionsRegistry, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
524 |
'ctxcomponents': CtxComponentsRegistry, |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
525 |
'uicfg': InstancesRegistry, |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
526 |
} |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
527 |
|
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
528 |
def __init__(self, config, initlog=True): |
169
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
529 |
if initlog: |
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
530 |
# first init log service |
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
531 |
config.init_log() |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
532 |
super(CWRegistryStore, self).__init__(config.debugmode) |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
533 |
self.config = config |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
534 |
# need to clean sys.path this to avoid import confusion pb (i.e. having |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
535 |
# the same module loaded as 'cubicweb.web.views' subpackage and as |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
536 |
# views' or 'web.views' subpackage. This is mainly for testing purpose, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
537 |
# we should'nt need this in production environment |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
538 |
for webdir in (join(dirname(realpath(__file__)), 'web'), |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
539 |
join(dirname(__file__), 'web')): |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
540 |
if webdir in sys.path: |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
541 |
sys.path.remove(webdir) |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
542 |
if CW_SOFTWARE_ROOT in sys.path: |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
543 |
sys.path.remove(CW_SOFTWARE_ROOT) |
0 | 544 |
self.schema = None |
2906
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
545 |
self.initialized = False |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
546 |
self['boxes'] = BwCompatCWRegistry(self, 'boxes', 'ctxcomponents') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
547 |
self['contentnavigation'] = BwCompatCWRegistry(self, 'contentnavigation', 'ctxcomponents') |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
548 |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
549 |
def setdefault(self, regid): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
550 |
try: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
551 |
return self[regid] |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
552 |
except RegistryNotFound: |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
553 |
self[regid] = self.registry_class(regid)(self) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
554 |
return self[regid] |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
555 |
|
0 | 556 |
def items(self): |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
557 |
return [item for item in super(CWRegistryStore, self).items() |
0 | 558 |
if not item[0] in ('propertydefs', 'propertyvalues')] |
2669
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
559 |
def iteritems(self): |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
560 |
return (item for item in super(CWRegistryStore, self).iteritems() |
2669
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
561 |
if not item[0] in ('propertydefs', 'propertyvalues')) |
0 | 562 |
|
563 |
def values(self): |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
564 |
return [value for key, value in self.items()] |
2669
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
565 |
def itervalues(self): |
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
566 |
return (value for key, value in self.items()) |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
567 |
|
5273
c4caef6f09c9
[vreg] refactor the [re]loading process so things get clearer and fix spurious errors on edge cases
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5147
diff
changeset
|
568 |
def reset(self): |
5880
a022dcbed0d3
[vreg] new [before|after]-registry-reset event, taking vreg as argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5753
diff
changeset
|
569 |
CW_EVENT_MANAGER.emit('before-registry-reset', self) |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
570 |
super(CWRegistryStore, self).reset() |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
571 |
self._needs_iface = {} |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
572 |
self._needs_appobject = {} |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
573 |
# two special registries, propertydefs which care all the property |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
574 |
# definitions, and propertyvals which contains values for those |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
575 |
# properties |
2906
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
576 |
if not self.initialized: |
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
577 |
self['propertydefs'] = {} |
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
578 |
self['propertyvalues'] = self.eprop_values = {} |
7031
a04621040cad
[config refactoring] rename eproperty_definition method to cwproperty_definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6925
diff
changeset
|
579 |
for key, propdef in self.config.cwproperty_definitions(): |
2906
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
580 |
self.register_property(key, **propdef) |
5880
a022dcbed0d3
[vreg] new [before|after]-registry-reset event, taking vreg as argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5753
diff
changeset
|
581 |
CW_EVENT_MANAGER.emit('after-registry-reset', self) |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
582 |
|
8437
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
583 |
def register_all(self, objects, modname, butclasses=()): |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
584 |
butclasses = set(related_appobject(obj) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
585 |
for obj in butclasses) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
586 |
objects = [related_appobject(obj) for obj in objects] |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
587 |
super(CWRegistryStore, self).register_all(objects, modname, butclasses) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
588 |
|
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
589 |
def register_and_replace(self, obj, replaced): |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
590 |
obj = related_appobject(obj) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
591 |
replaced = related_appobject(replaced) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
592 |
super(CWRegistryStore, self).register_and_replace(obj, replaced) |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
593 |
|
0 | 594 |
def set_schema(self, schema): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
595 |
"""set instance'schema and load application objects""" |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
596 |
self._set_schema(schema) |
0 | 597 |
# now we can load application's web objects |
8537
e30d0a7f0087
[config] turn internal configuration methods building appobjects search path into normal method rather than class method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8437
diff
changeset
|
598 |
self.reload(self.config.appobjects_path(), force_reload=False) |
2273
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
599 |
# map lowered entity type names to their actual name |
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
600 |
self.case_insensitive_etypes = {} |
3692
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
601 |
for eschema in self.schema.entities(): |
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
602 |
etype = str(eschema) |
2273
daf6e178659f
new case_insensitive_etypes resource on the cubicweb registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2223
diff
changeset
|
603 |
self.case_insensitive_etypes[etype.lower()] = etype |
3692
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
604 |
clear_cache(eschema, 'ordered_relations') |
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
605 |
clear_cache(eschema, 'meta_attributes') |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
606 |
|
5273
c4caef6f09c9
[vreg] refactor the [re]loading process so things get clearer and fix spurious errors on edge cases
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5147
diff
changeset
|
607 |
def reload_if_needed(self): |
8537
e30d0a7f0087
[config] turn internal configuration methods building appobjects search path into normal method rather than class method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8437
diff
changeset
|
608 |
path = self.config.appobjects_path() |
5273
c4caef6f09c9
[vreg] refactor the [re]loading process so things get clearer and fix spurious errors on edge cases
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5147
diff
changeset
|
609 |
if self.is_reload_needed(path): |
c4caef6f09c9
[vreg] refactor the [re]loading process so things get clearer and fix spurious errors on edge cases
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5147
diff
changeset
|
610 |
self.reload(path) |
c4caef6f09c9
[vreg] refactor the [re]loading process so things get clearer and fix spurious errors on edge cases
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5147
diff
changeset
|
611 |
|
5275
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
612 |
def reload(self, path, force_reload=True): |
5273
c4caef6f09c9
[vreg] refactor the [re]loading process so things get clearer and fix spurious errors on edge cases
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5147
diff
changeset
|
613 |
"""modification detected, reset and reload the vreg""" |
4966
e968e0a7776b
[registry] trigger reload events on set_schema()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4719
diff
changeset
|
614 |
CW_EVENT_MANAGER.emit('before-registry-reload') |
5275
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
615 |
if force_reload: |
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
616 |
cleanup_sys_modules(path) |
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
617 |
cubes = self.config.cubes() |
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
618 |
# if the fs code use some cubes not yet registered into the instance |
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
619 |
# we should cleanup sys.modules for those as well to avoid potential |
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
620 |
# bad class reference pb after reloading |
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
621 |
cfg = self.config |
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
622 |
for cube in cfg.expand_cubes(cubes, with_recommends=True): |
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
623 |
if not cube in cubes: |
8537
e30d0a7f0087
[config] turn internal configuration methods building appobjects search path into normal method rather than class method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8437
diff
changeset
|
624 |
cpath = cfg.build_appobjects_cube_path([cfg.cube_dir(cube)]) |
5275
32fbb13c06d3
[vreg] fix bug introduced in 5273:c4caef6f09c9 : we should not force_reload in vreg reset done because of a set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5273
diff
changeset
|
625 |
cleanup_sys_modules(cpath) |
5748
487ab6ac90cc
[auto-reload] we should never call load_module with use_sys=False, that may lead to inconsistency with module interdependancy (eg module get imported by another one, then is reimported by the vreg to load its appobjects. Cleanup of sys.modules done before reloading should be enough.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
626 |
self.register_objects(path) |
4966
e968e0a7776b
[registry] trigger reload events on set_schema()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4719
diff
changeset
|
627 |
CW_EVENT_MANAGER.emit('after-registry-reload') |
e968e0a7776b
[registry] trigger reload events on set_schema()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4719
diff
changeset
|
628 |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
629 |
def _set_schema(self, schema): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
630 |
"""set instance'schema""" |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
631 |
self.schema = schema |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
632 |
clear_cache(self, 'rqlhelper') |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
633 |
|
0 | 634 |
def update_schema(self, schema): |
635 |
"""update .schema attribute on registered objects, necessary for some |
|
636 |
tests |
|
637 |
""" |
|
638 |
self.schema = schema |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
639 |
for registry, regcontent in self.items(): |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
640 |
for objects in regcontent.itervalues(): |
0 | 641 |
for obj in objects: |
642 |
obj.schema = schema |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
643 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
644 |
@deprecated('[3.9] use .register instead') |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
645 |
def register_if_interface_found(self, obj, ifaces, **kwargs): |
5143
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
646 |
"""register `obj` but remove it if no entity class implements one of |
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
647 |
the given `ifaces` interfaces at the end of the registration process. |
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
648 |
|
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
649 |
Extra keyword arguments are given to the |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
650 |
:meth:`~cubicweb.cwvreg.CWRegistryStore.register` function. |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
651 |
""" |
785 | 652 |
self.register(obj, **kwargs) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
653 |
if not isinstance(ifaces, (tuple, list)): |
785 | 654 |
self._needs_iface[obj] = (ifaces,) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
655 |
else: |
785 | 656 |
self._needs_iface[obj] = ifaces |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
657 |
|
3055
06814d57514f
[vreg] keep positional arg compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2927
diff
changeset
|
658 |
def register(self, obj, *args, **kwargs): |
5143
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
659 |
"""register `obj` application object into `registryname` or |
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
660 |
`obj.__registry__` if not specified, with identifier `oid` or |
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
661 |
`obj.__regid__` if not specified. |
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
662 |
|
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
663 |
If `clear` is true, all objects with the same identifier will be |
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
664 |
previously unregistered. |
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
665 |
""" |
8437
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
666 |
obj = related_appobject(obj) |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
667 |
super(CWRegistryStore, self).register(obj, *args, **kwargs) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
668 |
# XXX bw compat |
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
776
diff
changeset
|
669 |
ifaces = use_interfaces(obj) |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
670 |
if ifaces: |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
671 |
if not obj.__name__.endswith('Adapter') and \ |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
672 |
any(iface for iface in ifaces if not isinstance(iface, basestring)): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
673 |
warn('[3.9] %s: interfaces in implements selector are ' |
5723
2ae478c47089
[3.9] update warning message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5627
diff
changeset
|
674 |
'deprecated in favor of adapters / adaptable ' |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
675 |
'selector' % obj.__name__, DeprecationWarning) |
785 | 676 |
self._needs_iface[obj] = ifaces |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
677 |
depends_on = require_appobject(obj) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
678 |
if depends_on is not None: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
679 |
self._needs_appobject[obj] = depends_on |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
680 |
|
5748
487ab6ac90cc
[auto-reload] we should never call load_module with use_sys=False, that may lead to inconsistency with module interdependancy (eg module get imported by another one, then is reimported by the vreg to load its appobjects. Cleanup of sys.modules done before reloading should be enough.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
681 |
def register_objects(self, path): |
487ab6ac90cc
[auto-reload] we should never call load_module with use_sys=False, that may lead to inconsistency with module interdependancy (eg module get imported by another one, then is reimported by the vreg to load its appobjects. Cleanup of sys.modules done before reloading should be enough.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
682 |
"""overriden to give cubicweb's extrapath (eg cubes package's __path__) |
487ab6ac90cc
[auto-reload] we should never call load_module with use_sys=False, that may lead to inconsistency with module interdependancy (eg module get imported by another one, then is reimported by the vreg to load its appobjects. Cleanup of sys.modules done before reloading should be enough.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
683 |
""" |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
684 |
super(CWRegistryStore, self).register_objects( |
5748
487ab6ac90cc
[auto-reload] we should never call load_module with use_sys=False, that may lead to inconsistency with module interdependancy (eg module get imported by another one, then is reimported by the vreg to load its appobjects. Cleanup of sys.modules done before reloading should be enough.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
685 |
path, self.config.extrapath) |
2651
3ad936634d2a
[registry] when a source file is changed, reset and reload the whole registry
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2613
diff
changeset
|
686 |
|
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
687 |
def initialization_completed(self): |
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
688 |
"""cw specific code once vreg initialization is completed: |
0 | 689 |
|
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
690 |
* remove objects requiring a missing interface, unless |
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
691 |
config.cleanup_interface_sobjects is false |
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
692 |
* init rtags |
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
693 |
""" |
1638 | 694 |
# we may want to keep interface dependent objects (e.g.for i18n |
695 |
# catalog generation) |
|
696 |
if self.config.cleanup_interface_sobjects: |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
697 |
# XXX deprecated with cw 3.9: remove appobjects that don't support |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
698 |
# any available interface |
1638 | 699 |
implemented_interfaces = set() |
700 |
if 'Any' in self.get('etypes', ()): |
|
701 |
for etype in self.schema.entities(): |
|
3702
29cce43d6af2
skip final type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3692
diff
changeset
|
702 |
if etype.final: |
29cce43d6af2
skip final type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3692
diff
changeset
|
703 |
continue |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
704 |
cls = self['etypes'].etype_class(etype) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
705 |
if cls.__implements__: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
706 |
warn('[3.9] %s: using __implements__/interfaces are ' |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
707 |
'deprecated in favor of adapters' % cls.__name__, |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
708 |
DeprecationWarning) |
1638 | 709 |
for iface in cls.__implements__: |
710 |
implemented_interfaces.update(iface.__mro__) |
|
711 |
implemented_interfaces.update(cls.__mro__) |
|
712 |
for obj, ifaces in self._needs_iface.items(): |
|
713 |
ifaces = frozenset(isinstance(iface, basestring) |
|
714 |
and iface in self.schema |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
715 |
and self['etypes'].etype_class(iface) |
1638 | 716 |
or iface |
717 |
for iface in ifaces) |
|
718 |
if not ('Any' in ifaces or ifaces & implemented_interfaces): |
|
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
719 |
reg = self[obj_registries(obj)[0]] |
6014
a5e22657f6f4
[debug] improve debug messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5890
diff
changeset
|
720 |
self.debug('unregister %s (no implemented ' |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
721 |
'interface among %s)', reg.objid(obj), ifaces) |
1638 | 722 |
self.unregister(obj) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
723 |
# since 3.9: remove appobjects which depending on other, unexistant |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
724 |
# appobjects |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
725 |
for obj, (regname, regids) in self._needs_appobject.items(): |
5562
4ccd599b5cf0
[vreg] on registration completed, don't crash if an object depends on an unexistant registry, simply kick the object out
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
726 |
try: |
4ccd599b5cf0
[vreg] on registration completed, don't crash if an object depends on an unexistant registry, simply kick the object out
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
727 |
registry = self[regname] |
4ccd599b5cf0
[vreg] on registration completed, don't crash if an object depends on an unexistant registry, simply kick the object out
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
728 |
except RegistryNotFound: |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
729 |
self.debug('unregister %s (no registry %s)', obj, regname) |
5562
4ccd599b5cf0
[vreg] on registration completed, don't crash if an object depends on an unexistant registry, simply kick the object out
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
730 |
self.unregister(obj) |
4ccd599b5cf0
[vreg] on registration completed, don't crash if an object depends on an unexistant registry, simply kick the object out
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
731 |
continue |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
732 |
for regid in regids: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
733 |
if registry.get(regid): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
734 |
break |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
735 |
else: |
6014
a5e22657f6f4
[debug] improve debug messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5890
diff
changeset
|
736 |
self.debug('unregister %s (no %s object in registry %s)', |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
737 |
registry.objid(obj), ' or '.join(regids), regname) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
738 |
self.unregister(obj) |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
739 |
super(CWRegistryStore, self).initialization_completed() |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
740 |
if 'uicfg' in self: # 'uicfg' is not loaded in a pure repository mode |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
741 |
for rtags in self['uicfg'].itervalues(): |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
742 |
for rtag in rtags: |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
743 |
# don't check rtags if we don't want to cleanup_interface_sobjects |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
744 |
rtag.init(self.schema, check=self.config.cleanup_interface_sobjects) |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
745 |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
746 |
# rql parsing utilities #################################################### |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
747 |
|
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
748 |
@property |
0 | 749 |
@cached |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
750 |
def rqlhelper(self): |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
751 |
return RQLHelper(self.schema, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
752 |
special_relations={'eid': 'uid', 'has_text': 'fti'}) |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
753 |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
754 |
def solutions(self, req, rqlst, args): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
755 |
def type_from_eid(eid, req=req): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
756 |
return req.describe(eid)[0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5147
diff
changeset
|
757 |
return self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args) |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
758 |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
759 |
def parse(self, req, rql, args=None): |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
760 |
rqlst = self.rqlhelper.parse(rql) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
761 |
try: |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
762 |
self.solutions(req, rqlst, args) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
763 |
except UnknownEid: |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
764 |
for select in rqlst.children: |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
765 |
select.solutions = [] |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3205
diff
changeset
|
766 |
return rqlst |
0 | 767 |
|
768 |
# properties handling ##################################################### |
|
769 |
||
770 |
def user_property_keys(self, withsitewide=False): |
|
771 |
if withsitewide: |
|
2223
59588e2d5cd1
close #343467, no sources sections in site properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
772 |
return sorted(k for k in self['propertydefs'] |
59588e2d5cd1
close #343467, no sources sections in site properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
773 |
if not k.startswith('sources.')) |
0 | 774 |
return sorted(k for k, kd in self['propertydefs'].iteritems() |
2223
59588e2d5cd1
close #343467, no sources sections in site properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
775 |
if not kd['sitewide'] and not k.startswith('sources.')) |
0 | 776 |
|
777 |
def register_property(self, key, type, help, default=None, vocabulary=None, |
|
778 |
sitewide=False): |
|
779 |
"""register a given property""" |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
780 |
properties = self['propertydefs'] |
7465
bb0c89d1a078
[vreg] help understanding assertion error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7302
diff
changeset
|
781 |
assert type in YAMS_TO_PY, 'unknown type %s' % type |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
782 |
properties[key] = {'type': type, 'vocabulary': vocabulary, |
0 | 783 |
'default': default, 'help': help, |
784 |
'sitewide': sitewide} |
|
785 |
||
786 |
def property_info(self, key): |
|
787 |
"""return dictionary containing description associated to the given |
|
788 |
property key (including type, defaut value, help and a site wide |
|
789 |
boolean) |
|
790 |
""" |
|
791 |
try: |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
792 |
return self['propertydefs'][key] |
0 | 793 |
except KeyError: |
794 |
if key.startswith('system.version.'): |
|
795 |
soft = key.split('.')[-1] |
|
796 |
return {'type': 'String', 'sitewide': True, |
|
797 |
'default': None, 'vocabulary': None, |
|
798 |
'help': _('%s software version of the database') % soft} |
|
799 |
raise UnknownProperty('unregistered property %r' % key) |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
800 |
|
0 | 801 |
def property_value(self, key): |
802 |
try: |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
803 |
return self['propertyvalues'][key] |
0 | 804 |
except KeyError: |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
805 |
return self.property_info(key)['default'] |
0 | 806 |
|
807 |
def typed_value(self, key, value): |
|
808 |
"""value is an unicode string, return it correctly typed. Let potential |
|
809 |
type error propagates. |
|
810 |
""" |
|
811 |
pdef = self.property_info(key) |
|
812 |
try: |
|
813 |
value = YAMS_TO_PY[pdef['type']](value) |
|
814 |
except (TypeError, ValueError): |
|
815 |
raise ValueError(_('bad value')) |
|
816 |
vocab = pdef['vocabulary'] |
|
817 |
if vocab is not None: |
|
818 |
if callable(vocab): |
|
6069
d7cef08aad27
[cwprops] fix callable vocabulary of cwproperties which were inconsistently called. No more argument, should now simply return a list of (untranslated) values
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
819 |
vocab = vocab(None) # XXX need a req object |
0 | 820 |
if not value in vocab: |
821 |
raise ValueError(_('unauthorized value')) |
|
822 |
return value |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
823 |
|
0 | 824 |
def init_properties(self, propvalues): |
825 |
"""init the property values registry using the given set of couple (key, value) |
|
826 |
""" |
|
827 |
self.initialized = True |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2613
diff
changeset
|
828 |
values = self['propertyvalues'] |
0 | 829 |
for key, val in propvalues: |
830 |
try: |
|
831 |
values[key] = self.typed_value(key, val) |
|
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8666
diff
changeset
|
832 |
except ValueError as ex: |
0 | 833 |
self.warning('%s (you should probably delete that property ' |
834 |
'from the database)', ex) |
|
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8666
diff
changeset
|
835 |
except UnknownProperty as ex: |
0 | 836 |
self.warning('%s (you should probably delete that property ' |
837 |
'from the database)', ex) |
|
838 |
||
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
839 |
|
7460
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
840 |
# XXX unify with yams.constraints.BASE_CONVERTERS? |
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
841 |
YAMS_TO_PY = BASE_CONVERTERS.copy() |
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
842 |
YAMS_TO_PY.update({ |
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
843 |
'Bytes': Binary, |
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7154
diff
changeset
|
844 |
'Date': date, |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7154
diff
changeset
|
845 |
'Datetime': datetime, |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7154
diff
changeset
|
846 |
'TZDatetime': datetime, |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7154
diff
changeset
|
847 |
'Time': time, |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7154
diff
changeset
|
848 |
'TZTime': time, |
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7154
diff
changeset
|
849 |
'Interval': timedelta, |
7460
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
850 |
}) |
0 | 851 |