Python rest_framework.viewsets 模块,GenericViewSet() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用rest_framework.viewsets.GenericViewSet()

项目:apimas    作者:grnet    | 项目源码 | 文件源码
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)
项目:vaultier    作者:Movile    | 项目源码 | 文件源码
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)
项目:djangocon2017viewsets    作者:buddylindsey    | 项目源码 | 文件源码
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)