develop #8

Merged
s460930 merged 7 commits from develop into master 2020-12-17 17:03:01 +01:00
5 changed files with 8 additions and 21 deletions
Showing only changes of commit c3a50e0552 - Show all commits

Binary file not shown.

View File

@ -2,10 +2,10 @@
@author: p.dolata
"""
from django.conf.urls import url
from rest_framework.routers import SimpleRouter
from smartpicasso.app.project.views import ProjectsView
urlpatterns = [
url(r'^projects', ProjectsView.as_view(), name='projects')
]
router = SimpleRouter(trailing_slash=False)
router.register('projects', ProjectsView, basename="projects")
urlpatterns = router.urls

View File

@ -2,31 +2,18 @@
@author p.dolata
"""
from rest_framework import status
from rest_framework.generics import CreateAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from smartpicasso.app.project.serializers import ProjectSerializer
class ProjectsView(CreateAPIView):
class ProjectsView(ModelViewSet):
"""
View for project endpoints
"""
permission_classes = (IsAuthenticated,)
serializer_class = ProjectSerializer
def post(self, request):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
project = serializer.save(user=request.user)
status_code = status.HTTP_201_CREATED
response = {
'success': 'True',
'status_code': status_code,
'data': {
'id': project.id
}
}
return Response(response, status=status_code)
def perform_create(self, serializer):
serializer.save(user=self.request.user)