def load(self, module): """Load a specific module. This method: Get the Controller class defined in the module Get the controller's bundle Instanciate the Controller class Set the server instance attribute Write the newly created object in the bundle's controllers Return the object """ bundle_name = Rule.bundle_name(module) bundle = self.server.bundles[bundle_name] name = Rule.module_name(module) class_name = name.capitalize() ctl_class = getattr(module, class_name) ctl_object = ctl_class(bundle) ctl_object.server = self.server # Write the object in the bundle bundle.controllers[class_name] = ctl_object # Add the controller's routes routes = tuple(bundle.config.routes.items()) routes = [(name, infos) for name, infos in routes if infos[1] == \ class_name] for route, (pattern, ctl_name, action, methods) in routes: action = getattr(ctl_object, action) self.server.dispatcher.add_route(route, pattern, ctl_object, \ action, methods) return ctl_object
def load(self, module): """Load a specific module. This method: Get the Model class defined in the module Set the data_connector class attribute of this class Write this dclass in the model's bundle Return the class """ name = Rule.module_name(module) class_name = name.capitalize() mod_class = getattr(module, class_name) mod_class.data_connector = self.data_connector self.data_connector.record_model(mod_class) # Write the class in the bundles bundle_name = Rule.bundle_name(module) self.server.bundles[bundle_name].models[class_name] = mod_class return mod_class