def taskDetail(request, task_id): try: task = Task.objects.get(id=int(task_id)) except Task.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) serializer = taskSerializer(task) return Response(serializer.data)
def taskList(request, status_filter=None): if status_filter and status_filter in TASK_STATUS.keys(): tasks = Task.objects.filter(status=TASK_STATUS[status_filter]) elif not status_filter: tasks = Task.objects.all() else: return Response(status=status.HTTP_404_NOT_FOUND) serializer = taskSerializer(tasks, many=True) return Response(serializer.data)
def updateTask(request, task_id): try: task = Task.objects.get(id=int(task_id)) except Task.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) serializer = taskSerializer(task, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def createTask(request, status_filter=None): created_time = datetime.datetime.now() request.data['time'] = created_time request.data['expiry'] = created_time request.data['status'] = 0 request.data['expiry_status'] = 0 serializer = taskSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def createTask(request, status_filter=None): serializer = taskSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)