1 """extend the generic VRegistry with some cubicweb specific stuff |
1 """extend the generic VRegistry with some cubicweb specific stuff |
2 |
2 |
3 :organization: Logilab |
3 :organization: Logilab |
4 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 __docformat__ = "restructuredtext en" |
7 __docformat__ = "restructuredtext en" |
8 |
8 |
9 from warnings import warn |
9 from warnings import warn |
10 |
10 |
11 from logilab.common.decorators import cached, clear_cache |
11 from logilab.common.decorators import cached, clear_cache |
|
12 from logilab.common.interface import extend |
12 |
13 |
13 from rql import RQLHelper |
14 from rql import RQLHelper |
14 |
15 |
15 from cubicweb import Binary, UnknownProperty |
16 from cubicweb import Binary, UnknownProperty |
16 from cubicweb.vregistry import VRegistry, ObjectNotFound, NoSelectableObject |
17 from cubicweb.vregistry import VRegistry, ObjectNotFound, NoSelectableObject |
127 """return an entity class for the given entity type. |
128 """return an entity class for the given entity type. |
128 Try to find out a specific class for this kind of entity or |
129 Try to find out a specific class for this kind of entity or |
129 default to a dump of the class registered for 'Any' |
130 default to a dump of the class registered for 'Any' |
130 """ |
131 """ |
131 etype = str(etype) |
132 etype = str(etype) |
|
133 if etype == 'Any': |
|
134 return self.select(self.registry_objects('etypes', 'Any'), 'Any') |
132 eschema = self.schema.eschema(etype) |
135 eschema = self.schema.eschema(etype) |
133 baseschemas = [eschema] + eschema.ancestors() |
136 baseschemas = [eschema] + eschema.ancestors() |
134 # browse ancestors from most specific to most generic and |
137 # browse ancestors from most specific to most generic and |
135 # try to find an associated custom entity class |
138 # try to find an associated custom entity class |
136 for baseschema in baseschemas: |
139 for baseschema in baseschemas: |
137 btype = str(baseschema) |
140 btype = str(baseschema) |
138 try: |
141 try: |
139 return self.select(self.registry_objects('etypes', btype), etype) |
142 cls = self.select(self.registry_objects('etypes', btype), etype) |
|
143 break |
140 except ObjectNotFound: |
144 except ObjectNotFound: |
141 pass |
145 pass |
142 # no entity class for any of the ancestors, fallback to the default one |
146 else: |
143 return self.select(self.registry_objects('etypes', 'Any'), etype) |
147 # no entity class for any of the ancestors, fallback to the default |
144 |
148 # one |
|
149 cls = self.select(self.registry_objects('etypes', 'Any'), etype) |
|
150 # add class itself to the list of implemented interfaces, as well as the |
|
151 # Any entity class so we can select according to class using the |
|
152 # `implements` selector |
|
153 extend(cls, cls) |
|
154 extend(cls, self.etype_class('Any')) |
|
155 return cls |
|
156 |
145 def render(self, registry, oid, req, **context): |
157 def render(self, registry, oid, req, **context): |
146 """select an object in a given registry and render it |
158 """select an object in a given registry and render it |
147 |
159 |
148 - registry: the registry's name |
160 - registry: the registry's name |
149 - oid : the view to call |
161 - oid : the view to call |