123 result += objs |
123 result += objs |
124 return result |
124 return result |
125 |
125 |
126 # dynamic selection methods ################################################ |
126 # dynamic selection methods ################################################ |
127 |
127 |
|
128 @deprecated('use select instead of object_by_id') |
128 def object_by_id(self, oid, *args, **kwargs): |
129 def object_by_id(self, oid, *args, **kwargs): |
129 """return object with the given oid. Only one object is expected to be |
130 """return object with the given oid. Only one object is expected to be |
130 found. |
131 found. |
131 |
132 |
132 raise `ObjectNotFound` if not object with id <oid> in <registry> |
133 raise `ObjectNotFound` if not object with id <oid> in <registry> |
141 according to the given context. |
142 according to the given context. |
142 |
143 |
143 raise `ObjectNotFound` if not object with id <oid> in <registry> |
144 raise `ObjectNotFound` if not object with id <oid> in <registry> |
144 raise `NoSelectableObject` if not object apply |
145 raise `NoSelectableObject` if not object apply |
145 """ |
146 """ |
146 return self.select_best(self[oid], *args, **kwargs) |
147 return self._select_best(self[oid], *args, **kwargs) |
147 |
148 |
148 def select_object(self, oid, *args, **kwargs): |
149 def select_or_none(self, oid, *args, **kwargs): |
149 """return the most specific object among those with the given oid |
150 """return the most specific object among those with the given oid |
150 according to the given context, or None if no object applies. |
151 according to the given context, or None if no object applies. |
151 """ |
152 """ |
152 try: |
153 try: |
153 return self.select(oid, *args, **kwargs) |
154 return self.select(oid, *args, **kwargs) |
154 except (NoSelectableObject, ObjectNotFound): |
155 except (NoSelectableObject, ObjectNotFound): |
155 return None |
156 return None |
|
157 select_object = deprecated('use select_or_none instead of select_object' |
|
158 )(select_or_none) |
156 |
159 |
157 def possible_objects(self, *args, **kwargs): |
160 def possible_objects(self, *args, **kwargs): |
158 """return an iterator on possible objects in this registry for the given |
161 """return an iterator on possible objects in this registry for the given |
159 context |
162 context |
160 """ |
163 """ |
161 for appobjects in self.itervalues(): |
164 for appobjects in self.itervalues(): |
162 try: |
165 try: |
163 yield self.select_best(appobjects, *args, **kwargs) |
166 yield self._select_best(appobjects, *args, **kwargs) |
164 except NoSelectableObject: |
167 except NoSelectableObject: |
165 continue |
168 continue |
166 |
169 |
167 def select_best(self, appobjects, *args, **kwargs): |
170 def _select_best(self, appobjects, *args, **kwargs): |
168 """return an instance of the most specific object according |
171 """return an instance of the most specific object according |
169 to parameters |
172 to parameters |
170 |
173 |
171 raise `NoSelectableObject` if not object apply |
174 raise `NoSelectableObject` if not object apply |
172 """ |
175 """ |
192 raise Exception('select ambiguity, args: %s\nkwargs: %s %s' |
195 raise Exception('select ambiguity, args: %s\nkwargs: %s %s' |
193 % (args, kwargs.keys(), |
196 % (args, kwargs.keys(), |
194 [repr(v) for v in winners])) |
197 [repr(v) for v in winners])) |
195 # return the result of calling the appobject |
198 # return the result of calling the appobject |
196 return winners[0](*args, **kwargs) |
199 return winners[0](*args, **kwargs) |
197 |
200 select_best = deprecated('select_best is now private')(_select_best) |
198 |
201 |
199 class VRegistry(dict): |
202 class VRegistry(dict): |
200 """class responsible to register, propose and select the various |
203 """class responsible to register, propose and select the various |
201 elements used to build the web interface. Currently, we have templates, |
204 elements used to build the web interface. Currently, we have templates, |
202 views, actions and components. |
205 views, actions and components. |