Пример #1
0
    def destroy(self, request: Request, *args, **kwargs) -> Response:
        storage = get_object_or_404(Storage.objects.all(),
                                    pk=self.kwargs['storage_id'])
        if not StorageUser.userMayWriteStorage(self.request.user, storage):
            return Response({'message': Messages.MSG_NO_STORAGE_WRITE_PERM},
                            status=status.HTTP_403_FORBIDDEN)

        file = get_object_or_404(self.get_queryset(), id=self.kwargs['pk'])
        file.excluded = True
        file.updated_by = request.user
        file.save()
        return Response(status=status.HTTP_204_NO_CONTENT)
Пример #2
0
    def get_object(self):
        """
        Returns the object the view is displaying.

        You may want to override this if you need to provide non-standard
        queryset lookups.  Eg if objects are referenced using multiple
        keyword arguments in the url conf.
        """
        queryset = self.filter_queryset(self.get_queryset())

        # Perform the lookup filtering.
        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

        assert lookup_url_kwarg in self.kwargs, (
            'Expected view %s to be called with a URL keyword argument '
            'named "%s". Fix your URL conf, or set the `.lookup_field` '
            'attribute on the view correctly.' %
            (self.__class__.__name__, lookup_url_kwarg))

        filter_kwargs = {self.lookup_field: self.kwargs[lookup_url_kwarg]}
        obj = get_object_or_404(queryset, **filter_kwargs)

        # May raise a permission denied
        self.check_object_permissions(self.request, obj)

        return obj
Пример #3
0
 def partial_update(self, request: Request, *args, **kwargs) -> Response:
     storage = get_object_or_404(Storage.objects.all(),
                                 id=self.kwargs['storage_id'])
     if not StorageUser.userMayReadStorage(request.user, storage):
         return Response({'message': Messages.MSG_NO_STORAGE_READ_PERM},
                         status=status.HTTP_403_FORBIDDEN)
     return super(StorageFileViewSet, self).partial_update(request=request,
                                                           *args,
                                                           **kwargs)
Пример #4
0
    def create(self, request: Request, *args, **kwargs) -> Response:
        storage = get_object_or_404(Storage.objects.all(), id=self.kwargs['storage_id'])
        request.data['storage'] = str(storage.id)
        request.data['created_by'] = request.user.username

        user = get_user_from_service(request)
        request.data['user'] = str(user.id)

        return super(StorageUserViewSet, self).create(request=request, *args, **kwargs)
Пример #5
0
 def get_queryset(self) -> QuerySet:
     storage = get_object_or_404(Storage.objects.all(),
                                 id=self.kwargs['storage_id'])
     queryset = StorageFile.objects.filter(storage=storage)
     return queryset
Пример #6
0
 def partial_update(self, request: Request, *args, **kwargs) -> Response:
     storage = get_object_or_404(Storage.objects.all(), id=self.kwargs['storage_id'])
     request.data['storage'] = str(storage.id)
     request.data['updated_by'] = request.user.username
     return super(StorageUserViewSet, self).partial_update(request=request, *args, **kwargs)