def load(self, module): """Load a specific module. This method: Get the Repository class defined in the module Write this class in the bundle's repositories Return the class """ name = Rule.module_name(module) bundle_name = Rule.bundle_name(module) bundle = self.server.bundles[bundle_name] rep_class = Rule.find_class(module, Repository) # Write the class in the bundles model_name = self.get_model_name(rep_class) bundle.repositories[model_name] = rep_class return rep_class
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.routes.items()) routes = [(name, infos) for name, infos in routes if infos[1] == \ class_name] for route, (pattern, ctl_name, action, methods) in routes: route_name = bundle_name + "." + route function = getattr(ctl_object, action) route = self.server.dispatcher.add_route( route_name, pattern, ctl_object, function, methods) route.bundle = bundle route.controller_name = class_name route.action_name = action return ctl_object
def load(self, module): """Load a specific module. This method: Get the Model class defined in the module Try to find the corresponding repository Write this dclass in the model's bundle Return the class """ name = Rule.module_name(module) bundle_name = Rule.bundle_name(module) bundle = self.server.bundles[bundle_name] class_name = name.capitalize() mod_class = getattr(module, class_name) mod_class.bundle = bundle mod_name = get_name(mod_class) # Try to find the corresponding repository if mod_name in bundle.repositories: rep_class = bundle.repositories[mod_name] print("Found the repository", rep_class) else: rep_class = Repository print("Create a new repository") repository = rep_class(self.data_connector, mod_class) mod_class._repository = repository # Write the class in the bundles bundle.models[mod_name] = mod_class # Record the new bundle in the data connector self.data_connector.repository_manager.record_model(mod_class) return mod_class