author | Laurent Peuch <cortex@worlddomination.be> |
Tue, 17 Dec 2019 21:21:55 +0100 | |
changeset 12824 | bc623a3e44e9 |
parent 12785 | a9025212ce0c |
child 12882 | 3ddd03309315 |
permissions | -rw-r--r-- |
11767
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11765
diff
changeset
|
1 |
# copyright 2003-2016 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/>. |
10499
d0907690af55
[doc] move the documentations from docstring directly to the book.
David Douard <david.douard@logilab.fr>
parents:
10496
diff
changeset
|
18 |
""" |
d0907690af55
[doc] move the documentations from docstring directly to the book.
David Douard <david.douard@logilab.fr>
parents:
10496
diff
changeset
|
19 |
Cubicweb registries |
0 | 20 |
""" |
5886 | 21 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
22 |
import sys |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
23 |
from os.path import join, dirname, realpath |
7460
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
24 |
from datetime import datetime, date, time, timedelta |
8930
6a02be304486
remove unused import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8913
diff
changeset
|
25 |
from functools import reduce |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
26 |
|
4719
aaed3f813ef8
kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
27 |
from logilab.common.decorators import cached, clear_cache |
11249
0ff4c02a1871
[test] Fix devtools unittest_i18n when ran without pytest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11057
diff
changeset
|
28 |
from logilab.common.deprecation import class_deprecated |
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
29 |
from logilab.common.modutils import clean_sys_modules |
11249
0ff4c02a1871
[test] Fix devtools unittest_i18n when ran without pytest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11057
diff
changeset
|
30 |
from logilab.common.registry import RegistryStore, Registry, ObjectNotFound, RegistryNotFound |
0 | 31 |
|
32 |
from rql import RQLHelper |
|
7460
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
33 |
from yams.constraints import BASE_CONVERTERS |
0 | 34 |
|
11767
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11765
diff
changeset
|
35 |
from cubicweb import _ |
12768
7d2c61d40fe9
[debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents:
12567
diff
changeset
|
36 |
from cubicweb.debug import emit_to_debug_channel |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
37 |
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
|
38 |
onevent, Binary, UnknownProperty, UnknownEid) |
9256
697a8181ba30
remove 3.9 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8930
diff
changeset
|
39 |
from cubicweb.predicates import appobject_selectable, _reset_is_instance_cache |
0 | 40 |
|
8701
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
41 |
|
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
42 |
@onevent('before-registry-reload') |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
43 |
def cleanup_uicfg_compat(): |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
44 |
""" 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
|
45 |
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
|
46 |
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
|
47 |
subsequent reload |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
48 |
""" |
d94d3a3ba586
[cwvreg] complete cw.web.uicfg cleanup callback (closes #2718217)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
sys.modules.pop('cubicweb.web.uihelper', None) |
0 | 56 |
|
10499
d0907690af55
[doc] move the documentations from docstring directly to the book.
David Douard <david.douard@logilab.fr>
parents:
10496
diff
changeset
|
57 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
58 |
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
|
59 |
"""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
|
60 |
`appobject_selectable` predicate |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
61 |
""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
62 |
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
|
63 |
if impl: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
64 |
return (impl.registry, impl.regids) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
65 |
return None |
0 | 66 |
|
67 |
||
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
|
68 |
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
|
69 |
def __init__(self, vreg): |
10499
d0907690af55
[doc] move the documentations from docstring directly to the book.
David Douard <david.douard@logilab.fr>
parents:
10496
diff
changeset
|
70 |
""" |
d0907690af55
[doc] move the documentations from docstring directly to the book.
David Douard <david.douard@logilab.fr>
parents:
10496
diff
changeset
|
71 |
:param vreg: the :py:class:`CWRegistryStore` managing this registry. |
d0907690af55
[doc] move the documentations from docstring directly to the book.
David Douard <david.douard@logilab.fr>
parents:
10496
diff
changeset
|
72 |
""" |
9980
91fbd3111828
Almost backout afcd46716d6a which breaks _select_best raising an ambiguity exception in debug mode.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9947
diff
changeset
|
73 |
super(CWRegistry, self).__init__(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
|
74 |
self.vreg = vreg |
12785
a9025212ce0c
[debug-toolbar/registry] move to Registry.add_select_best_listener new api
Laurent Peuch <cortex@worlddomination.be>
parents:
12768
diff
changeset
|
75 |
self.add_select_best_listener(self._emit_registry_debug_information) |
2927
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
76 |
|
12785
a9025212ce0c
[debug-toolbar/registry] move to Registry.add_select_best_listener new api
Laurent Peuch <cortex@worlddomination.be>
parents:
12768
diff
changeset
|
77 |
def _emit_registry_debug_information(self, debug_registry_select_best): |
a9025212ce0c
[debug-toolbar/registry] move to Registry.add_select_best_listener new api
Laurent Peuch <cortex@worlddomination.be>
parents:
12768
diff
changeset
|
78 |
emit_to_debug_channel("registry_decisions", debug_registry_select_best) |
12768
7d2c61d40fe9
[debug-toolbar] add registry decisions debug panel
Laurent Peuch <cortex@worlddomination.be>
parents:
12567
diff
changeset
|
79 |
|
2927
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
80 |
@property |
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
81 |
def schema(self): |
10499
d0907690af55
[doc] move the documentations from docstring directly to the book.
David Douard <david.douard@logilab.fr>
parents:
10496
diff
changeset
|
82 |
"""The :py:class:`cubicweb.schema.CubicWebSchema` |
d0907690af55
[doc] move the documentations from docstring directly to the book.
David Douard <david.douard@logilab.fr>
parents:
10496
diff
changeset
|
83 |
""" |
2927
d249dd9000d9
use a property for schema, avoid bad schema reference
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2914
diff
changeset
|
84 |
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
|
85 |
|
2805
c6d10de521bc
R deprecate CWRegistry.possible_vobjects
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2800
diff
changeset
|
86 |
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
|
87 |
"""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
|
88 |
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
|
89 |
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
|
90 |
""" |
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
|
91 |
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
|
92 |
if x.cw_propval('visible')], |
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2815
diff
changeset
|
93 |
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
|
94 |
|
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
|
95 |
|
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
|
96 |
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
|
97 |
""" 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
|
98 |
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
|
99 |
""" |
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
100 |
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
|
101 |
|
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
|
102 |
|
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
103 |
class InstancesRegistry(CWRegistry): |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
104 |
|
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
105 |
def selected(self, winner, args, kwargs): |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
106 |
"""overriden to avoid the default 'instanciation' behaviour, ie |
10496
e95b559a06a2
[doc] more fixes of warnings/errors in doc build
David Douard <david.douard@logilab.fr>
parents:
9984
diff
changeset
|
107 |
`winner(*args, **kwargs)` |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
108 |
""" |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
109 |
return winner |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
110 |
|
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
111 |
|
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
|
112 |
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
|
113 |
|
6795
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6742
diff
changeset
|
114 |
def clear_caches(self): |
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6742
diff
changeset
|
115 |
clear_cache(self, 'etype_class') |
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6742
diff
changeset
|
116 |
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
|
117 |
_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
|
118 |
|
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
|
119 |
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
|
120 |
"""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
|
121 |
""" |
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
|
122 |
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
|
123 |
# 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
|
124 |
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
|
125 |
# 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
|
126 |
# (see #2719113) |
409ea1ed9832
[vreg]Â (re)build entity classes cache after registry initialization.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8719
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
|
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
|
130 |
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
|
131 |
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
|
132 |
oid = kwargs.get('oid') or obj.__regid__ |
12541
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
133 |
if oid != 'Any' and oid not 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
|
134 |
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
|
135 |
'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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
|
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
|
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
|
144 |
@cached |
2824
3455f72010fe
better as a method of the etypes registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
|
3455f72010fe
better as a method of the etypes registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2818
diff
changeset
|
152 |
@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
|
153 |
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
|
154 |
"""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
|
155 |
|
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
|
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
159 |
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
|
160 |
""" |
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
|
161 |
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
|
162 |
if etype == 'Any': |
4149
ecde9f78a080
etype_class('Any') should return bare 'Any' class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
163 |
objects = self['Any'] |
ecde9f78a080
etype_class('Any') should return bare 'Any' class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
# 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
|
169 |
# 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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
try: |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
# 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
|
182 |
# 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
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
# 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
|
189 |
# one |
2658
5535857eeaa5
[appobject selection process] drop the need for the .selected method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
190 |
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
|
191 |
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
|
192 |
cls = objects[0] |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
193 |
# make a copy event if cls.__regid__ == etype, else we may have pb for |
3035 | 194 |
# client application using multiple connections to different |
195 |
# repositories (eg shingouz) |
|
7423
598a4f051259
[cwvreg] inline function dump_class()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7304
diff
changeset
|
196 |
# __autogenerated__ attribute is just a marker |
598a4f051259
[cwvreg] inline function dump_class()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7304
diff
changeset
|
197 |
cls = type(str(etype), (cls,), {'__autogenerated__': True, |
598a4f051259
[cwvreg] inline function dump_class()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7304
diff
changeset
|
198 |
'__doc__': cls.__doc__, |
598a4f051259
[cwvreg] inline function dump_class()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7304
diff
changeset
|
199 |
'__module__': cls.__module__}) |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
200 |
cls.__regid__ = etype |
2807
696ff03f9a58
__initialize__ needs the schema as argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2804
diff
changeset
|
201 |
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
|
202 |
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
|
203 |
|
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
|
204 |
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
|
205 |
"""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
|
206 |
`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
|
207 |
""" |
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
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
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
|
213 |
|
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
|
214 |
|
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
|
215 |
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
|
216 |
|
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
217 |
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
|
218 |
"""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
|
219 |
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
|
220 |
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
|
221 |
""" |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
222 |
obj = self.select(oid, req, rset=rset, **kwargs) |
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
223 |
res = obj.render(**kwargs) |
12567
26744ad37953
Drop python2 support
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12549
diff
changeset
|
224 |
if isinstance(res, str): |
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
|
225 |
return res.encode(req.encoding) |
12567
26744ad37953
Drop python2 support
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12549
diff
changeset
|
226 |
assert isinstance(res, bytes) |
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
|
227 |
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
|
228 |
|
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
|
229 |
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
|
230 |
"""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
|
231 |
|
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
|
232 |
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
|
233 |
""" |
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
|
234 |
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
|
235 |
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
|
236 |
continue |
6454
97203d0af4cb
[test/possible views] skip deprecated views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
237 |
views = [view for view in views |
97203d0af4cb
[test/possible views] skip deprecated views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6162
diff
changeset
|
238 |
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
|
239 |
try: |
2770
356e9d7c356d
R propagate registry API changes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2705
diff
changeset
|
240 |
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
|
241 |
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
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
|
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
|
247 |
|
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
|
248 |
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
|
249 |
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
|
250 |
"""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
|
251 |
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
|
252 |
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
|
253 |
|
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 |
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
|
255 |
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
|
256 |
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
|
257 |
else: |
12541
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
258 |
actions = rset.possible_actions(**kwargs) # cached implementation |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
|
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 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
265 |
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
|
266 |
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
|
267 |
"""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
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
else: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
274 |
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
|
275 |
try: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
*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
|
280 |
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
|
281 |
components = [] |
352db17719d2
[ctxcomponents vreg] allow to specify 'no cache' using __cache argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
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
|
293 |
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
|
294 |
# 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
|
295 |
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
|
296 |
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
|
297 |
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
|
298 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
299 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
300 |
class CWRegistryStore(RegistryStore): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
301 |
"""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
|
302 |
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
|
303 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
304 |
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
|
305 |
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
|
306 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
311 |
* '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
|
312 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
313 |
* '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
|
314 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
315 |
* '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
|
316 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
317 |
* '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
|
318 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
319 |
* '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
|
320 |
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
|
321 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
322 |
* '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
|
323 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
324 |
* '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
|
325 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6069
diff
changeset
|
326 |
* '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
|
327 |
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
|
328 |
""" |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
329 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
330 |
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
|
331 |
'etypes': ETypeRegistry, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
332 |
'views': ViewsRegistry, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
333 |
'actions': ActionsRegistry, |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
334 |
'ctxcomponents': CtxComponentsRegistry, |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
335 |
'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
|
336 |
} |
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
337 |
|
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
|
338 |
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
|
339 |
if initlog: |
0e031b66cb0b
don't systematically init_log, it may breaks client log configuration
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
340 |
# 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
|
341 |
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
|
342 |
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
|
343 |
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
|
344 |
# 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
|
345 |
# 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
|
346 |
# 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
|
347 |
# 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
|
348 |
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
|
349 |
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
|
350 |
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
|
351 |
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
|
352 |
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
|
353 |
sys.path.remove(CW_SOFTWARE_ROOT) |
0 | 354 |
self.schema = None |
2906
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
355 |
self.initialized = False |
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
356 |
|
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
|
357 |
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
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
|
0 | 364 |
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
|
365 |
return [item for item in super(CWRegistryStore, self).items() |
0 | 366 |
if not item[0] in ('propertydefs', 'propertyvalues')] |
12541
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
367 |
|
2669
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
368 |
def iteritems(self): |
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10499
diff
changeset
|
369 |
return (item for item in super(CWRegistryStore, self).items() |
2669
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
370 |
if not item[0] in ('propertydefs', 'propertyvalues')) |
0 | 371 |
|
372 |
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
|
373 |
return [value for key, value in self.items()] |
12541
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
374 |
|
2669
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
375 |
def itervalues(self): |
cab66dfe0db6
to avoid confusions, implements iteritems/itervalues as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2659
diff
changeset
|
376 |
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
|
377 |
|
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
|
378 |
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
|
379 |
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
|
380 |
super(CWRegistryStore, self).reset() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
381 |
self._needs_appobject = {} |
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
382 |
# two special registries, propertydefs which care all the property |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
383 |
# definitions, and propertyvals which contains values for those |
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
384 |
# properties |
2906
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
385 |
if not self.initialized: |
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
386 |
self['propertydefs'] = {} |
677fa98659a8
fix cw properties initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2761
diff
changeset
|
387 |
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
|
388 |
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
|
389 |
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
|
390 |
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
|
391 |
|
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
|
392 |
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
|
393 |
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
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
|
c9ab72f0645d
[registry|ajaxcontroller] the @ajaxcontroller decorator ought to return a compatible object (closes #2385155)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
398 |
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
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
|
0 | 403 |
def set_schema(self, schema): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2389
diff
changeset
|
404 |
"""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
|
405 |
self._set_schema(schema) |
0 | 406 |
# now we can load application's web objects |
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
407 |
self.reload(self.config.appobjects_modnames(), 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
|
408 |
# 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
|
409 |
self.case_insensitive_etypes = {} |
3692
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
410 |
for eschema in self.schema.entities(): |
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
411 |
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
|
412 |
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
|
413 |
clear_cache(eschema, 'ordered_relations') |
54aa8d13aab4
clear eschema caches on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3641
diff
changeset
|
414 |
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
|
415 |
|
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
416 |
def is_reload_needed(self, modnames): |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
417 |
"""overriden to handle modules names instead of directories""" |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
418 |
lastmodifs = self._lastmodifs |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
419 |
for modname in modnames: |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
420 |
if modname not in sys.modules: |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
421 |
# new module to load |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
422 |
return True |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
423 |
filepath = sys.modules[modname].__file__ |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
424 |
if filepath.endswith('.py'): |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
425 |
mdate = self._mdate(filepath) |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
426 |
if filepath not in lastmodifs or lastmodifs[filepath] < mdate: |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
427 |
self.info('File %s changed since last visit', filepath) |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
428 |
return True |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
429 |
return False |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
430 |
|
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
|
431 |
def reload_if_needed(self): |
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
432 |
modnames = self.config.appobjects_modnames() |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
433 |
if self.is_reload_needed(modnames): |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
434 |
self.reload(modnames) |
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
|
435 |
|
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
436 |
def _cleanup_sys_modules(self, modnames): |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
437 |
"""Remove modules and submodules of `modnames` from `sys.modules` and cleanup |
9926
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
438 |
CW_EVENT_MANAGER accordingly. |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
439 |
|
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
440 |
We take care to properly remove obsolete registry callbacks. |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
441 |
|
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
442 |
""" |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
443 |
caches = {} |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
444 |
callbackdata = CW_EVENT_MANAGER.callbacks.values() |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
445 |
for callbacklist in callbackdata: |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
446 |
for callback in callbacklist: |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
447 |
func = callback[0] |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
448 |
# for non-function callable, we do nothing interesting |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
449 |
module = getattr(func, '__module__', None) |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
450 |
caches[id(callback)] = module |
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
451 |
deleted_modules = set(clean_sys_modules(modnames)) |
9926
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
452 |
for callbacklist in callbackdata: |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
453 |
for callback in callbacklist[:]: |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
454 |
module = caches[id(callback)] |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
455 |
if module and module in deleted_modules: |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
456 |
callbacklist.remove(callback) |
93a44cf0d030
[cwvreg] cleanup the event manager when reloading modules
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
8930
diff
changeset
|
457 |
|
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
458 |
def reload(self, modnames, 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
|
459 |
"""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
|
460 |
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
|
461 |
if force_reload: |
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
462 |
self._cleanup_sys_modules(modnames) |
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
|
463 |
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
|
464 |
# 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
|
465 |
# 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
|
466 |
# 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
|
467 |
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
|
468 |
for cube in cfg.expand_cubes(cubes, with_recommends=True): |
12541
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
469 |
if cube not in cubes: |
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
470 |
cube_modnames = cfg.appobjects_cube_modnames(cube) |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
471 |
self._cleanup_sys_modules(cube_modnames) |
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11767
diff
changeset
|
472 |
self.register_modnames(modnames) |
4966
e968e0a7776b
[registry] trigger reload events on set_schema()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4719
diff
changeset
|
473 |
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
|
474 |
|
9367
c8a5f7f43c03
instrument cwvreg, so we may know what's being loaded by asking the registry store
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9258
diff
changeset
|
475 |
def load_file(self, filepath, modname): |
c8a5f7f43c03
instrument cwvreg, so we may know what's being loaded by asking the registry store
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9258
diff
changeset
|
476 |
# override to allow some instrumentation (eg localperms) |
c8a5f7f43c03
instrument cwvreg, so we may know what's being loaded by asking the registry store
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9258
diff
changeset
|
477 |
modpath = modname.split('.') |
c8a5f7f43c03
instrument cwvreg, so we may know what's being loaded by asking the registry store
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9258
diff
changeset
|
478 |
try: |
c8a5f7f43c03
instrument cwvreg, so we may know what's being loaded by asking the registry store
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9258
diff
changeset
|
479 |
self.currently_loading_cube = modpath[modpath.index('cubes') + 1] |
c8a5f7f43c03
instrument cwvreg, so we may know what's being loaded by asking the registry store
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9258
diff
changeset
|
480 |
except ValueError: |
c8a5f7f43c03
instrument cwvreg, so we may know what's being loaded by asking the registry store
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9258
diff
changeset
|
481 |
self.currently_loading_cube = 'cubicweb' |
c8a5f7f43c03
instrument cwvreg, so we may know what's being loaded by asking the registry store
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9258
diff
changeset
|
482 |
return super(CWRegistryStore, self).load_file(filepath, modname) |
c8a5f7f43c03
instrument cwvreg, so we may know what's being loaded by asking the registry store
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9258
diff
changeset
|
483 |
|
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
|
484 |
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
|
485 |
"""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
|
486 |
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
|
487 |
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
|
488 |
|
0 | 489 |
def update_schema(self, schema): |
490 |
"""update .schema attribute on registered objects, necessary for some |
|
491 |
tests |
|
492 |
""" |
|
493 |
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
|
494 |
for registry, regcontent in self.items(): |
10663
54b8a1f249fb
[py3k] dict.itervalues → dict.values
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10662
diff
changeset
|
495 |
for objects in regcontent.values(): |
0 | 496 |
for obj in objects: |
497 |
obj.schema = schema |
|
666
8ad9885ea45a
interface handling should be done here
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
498 |
|
3055
06814d57514f
[vreg] keep positional arg compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2927
diff
changeset
|
499 |
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
|
500 |
"""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
|
501 |
`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
|
502 |
`obj.__regid__` if not specified. |
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
503 |
|
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
504 |
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
|
505 |
previously unregistered. |
43afbdd5c8b4
improved doc on selectors an vregistry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5080
diff
changeset
|
506 |
""" |
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
|
507 |
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
|
508 |
super(CWRegistryStore, self).register(obj, *args, **kwargs) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
509 |
depends_on = require_appobject(obj) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
510 |
if depends_on is not None: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
511 |
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
|
512 |
|
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
513 |
def initialization_completed(self): |
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
514 |
"""cw specific code once vreg initialization is completed: |
0 | 515 |
|
9258
4e79f587c6ab
Rename cleanup_interface_sobjects into cleanup_unused_appobjects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9256
diff
changeset
|
516 |
* remove objects requiring a missing appobject, unless |
4e79f587c6ab
Rename cleanup_interface_sobjects into cleanup_unused_appobjects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9256
diff
changeset
|
517 |
config.cleanup_unused_appobjects is false |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
518 |
* init rtags |
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
519 |
""" |
1638 | 520 |
# we may want to keep interface dependent objects (e.g.for i18n |
521 |
# catalog generation) |
|
9258
4e79f587c6ab
Rename cleanup_interface_sobjects into cleanup_unused_appobjects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9256
diff
changeset
|
522 |
if self.config.cleanup_unused_appobjects: |
9256
697a8181ba30
remove 3.9 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8930
diff
changeset
|
523 |
# remove appobjects which depend on other, unexistant appobjects |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
524 |
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
|
525 |
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
|
526 |
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
|
527 |
except RegistryNotFound: |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
528 |
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
|
529 |
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
|
530 |
continue |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
531 |
for regid in regids: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
532 |
if registry.get(regid): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
533 |
break |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5446
diff
changeset
|
534 |
else: |
6014
a5e22657f6f4
[debug] improve debug messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5890
diff
changeset
|
535 |
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
|
536 |
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
|
537 |
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
|
538 |
super(CWRegistryStore, self).initialization_completed() |
12541
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
539 |
if 'uicfg' in self: # 'uicfg' is not loaded in a pure repository mode |
10663
54b8a1f249fb
[py3k] dict.itervalues → dict.values
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10662
diff
changeset
|
540 |
for rtags in self['uicfg'].values(): |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8663
diff
changeset
|
541 |
for rtag in rtags: |
9258
4e79f587c6ab
Rename cleanup_interface_sobjects into cleanup_unused_appobjects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9256
diff
changeset
|
542 |
# don't check rtags if we don't want to cleanup_unused_appobjects |
4e79f587c6ab
Rename cleanup_interface_sobjects into cleanup_unused_appobjects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9256
diff
changeset
|
543 |
rtag.init(self.schema, check=self.config.cleanup_unused_appobjects) |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
544 |
|
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
|
545 |
# 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
|
546 |
|
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
|
547 |
@property |
0 | 548 |
@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
|
549 |
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
|
550 |
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
|
551 |
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
|
552 |
|
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
|
553 |
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
|
554 |
def type_from_eid(eid, req=req): |
11765
9cb215e833b0
[cnx] Use entity_type instead of entity_metas()['type']
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11249
diff
changeset
|
555 |
return req.entity_type(eid) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5147
diff
changeset
|
556 |
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
|
557 |
|
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
|
558 |
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
|
559 |
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
|
560 |
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
|
561 |
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
|
562 |
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
|
563 |
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
|
564 |
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
|
565 |
return rqlst |
0 | 566 |
|
567 |
# properties handling ##################################################### |
|
568 |
||
569 |
def user_property_keys(self, withsitewide=False): |
|
570 |
if withsitewide: |
|
2223
59588e2d5cd1
close #343467, no sources sections in site properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
571 |
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
|
572 |
if not k.startswith('sources.')) |
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10499
diff
changeset
|
573 |
return sorted(k for k, kd in self['propertydefs'].items() |
2223
59588e2d5cd1
close #343467, no sources sections in site properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2025
diff
changeset
|
574 |
if not kd['sitewide'] and not k.startswith('sources.')) |
0 | 575 |
|
576 |
def register_property(self, key, type, help, default=None, vocabulary=None, |
|
577 |
sitewide=False): |
|
578 |
"""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
|
579 |
properties = self['propertydefs'] |
7465
bb0c89d1a078
[vreg] help understanding assertion error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7302
diff
changeset
|
580 |
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
|
581 |
properties[key] = {'type': type, 'vocabulary': vocabulary, |
0 | 582 |
'default': default, 'help': help, |
583 |
'sitewide': sitewide} |
|
584 |
||
585 |
def property_info(self, key): |
|
586 |
"""return dictionary containing description associated to the given |
|
587 |
property key (including type, defaut value, help and a site wide |
|
588 |
boolean) |
|
589 |
""" |
|
590 |
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
|
591 |
return self['propertydefs'][key] |
0 | 592 |
except KeyError: |
593 |
if key.startswith('system.version.'): |
|
594 |
soft = key.split('.')[-1] |
|
595 |
return {'type': 'String', 'sitewide': True, |
|
596 |
'default': None, 'vocabulary': None, |
|
597 |
'help': _('%s software version of the database') % soft} |
|
598 |
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
|
599 |
|
0 | 600 |
def property_value(self, key): |
601 |
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
|
602 |
return self['propertyvalues'][key] |
0 | 603 |
except KeyError: |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
604 |
return self.property_info(key)['default'] |
0 | 605 |
|
606 |
def typed_value(self, key, value): |
|
9701
46c8d8701240
an unicode string -> a unicode string
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9367
diff
changeset
|
607 |
"""value is a unicode string, return it correctly typed. Let potential |
0 | 608 |
type error propagates. |
609 |
""" |
|
610 |
pdef = self.property_info(key) |
|
611 |
try: |
|
612 |
value = YAMS_TO_PY[pdef['type']](value) |
|
613 |
except (TypeError, ValueError): |
|
614 |
raise ValueError(_('bad value')) |
|
615 |
vocab = pdef['vocabulary'] |
|
616 |
if vocab is not None: |
|
617 |
if callable(vocab): |
|
12541
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
618 |
vocab = vocab(None) # XXX need a req object |
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
619 |
if value not in vocab: |
0 | 620 |
raise ValueError(_('unauthorized value')) |
621 |
return value |
|
1475
5c1ec97f317e
should not be necessary anymore to add entity class to __implements__
sylvain.thenault@logilab.fr
parents:
1357
diff
changeset
|
622 |
|
0 | 623 |
def init_properties(self, propvalues): |
624 |
"""init the property values registry using the given set of couple (key, value) |
|
625 |
""" |
|
626 |
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
|
627 |
values = self['propertyvalues'] |
0 | 628 |
for key, val in propvalues: |
629 |
try: |
|
630 |
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
|
631 |
except ValueError as ex: |
0 | 632 |
self.warning('%s (you should probably delete that property ' |
633 |
'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
|
634 |
except UnknownProperty as ex: |
0 | 635 |
self.warning('%s (you should probably delete that property ' |
636 |
'from the database)', ex) |
|
637 |
||
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
|
638 |
|
7460
2455cdbeadca
[schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7423
diff
changeset
|
639 |
# 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
|
640 |
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
|
641 |
YAMS_TO_PY.update({ |
12541
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
642 |
'Bytes': Binary, |
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
643 |
'Date': date, |
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
644 |
'Datetime': datetime, |
7166
dde161937d3e
[time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7154
diff
changeset
|
645 |
'TZDatetime': datetime, |
12541
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
646 |
'Time': time, |
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
647 |
'TZTime': time, |
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
648 |
'Interval': timedelta, |
bbbccb0b3a66
Flake8 cubicweb/cwvreg.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12540
diff
changeset
|
649 |
}) |