Exemplo n.º 1
0
def todo_list(request):
    if request.method == 'GET':
        task_list = Task_List.objects.all()
        serializer = TaskListSerializer(task_list, many=True)
        return JsonResponse(serializer.data, safe=False)
    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = TaskListSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse(serializer.errors, status=400)
Exemplo n.º 2
0
def task_list(request):
    """
    List all code snippets, or create a new snippet.
    """
    if request.method == 'GET':
        task_lists = Task_List.objects.all()
        serializer = TaskListSerializer(task_lists, many=True)
        return JsonResponse(serializer.data, safe=False)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = TaskListSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse(serializer.errors, status=400)
Exemplo n.º 3
0
 def tasks(self, request, pk):
     if request.method == 'GET':
         instance = self.get_object()
         tasks = Task.objects.filter(block=instance)
         serializer = TaskListSerializer(tasks, many=True)
         return Response(serializer.data)
     if request.method == 'POST':
         instance = self.get_object()
         serializer = TaskCreateSerializer(data=request.data)
         if serializer.is_valid():
             serializer.save(block=instance, creator=request.user)
             return Response(serializer.data)
         return Response(serializer.errors)
Exemplo n.º 4
0
 def tasks(self, request, pk):
     if request.method == 'GET':
         instance = self.get_object()
         tasks = Task.objects.filter(block=instance)
         serializer = TaskListSerializer(tasks, many=True)
         return Response(serializer.data)
     if request.method == 'POST':
         instance = self.get_object()
         serializer = TaskCreateSerializer(data=request.data)
         if serializer.is_valid():
             serializer.save(block=instance, creator=request.user)
             logger.info(
                 f"{request.user} updated task {serializer.data.get('id')}")
             return Response(serializer.data)
         logger.error(
             f"{request.user} task creation failed {serializer.errors}")
         return Response(serializer.errors)
Exemplo n.º 5
0
def todo_list_detail(request, pk):
    try:
        task_list = Task_List.objects.get(pk=pk)
    except Task_List.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = TaskListSerializer(task_list)
        return JsonResponse(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = TaskListSerializer(task_list, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data)
        return JsonResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        task_list.delete()
        return HttpResponse(status=204)
Exemplo n.º 6
0
 def get(self, request, pk):
     block = get_object_or_404(Block, id=pk)
     tasks = Task.objects.filter(block=block)
     serializer = TaskListSerializer(tasks, many=True)
     return Response(serializer.data)