def plugin(module, *args, **kwargs):
    """
    Decorator to extend a package to a view.
    The module can be a class or function. It will copy all the methods to the class

    ie:
        # Your module.py
        my_ext(view, **kwargs):
            class MyExtension(object):
                def my_view(self):
                    return {}

            return MyExtension

        # Your view.py
        @plugin(my_ext)
        class Index(View):
            pass

    :param module: object
    :param args:
    :param kwargs:
    :return:
    """
    def wrap(f):
        m = module(f, *args, **kwargs)
        if inspect.isclass(m):
            for k, v in m.__dict__.items():
                if not k.startswith("__"):
                    setattr(f, k, v)
        elif inspect.isfunction(m):
            setattr(f, kls.__name__, m)
        return f
    return wrap