|
@@ -1,61 +1,96 @@
|
|
|
from django.views.decorators.http import require_POST
|
|
|
-from pycs_api.views.base import JsonResponseView
|
|
|
+from rest_framework import status
|
|
|
from rest_framework.decorators import permission_classes
|
|
|
+from rest_framework.response import Response
|
|
|
|
|
|
+from pycs_api.models import Project
|
|
|
+from pycs_api.serializers import ProjectSerializer
|
|
|
+from pycs_api.views.base import BaseViewSet
|
|
|
|
|
|
-class ProjectView(JsonResponseView):
|
|
|
|
|
|
- """
|
|
|
- serves POST and GET for '/projects/'
|
|
|
+class ProjectViewSet(BaseViewSet):
|
|
|
|
|
|
- staticmethods serve POST methods for
|
|
|
- '/projects/<id>/name'
|
|
|
- '/projects/<id>/description'
|
|
|
- '/projects/<id>/remove'
|
|
|
- """
|
|
|
+ queryset = Project.objects.all().order_by("id")
|
|
|
+ serializer_class = ProjectSerializer
|
|
|
|
|
|
- http_method_names = ["get", "post"]
|
|
|
+ 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 get(self, request, *args, **kwargs):
|
|
|
- """ lists projects """
|
|
|
- return self.respond([
|
|
|
- dict(name="Project 1", description="Desc1", ),
|
|
|
- dict(name="Project 2", description="Desc2"),
|
|
|
- ])
|
|
|
+ def create(self, request):
|
|
|
+ if request.user.is_anonymous:
|
|
|
+ return Response('Unauthorized',
|
|
|
+ status=status.HTTP_401_UNAUTHORIZED)
|
|
|
|
|
|
- def post(self, request, *args, **kwargs):
|
|
|
- """ creates a project """
|
|
|
- return self.respond()
|
|
|
+ project = Project(
|
|
|
+ user=request.user,
|
|
|
+ **request.data
|
|
|
+ )
|
|
|
|
|
|
+ project.save()
|
|
|
+ serializer = self.get_serializer(project)
|
|
|
+ return Response(serializer.data)
|
|
|
|
|
|
- @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()
|
|
|
+# class ProjectView(JsonResponseView):
|
|
|
|
|
|
- @require_POST
|
|
|
- @classmethod
|
|
|
- def run_external_storage(cls, request, project_id: int):
|
|
|
- """ runs external storage routine """
|
|
|
- return cls.respond()
|
|
|
+# """
|
|
|
+# serves POST and GET for '/projects/'
|
|
|
|
|
|
- @require_POST
|
|
|
- @classmethod
|
|
|
- def run_label_provider(cls, request, project_id: int):
|
|
|
- """ runs label provider routine """
|
|
|
- return cls.respond()
|
|
|
+# 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()
|
|
|
|