Ejemplo n.º 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))
Ejemplo n.º 2
0
 def _init_app_appstatistics(self):
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 2, "id": 1}', 1).save()
     AppStatistics.create('{"count": 3, "id": 1}', 1).save()
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 2, "id": 1}', 1).save()
     AppStatistics.create('{"count": 3, "id": 1}', 1).save()
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 2, "id": 1}', 1).save()
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 3, "id": 1}', 1).save()
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 4, "id": 1}', 1).save()
     AppStatistics.create('{"count": 4, "id": 1}', 1).save()
     AppStatistics.create('{"count": 4, "id": 1}', 1).save()
Ejemplo n.º 3
0
 def _init_app_appstatistics(self):
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 2, "id": 1}', 1).save()
     AppStatistics.create('{"count": 3, "id": 1}', 1).save()
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 2, "id": 1}', 1).save()
     AppStatistics.create('{"count": 3, "id": 1}', 1).save()
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 2, "id": 1}', 1).save()
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 3, "id": 1}', 1).save()
     AppStatistics.create('{"count": 1, "id": 1}', 1).save()
     AppStatistics.create('{"count": 4, "id": 1}', 1).save()
     AppStatistics.create('{"count": 4, "id": 1}', 1).save()
     AppStatistics.create('{"count": 4, "id": 1}', 1).save()