Пример #1
0
def app_detail(request, pk):
    try:
        try:
            pk = int(pk)
            app = App.objects.get(pk=pk)
        except:
            app = App.objects.filter(name=pk).first()
    except Group.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = AppSerializer(app)
        return JsonResponse(serializer.data)

    if request.method == 'DELETE':
        app.enable = 0
        app.save()
        return JsonResponse(serializer.data)

    if request.method == 'PUT':
        if not app:
            res = {"code": 405, "message": "Not found this app"}
            return Response(data=res,
                            status=405)
    ip = get_ip(request, right_most_proxy=True)
    if ip is not None:
        host = Host.objects.filter(ip=ip).first()
        if host is None:
            host = Host.create(ip)
            host.save()
    status = request.data.get("status")
    statistics = request.data.get('statistics')
    app.message = request.data.get("message", app.message)
    if status is None:
        res = {"code": 400,
               "message": "wong"}
        return Response(data=res,  status=400)
    app.status = status
    app.last_update = datetime.now()
    app.host_id = host.id
    app.save()
    if statistics:
        try:
            json.loads(statistics)
        except:
            res = {"code": 400, "message": "Statistics format must json"}
            return Response(data=res,
                            status=400)
        appStatistics = AppStatistics.create(statistics, app.id)
        appStatistics.save()
    return JsonResponse(object_to_json(app))
Пример #2
0
def host_detail(request, pk):
    """
    Retrieve, update or delete a code host.
    """
    try:
        host = Host.objects.get(pk=pk)
    except Group.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = host_serializer(host)
        return JsonResponse(serializer.data)

    elif request.method == 'PUT':
        host.name = request.data.get("name", host.name)
        host.description = request.data.get("description", host.description)
        host.save()
        return JsonResponse(object_to_json(host))
Пример #3
0
def host_detail(request, pk):
    """
    Retrieve, update or delete a code host.
    """
    try:
        host = Host.objects.get(pk=pk)
    except Group.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = host_serializer(host)
        return JsonResponse(serializer.data)

    elif request.method == 'PUT':
        host.name = request.data.get("name", host.name)
        host.description = request.data.get("description", host.description)
        host.save()
        return JsonResponse(object_to_json(host))
Пример #4
0
def group_detail(request, pk):
    """
    Get, udpate, or delete a specific task
    """
    try:
        group = Group.objects.get(pk=pk)
    except Group.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = GroupSerializer(group)
        return JsonResponse(serializer.data)

    elif request.method == 'PUT':
        group.unique_name = request.data.get("unique_name", group.unique_name)
        group.display_name = request.data.get("display_name",
                                              group.display_name)
        group.save()
        return JsonResponse(object_to_json(group))
Пример #5
0
def group_detail(request, pk):
    """
    Get, udpate, or delete a specific task
    """
    try:
        group = Group.objects.get(pk=pk)
    except Group.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = GroupSerializer(group)
        return JsonResponse(serializer.data)

    elif request.method == 'PUT':
        group.unique_name = request.data.get("unique_name", group.unique_name)
        group.display_name = request.data.get("display_name",
                                              group.display_name)
        group.save()
        return JsonResponse(object_to_json(group))