permissions.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:baya 作者: counsyl 项目源码 文件源码
def __call__(self, fn, *args, **kwargs):
        """Delegate the decoration to the appropriate method."""
        if isinstance(fn, functools.partial) and not hasattr(fn, '__module__'):
            raise ValueError(
                'Cannot decorate a bare functools.partial view.  '
                'You must invoke functools.update_wrapper(partial_view, '
                'full_view) first.')
        if not isinstance(fn, type) and isinstance(fn, collections.Callable):
            return self.decorate_method(fn, *args, **kwargs)
        elif isinstance(fn, tuple):
            # Must be an include('my_app.urls') we're decorating
            return self.decorate_include(fn, *args, **kwargs)
        elif isinstance(fn, (RegexURLPattern, RegexURLResolver)):
            return self.decorate_url_pattern(fn, *args, **kwargs)
        elif isinstance(fn, type) and issubclass(fn, BaseModelAdmin):
            if issubclass(fn, InlineModelAdmin):
                raise TypeError("Cannot decorate Inlines. See "
                                "baya.admin.options.BayaInline instead.")
            return self.decorate_admin(fn, *args, **kwargs)
        elif isinstance(fn, six.string_types):
            raise TypeError("Cannot decorate string-path to view: %s." % fn)
        else:
            # You'll probably only get here if you're trying to decorate
            # a class-based view
            raise TypeError(
                "Invalid type for requires decorator (%s). "
                "You cannot decorate class-based views. Decorate "
                "the URL or the as_view method instead." % type(fn))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号