Esempio n. 1
0
    def __call__(self, context):
        path       = context.path
        method     = context.method
        controller = None
        action     = None
        cls        = None
        result     = None

        try:
            controller, action = self.action_with_method(method)
        except KeyError as e:
            raise exceptions.RouteExecutionException(path, e.message)

        if controller not in route_controller_registry:
            cls = import_class(controller)
            route_controller_registry[controller] = cls
        else:
            cls = route_controller_registry[controller]

        params = {}

        if self.params:
            result = self.pattern.match(path)
            params = dict(zip(self.params, result.groups()))

        obj = cls()
        obj._current_context = context
        
        try:
            init = getattr(obj, "initialize")
            init(context.request)
        except KeyError:
            # initialize is optional
            pass
        
        method = getattr(obj, action)
        
        try:
            result = method(**params)

            if result is not None:
                result._current_context = context

        except Exception as e:
            raise exceptions.RouteExecutionException(path, "{0} in {1}.{2}".format(e.message, controller, action))
        
        return result
Esempio n. 2
0
    def initialize_default_view(self, section):

        view_path = None
        try:
            view_path        = section["default_view"]
        except KeyError:
            crazyhorse.get_logger().warning("No default_view specified in config. Calling MyController.view() will throw error")
            return

        crazyhorse.get_logger().debug("Registering default view: {0}".format(view_path))

        cls = import_class(view_path)

        if cls:
            CrazyHorseController.view_class = cls
            return

        crazyhorse.get_logger().fatal("Failed to import specified default view: {0}. Calling MyController.view() will throw error".format(view_path))
        raise exceptions.ConfigurationErrorException("Failed to import specified default view")
Esempio n. 3
0
    def initialize_custom_section(self, config, meta):

        name    = meta["name"]
        pkg     = meta["type"]
        cls     = import_class(pkg)
        obj     = None
        section = None

        crazyhorse.get_logger().debug("Processing {0} Configuration".format(cls.__name__))

        if name in config:
            section = config[name]

        obj = cls()

        config_name = "CUSTOM_" + name.upper().replace("-", "_")

        if section:
            setattr(Configuration, config_name, obj(section))
        else:
            setattr(Configuration, config_name, obj())
Esempio n. 4
0
 def load_feature(self, pkg):
     obj = import_class(pkg)
     return obj