develop #8
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,10 +2,10 @@
|
|||||||
@author: p.dolata
|
@author: p.dolata
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.conf.urls import url
|
from rest_framework.routers import SimpleRouter
|
||||||
|
|
||||||
from smartpicasso.app.project.views import ProjectsView
|
from smartpicasso.app.project.views import ProjectsView
|
||||||
|
|
||||||
urlpatterns = [
|
router = SimpleRouter(trailing_slash=False)
|
||||||
url(r'^projects', ProjectsView.as_view(), name='projects')
|
router.register('projects', ProjectsView, basename="projects")
|
||||||
]
|
urlpatterns = router.urls
|
||||||
|
@ -2,31 +2,18 @@
|
|||||||
@author p.dolata
|
@author p.dolata
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework.generics import CreateAPIView
|
|
||||||
from rest_framework.permissions import IsAuthenticated
|
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
|
from smartpicasso.app.project.serializers import ProjectSerializer
|
||||||
|
|
||||||
|
|
||||||
class ProjectsView(CreateAPIView):
|
class ProjectsView(ModelViewSet):
|
||||||
"""
|
"""
|
||||||
View for project endpoints
|
View for project endpoints
|
||||||
"""
|
"""
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
serializer_class = ProjectSerializer
|
serializer_class = ProjectSerializer
|
||||||
|
|
||||||
def post(self, request):
|
def perform_create(self, serializer):
|
||||||
serializer = self.serializer_class(data=request.data)
|
serializer.save(user=self.request.user)
|
||||||
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)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user