Ejemplo n.º 1
0
def project_page_detail(request, project_uuid, page_uuid):
    project = get_object_or_404(Project, pk=project_uuid)
    page = get_object_or_404(Page, pk=page_uuid)
    check_if_member_of_project(request.user.id, project.uuid)

    if page.project != project:
        return JsonResponse({}, status=status.HTTP_400_BAD_REQUEST)

    if request.method == "GET":
        serializer = PageSerializer(page)
        return JsonResponse(serializer.data)

    elif request.method == "PUT":
        check_if_admin_of_project(request.user.id, project.uuid)
        data = JSONParser().parse(request)
        serializer = PageSerializer(page, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data)
        return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == "DELETE":
        check_if_admin_of_project(request.user.id, project.uuid)
        page.delete()
        return JsonResponse({}, status=status.HTTP_204_NO_CONTENT)
Ejemplo n.º 2
0
def project_page_list(request, project_uuid):
    project = Project.objects.get(uuid=project_uuid)
    check_if_member_of_project(request.user.id, project.uuid)

    if request.method == "GET":
        pages = project.pages.all()
        serializer = PageSerializer(pages, many=True)
        return JsonResponse(serializer.data, safe=False)
    elif request.method == "POST":
        check_if_admin_of_project(request.user.id, project.uuid)
        data = JSONParser().parse(request)
        serializer = PageSerializer(data=data)
        if serializer.is_valid():
            page = Page.objects.create(project=project, **serializer.validated_data)
            page.save()
            return JsonResponse(
                {"uuid": page.uuid, **serializer.data}, status=status.HTTP_201_CREATED
            )
        return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 3
0
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data)
        return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == "DELETE":
        check_if_admin_of_project(request.user.id, project.uuid)
        project.delete()
        return JsonResponse({}, status=status.HTTP_204_NO_CONTENT)


@swagger_auto_schema(
    methods=["get"],
    responses={
        200: openapi.Response(
            "Returns a list of all pages in the project", PageSerializer(many=True)
        )
    },
    tags=["Pages"],
)
@swagger_auto_schema(
    methods=["post"],
    request_body=PageSerializer,
    responses={201: openapi.Response("Returns the created page", PageSerializer)},
    tags=["Pages"],
)
@api_view(["GET", "POST"])
@permission_classes([permissions.IsAuthenticated])
def project_page_list(request, project_uuid):
    project = Project.objects.get(uuid=project_uuid)
    check_if_member_of_project(request.user.id, project.uuid)
Ejemplo n.º 4
0
            return JsonResponse(serializer.data)
        return JsonResponse(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

    elif request.method == "DELETE":
        check_if_admin_of_project(request.user.id, project.uuid)
        project.delete()
        return JsonResponse({}, status=status.HTTP_204_NO_CONTENT)


@swagger_auto_schema(
    methods=["get"],
    responses={
        200:
        openapi.Response("Returns a list of all pages in the project",
                         PageSerializer(many=True))
    },
    tags=["Pages"],
)
@swagger_auto_schema(
    methods=["post"],
    request_body=PageSerializer,
    responses={
        201: openapi.Response("Returns the created page", PageSerializer)
    },
    tags=["Pages"],
)
@api_view(["GET", "POST"])
@permission_classes([permissions.IsAuthenticated])
def project_page_list(request, project_uuid):
    project = Project.objects.get(uuid=project_uuid)