示例#1
0
    def get_permissions(self):
        if self.action in ('update', 'partial_update'):
            self.permission_classes = (IsMember, )
        elif is_custom_action(self.action):
            pass
        else:
            self.permission_classes = (IsAuthenticatedOrReadOnly, )

        return super().get_permissions()
示例#2
0
 def get_serializer_class(self):
     if self.action == 'create':
         self.serializer_class = GroupDetailSerializer
     elif self.action in ('retrieve', 'update', 'partial_update'):
         self.serializer_class = GroupPreviewSerializer
         try:
             if self.request.user in self.get_object().members.all():
                 self.serializer_class = GroupDetailSerializer
         except AssertionError:
             # Swagger (using OpenAPI) does not give a pk, therefore
             # we can't determine if it's legit to return the Detail serializer
             pass
     elif is_custom_action(self.action):
         pass
     else:
         self.serializer_class = GroupPreviewSerializer
     return self.serializer_class