vregistry.py
changeset 2968 0e3460341023
parent 2844 4657d6e16e0c
parent 2906 677fa98659a8
child 3072 6fb42c53f6df
equal deleted inserted replaced
2902:dd9f2dd02f85 2968:0e3460341023
   136             result += objs
   136             result += objs
   137         return result
   137         return result
   138 
   138 
   139     # dynamic selection methods ################################################
   139     # dynamic selection methods ################################################
   140 
   140 
   141     @deprecated('[3.5] use select instead of object_by_id')
   141     @deprecated('[3.6] use select instead of object_by_id')
   142     def object_by_id(self, oid, *args, **kwargs):
   142     def object_by_id(self, oid, *args, **kwargs):
   143         """return object with the given oid. Only one object is expected to be
   143         """return object with the given oid. Only one object is expected to be
   144         found.
   144         found.
   145 
   145 
   146         raise `ObjectNotFound` if not object with id <oid> in <registry>
   146         raise `ObjectNotFound` if not object with id <oid> in <registry>
   165         """
   165         """
   166         try:
   166         try:
   167             return self.select(oid, *args, **kwargs)
   167             return self.select(oid, *args, **kwargs)
   168         except (NoSelectableObject, ObjectNotFound):
   168         except (NoSelectableObject, ObjectNotFound):
   169             return None
   169             return None
   170     select_object = deprecated('[3.5] use select_or_none instead of select_object'
   170     select_object = deprecated('[3.6] use select_or_none instead of select_object'
   171                                )(select_or_none)
   171                                )(select_or_none)
   172 
   172 
   173     def possible_objects(self, *args, **kwargs):
   173     def possible_objects(self, *args, **kwargs):
   174         """return an iterator on possible objects in this registry for the given
   174         """return an iterator on possible objects in this registry for the given
   175         context
   175         context
   208                 raise Exception('select ambiguity, args: %s\nkwargs: %s %s'
   208                 raise Exception('select ambiguity, args: %s\nkwargs: %s %s'
   209                                 % (args, kwargs.keys(),
   209                                 % (args, kwargs.keys(),
   210                                    [repr(v) for v in winners]))
   210                                    [repr(v) for v in winners]))
   211         # return the result of calling the appobject
   211         # return the result of calling the appobject
   212         return winners[0](*args, **kwargs)
   212         return winners[0](*args, **kwargs)
   213     select_best = deprecated('[3.5] select_best is now private')(_select_best)
   213     select_best = deprecated('[3.6] select_best is now private')(_select_best)
   214 
   214 
   215 class VRegistry(dict):
   215 class VRegistry(dict):
   216     """class responsible to register, propose and select the various
   216     """class responsible to register, propose and select the various
   217     elements used to build the web interface. Currently, we have templates,
   217     elements used to build the web interface. Currently, we have templates,
   218     views, actions and components.
   218     views, actions and components.
   221     def __init__(self, config):
   221     def __init__(self, config):
   222         super(VRegistry, self).__init__()
   222         super(VRegistry, self).__init__()
   223         self.config = config
   223         self.config = config
   224 
   224 
   225     def reset(self, path=None, force_reload=None):
   225     def reset(self, path=None, force_reload=None):
   226         self.clear()
   226         # don't use self.clear, we want to keep existing subdictionaries
       
   227         for subdict in self.itervalues():
       
   228             subdict.clear()
   227         self._lastmodifs = {}
   229         self._lastmodifs = {}
   228 
   230 
   229     def __getitem__(self, name):
   231     def __getitem__(self, name):
   230         """return the registry (dictionary of class objects) associated to
   232         """return the registry (dictionary of class objects) associated to
   231         this name
   233         this name