From c3a50e0552df78b5b48d5d860b49625e22445a76 Mon Sep 17 00:00:00 2001 From: s460930 Date: Tue, 15 Dec 2020 16:28:25 +0100 Subject: [PATCH] SMART-48 change implementation of create project endpoint --- rest-app/db.sqlite3 | Bin 172032 -> 172032 bytes .../__pycache__/settings.cpython-38.pyc | Bin 3530 -> 3530 bytes .../__pycache__/urls.cpython-38.pyc | Bin 1110 -> 1110 bytes rest-app/smartpicasso/app/project/urls.py | 8 +++---- rest-app/smartpicasso/app/project/views.py | 21 ++++-------------- 5 files changed, 8 insertions(+), 21 deletions(-) diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index a535fbea4a5b141051a4e8b52e17271486c2c37c..2414073beab6a27f43deb3d987b75cfdf4fec5ac 100644 GIT binary patch delta 431 zcmZoTz}0YoYl1Xm@I)DB#^A<;)&$0_2~6ww1WgqTO|6WKtW3@Ij4h4Kjm)M$$Y)a6 zZqLtjG=PhlFOPx0ith_w-p0lRzO+VWW;S1WM@Qc@gH&VlG!xS#3rlm8RO4jJv=o!X z38axG$7{R0onjD Xp9Q299M-I0Q@~6{rtNq7nN$P-`z&*3 delta 91 zcmZoTz}0YoYl1Xmz(g5m#(>6z)&$0_2~6ww1WgnSEv<~qtxQey3@uFz49%uL$Y)a6 tZqLtjG=PnfzlwpsYGY#o|MaSSrmoE_3-0hwe^Ae)0%mQ0(9fhG000Zf9o7H< diff --git a/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc index d45f22ec0d2aabc9aaa15421e5c3329c353440c2..68dbbda0dc09c8e2598ab360a1610297c3dec1ae 100644 GIT binary patch delta 20 acmX>leM*`;l$V!_0SHPi-Pp*zpBDf+9tHIP delta 20 acmX>leM*`;l$V!_0SKbEUEj#PpBDf)!Uewo diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index 8ca7aebd49506e1b9f27b846acd1d15a3f08de6e..d832aea1c7fd30a3ac3b86954119100184199922 100644 GIT binary patch delta 20 acmcb{agBpJl$V!_0SHPi-Pp+O%>n>8Nd;;E delta 20 acmcb{agBpJl$V!_0SG?sxxSIxn*{(nD+SO1 diff --git a/rest-app/smartpicasso/app/project/urls.py b/rest-app/smartpicasso/app/project/urls.py index 72aa447..f966670 100644 --- a/rest-app/smartpicasso/app/project/urls.py +++ b/rest-app/smartpicasso/app/project/urls.py @@ -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 diff --git a/rest-app/smartpicasso/app/project/views.py b/rest-app/smartpicasso/app/project/views.py index a20dc68..df6ffb0 100644 --- a/rest-app/smartpicasso/app/project/views.py +++ b/rest-app/smartpicasso/app/project/views.py @@ -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)