def collaborate_create_view(request): if request.method == 'POST': data = request.data data['author'] = request.user.pk serializer = CollaborateSerializer(data=data) data = {} if serializer.is_valid(): collaborate_detail = serializer.save() data['response'] = CREATE_SUCCESS data['userId'] = collaborate_detail.userId data['workDuring'] = collaborate_detail.workDuring data['otherWorkDuring'] = collaborate_detail.otherWorkDuring data['workWith'] = collaborate_detail.workWith data['communicateOver'] = collaborate_detail.communicateOver data['communicateWith'] = collaborate_detail.communicateWith data['workBy'] = collaborate_detail.workBy data['otherWorkBy'] = collaborate_detail.otherWorkBy data['workHours'] = collaborate_detail.workHours data['otherWorkHours'] = collaborate_detail.otherWorkHours data['projectDuration'] = collaborate_detail.projectDuration return Response(data=data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def collaborate_view(request): try: collaborate = CollaborateModel.objects.get( userId=request.query_params.get('userId')) except CollaborateModel.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = CollaborateSerializer(collaborate) return Response(serializer.data)
def collaborate_create_view(request): if request.method == 'POST': data = request.data data['author'] = request.user.pk serializer = CollaborateSerializer(data=data) data = {} if serializer.is_valid(): collaborate_detail = serializer.save() data['response'] = CREATE_SUCCESS data['userId'] = collaborate_detail.userId data['workDuring'] = collaborate_detail.workDuring data['otherWorkDuring'] = collaborate_detail.otherWorkDuring data['workWith'] = collaborate_detail.workWith data['communicateOver'] = collaborate_detail.communicateOver data['communicateWith'] = collaborate_detail.communicateWith data['workBy'] = collaborate_detail.workBy data['otherWorkBy'] = collaborate_detail.otherWorkBy data['workHours'] = collaborate_detail.workHours data['otherWorkHours'] = collaborate_detail.otherWorkHours data['projectDuration'] = collaborate_detail.projectDuration return Response(data=data) if serializer.errors['userId'][ 0] == 'collaborate model with this userId already exists.': updateData = CollaborateModel.objects.get( userId=int(request.data['userId'])) updateData.workDuring = request.data['workDuring'] updateData.otherWorkDuring = request.data['otherWorkDuring'] updateData.workWith = request.data['workWith'] updateData.communicateOver = request.data['communicateOver'] updateData.communicateWith = request.data['communicateWith'] updateData.workBy = request.data['workBy'] updateData.otherWorkBy = request.data['otherWorkBy'] updateData.workHours = request.data['workHours'] updateData.otherWorkHours = request.data['otherWorkHours'] updateData.projectDuration = request.data['projectDuration'] updateData.save() data['response'] = UPDATE_SUCCESS return Response(data=data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)