|
@@ -1,4 +1,5 @@
|
|
|
-from django.views.decorators.http import require_POST
|
|
|
+from django.shortcuts import get_object_or_404
|
|
|
+
|
|
|
from rest_framework import status
|
|
|
from rest_framework.decorators import permission_classes
|
|
|
from rest_framework.response import Response
|
|
@@ -10,87 +11,10 @@ from pycs_api.views.base import BaseViewSet
|
|
|
|
|
|
class ProjectViewSet(BaseViewSet):
|
|
|
|
|
|
- queryset = Project.objects.all().order_by("id")
|
|
|
serializer_class = ProjectSerializer
|
|
|
|
|
|
- def list(self, request):
|
|
|
- if request.user.is_anonymous:
|
|
|
- return Response('Unauthorized',
|
|
|
- status=status.HTTP_401_UNAUTHORIZED)
|
|
|
-
|
|
|
- projects = request.user.projects.all()
|
|
|
- serializer = self.get_serializer(projects, many=True)
|
|
|
- return Response(serializer.data)
|
|
|
-
|
|
|
- def create(self, request):
|
|
|
- if request.user.is_anonymous:
|
|
|
- return Response('Unauthorized',
|
|
|
- status=status.HTTP_401_UNAUTHORIZED)
|
|
|
-
|
|
|
- project = Project(
|
|
|
- user=request.user,
|
|
|
- **request.data
|
|
|
- )
|
|
|
-
|
|
|
- project.save()
|
|
|
- serializer = self.get_serializer(project)
|
|
|
- return Response(serializer.data)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-# class ProjectView(JsonResponseView):
|
|
|
-
|
|
|
-# """
|
|
|
-# serves POST and GET for '/projects/'
|
|
|
-
|
|
|
-# staticmethods serve POST methods for
|
|
|
-# '/projects/<id>/name'
|
|
|
-# '/projects/<id>/description'
|
|
|
-# '/projects/<id>/remove'
|
|
|
-# """
|
|
|
-
|
|
|
-# http_method_names = ["get", "post"]
|
|
|
-
|
|
|
-
|
|
|
-# def get(self, request, *args, **kwargs):
|
|
|
-# """ lists projects """
|
|
|
-# return self.respond([
|
|
|
-# dict(name="Project 1", description="Desc1", ),
|
|
|
-# dict(name="Project 2", description="Desc2"),
|
|
|
-# ])
|
|
|
-
|
|
|
-# def post(self, request, *args, **kwargs):
|
|
|
-# """ creates a project """
|
|
|
-# return self.respond()
|
|
|
-
|
|
|
-
|
|
|
-# @require_POST
|
|
|
-# @classmethod
|
|
|
-# def remove(cls, request, project_id: int):
|
|
|
-# """ removes a project """
|
|
|
-# return cls.respond()
|
|
|
-
|
|
|
-# @require_POST
|
|
|
-# @classmethod
|
|
|
-# def edit_name(cls, request, project_id: int):
|
|
|
-# """ edit project's name """
|
|
|
-# return cls.respond()
|
|
|
-
|
|
|
-# @require_POST
|
|
|
-# @classmethod
|
|
|
-# def edit_description(cls, request, project_id: int):
|
|
|
-# """ edit project's description """
|
|
|
-# return cls.respond()
|
|
|
-
|
|
|
-# @require_POST
|
|
|
-# @classmethod
|
|
|
-# def run_external_storage(cls, request, project_id: int):
|
|
|
-# """ runs external storage routine """
|
|
|
-# return cls.respond()
|
|
|
-
|
|
|
-# @require_POST
|
|
|
-# @classmethod
|
|
|
-# def run_label_provider(cls, request, project_id: int):
|
|
|
-# """ runs label provider routine """
|
|
|
-# return cls.respond()
|
|
|
+ def get_queryset(self):
|
|
|
+ return self.request.user.projects
|
|
|
|
|
|
+ def perform_create(self, serializer):
|
|
|
+ serializer.save(user=self.request.user)
|