python类GenericViewSet()的实例源码

views.py 文件源码 项目:apimas 作者: grnet 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_bases_classes(mixins, hook_class, actions):
    """
    This function gets the corresponding base classes in order to construct
    the viewset class.

    A model can specify the allowed operations to it, e.g. update,
    list, delete, etc. Then, a viewset specify the allowed methods based on
    model's allowed operations by defining the corresponding bases classes.

    By default, all methods are allowed.

    Apart from this, also configration object can also include custom mixins
    classes. Therefore, they are also added to the list of bases classes.

    :returns: A tuple of the corresponding base classes.
    """
    hook_class = utils.import_object(hook_class) if hook_class\
        else view_mixins.HookMixin
    mixins = map(utils.LOAD_CLASS, mixins)
    bases = (viewsets.GenericViewSet,) if not actions\
        else tuple([MIXINS[action] for action in actions]) + (
            viewsets.GenericViewSet,)
    return (hook_class,) + tuple(mixins) + tuple(bases)
viewsets.py 文件源码 项目:vaultier 作者: Movile 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def initial(self, request, *args, **kwargs):
        """
        Call check_method if present and returns parent
        """
        if hasattr(self, 'filter_method'):
            self.filter_method(request)

        return super(GenericViewSet, self).initial(request, args, kwargs)
tests.py 文件源码 项目:djangocon2017viewsets 作者: buddylindsey 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_attrs(self):
        self.assertIsInstance(self.view, mixins.CreateModelMixin)
        self.assertIsInstance(self.view, mixins.ListModelMixin)
        self.assertIsInstance(self.view, mixins.UpdateModelMixin)
        self.assertIsInstance(self.view, mixins.RetrieveModelMixin)
        self.assertIsInstance(self.view, mixins.DestroyModelMixin)
        self.assertIsInstance(self.view, viewsets.GenericViewSet)

        self.assertEqual(self.view.permission_classes, (IsAuthenticated,))
        self.assertEqual(self.view.serializer_class, CoinSerializer)
        self.assertSequenceEqual(
            self.view.filter_backends,
            (filters.DjangoFilterBackend, BitFilter))

        self.assertEqual(self.view.filter_class, CoinFilter)


问题


面经


文章

微信
公众号

扫码关注公众号