• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.check_body函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中uwsgi_it_api.utils.check_body函数的典型用法代码示例。如果您正苦于以下问题:Python check_body函数的具体用法?Python check_body怎么用?Python check_body使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了check_body函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: domains

def domains(request):
    customer = request.user.customer

    if request.method == 'POST':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        if Domain.objects.filter(name=j['name']):
            response = HttpResponse(json.dumps({'error': 'Conflict'}),
                                    content_type="application/json")
            response.status_code = 409
            return response
        if dns_check(j['name'], customer.uuid):
            try:
                customer.domain_set.create(name=j['name'])
                response = HttpResponse(json.dumps({'message': 'Created'}),
                                        content_type="application/json")
                response.status_code = 201
            except:
                response = HttpResponse(json.dumps({'error': 'Conflict'}),
                                        content_type="application/json")
                response.status_code = 409
            return response
        else:
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}),
                                         content_type="application/json")

    elif request.method == 'DELETE':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        try:
            customer.domain_set.get(name=j['name']).delete()
        except Domain.DoesNotExist:
            return HttpResponseNotFound(json.dumps({'error': 'Not found'}),
                                        content_type="application/json")
        return HttpResponse(json.dumps({'message': 'Ok'}),
                            content_type="application/json")

    elif request.method == 'GET':
        if 'tags' in request.GET:
            j = [{'id': d.pk, 'name': d.name, 'uuid': d.uuid,
                  'tags': [t.name for t in d.tags.all()]} for d in
                 customer.domain_set.filter(
                     tags__name__in=request.GET['tags'].split(','))]
        else:
            j = [{'id': d.pk, 'name': d.name, 'uuid': d.uuid,
                  'tags': [t.name for t in d.tags.all()]} for d in
                 customer.domain_set.all()]
        return spit_json(request, j)

    response = HttpResponse(json.dumps({'error': 'Method not allowed'}),
                            content_type="application/json")
    response.status_code = 405
    return response
开发者ID:pauloxnet,项目名称:uwsgi.it,代码行数:57,代码来源:views.py


示例2: portmappings

def portmappings(request, ip):
    customer = request.user.customer
    try:
        server = Server.objects.get(address=ip, owner=customer)
    except:
        return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
    if request.method == "POST":
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        if not j:
            return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
        pm = Portmap()
        try:
            pm.proto = j["proto"]
            pm.public_port = int(j["public_port"])
            pm.private_port = int(j["private_port"])
            pm.container = server.container_set.get(pk=(int(j["container"]) - UWSGI_IT_BASE_UID), customer=customer)
            pm.full_clean()
            pm.save()
        except:
            import sys

            print sys.exc_info()
            return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
        response = HttpResponse(json.dumps({"message": "Created"}), content_type="application/json")
        response.status_code = 201
        return response
    elif request.method == "DELETE":
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        if not j:
            return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
        try:
            pm = Portmap.objects.get(pk=j["id"], container__server=server)
            pm.delete()
        except:
            return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
        return HttpResponse(json.dumps({"message": "Ok"}), content_type="application/json")
    mappings = []
    for portmap in Portmap.objects.filter(container__server=server):
        mappings.append(
            {
                "id": portmap.pk,
                "proto": portmap.proto,
                "public_port": portmap.public_port,
                "container": portmap.container.uid,
                "container_ip": str(portmap.container.ip),
                "private_port": portmap.private_port,
            }
        )
    return spit_json(request, mappings)
开发者ID:unbit,项目名称:uwsgi.it,代码行数:55,代码来源:views.py


示例3: domains

def domains(request):
    customer = request.user.customer

    if request.method == "POST":
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        if Domain.objects.filter(name=j["name"]):
            response = HttpResponse(json.dumps({"error": "Conflict"}), content_type="application/json")
            response.status_code = 409
            return response
        if dns_check(j["name"], customer.uuid):
            try:
                customer.domain_set.create(name=j["name"])
                response = HttpResponse(json.dumps({"message": "Created"}), content_type="application/json")
                response.status_code = 201
            except:
                response = HttpResponse(json.dumps({"error": "Conflict"}), content_type="application/json")
                response.status_code = 409
            return response
        else:
            return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")

    elif request.method == "DELETE":
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        try:
            customer.domain_set.get(name=j["name"]).delete()
        except Domain.DoesNotExist:
            return HttpResponseNotFound(json.dumps({"error": "Not found"}), content_type="application/json")
        return HttpResponse(json.dumps({"message": "Ok"}), content_type="application/json")

    elif request.method == "GET":
        if "tags" in request.GET:
            j = [
                {"id": d.pk, "name": d.name, "uuid": d.uuid, "tags": [t.name for t in d.tags.all()]}
                for d in customer.domain_set.filter(tags__name__in=request.GET["tags"].split(","))
            ]
        else:
            j = [
                {"id": d.pk, "name": d.name, "uuid": d.uuid, "tags": [t.name for t in d.tags.all()]}
                for d in customer.domain_set.all()
            ]
        return spit_json(request, j)

    response = HttpResponse(json.dumps({"error": "Method not allowed"}), content_type="application/json")
    response.status_code = 405
    return response
开发者ID:unbit,项目名称:uwsgi.it,代码行数:51,代码来源:views.py


示例4: portmappings

def portmappings(request, ip):
    customer = request.user.customer
    try:
        server = Server.objects.get(address=ip,owner=customer)
    except:
        return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
    if request.method == 'POST':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        if not j:
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        pm = Portmap()
        try:
            pm.proto = j['proto']
            pm.public_port = int(j['public_port'])
            pm.private_port = int(j['private_port'])
            pm.container = server.container_set.get(pk=(int(j['container']) - UWSGI_IT_BASE_UID), customer=customer)
            pm.full_clean()
            pm.save()
        except:
            import sys
            print sys.exc_info()
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        response = HttpResponse(json.dumps({'message': 'Created'}), content_type="application/json")
        response.status_code = 201
        return response
    elif request.method == 'DELETE':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        if not j:
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        try:
            pm = Portmap.objects.get(pk=j['id'], container__server=server)
            pm.delete()
        except:
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        return HttpResponse(json.dumps({'message': 'Ok'}), content_type="application/json")
    mappings = []
    for portmap in Portmap.objects.filter(container__server=server):
        mappings.append({'id': portmap.pk,
                         'proto': portmap.proto,
                         'public_port': portmap.public_port,
                         'container': portmap.container.uid,
                         'container_ip': str(portmap.container.ip),
                         'private_port': portmap.private_port,
                       })
    return spit_json(request, mappings)
开发者ID:Mikrobit,项目名称:uwsgi.it,代码行数:51,代码来源:views.py


示例5: custom_distro

def custom_distro(request, id):
    customer = request.user.customer
    try:
        distro = CustomDistro.objects.get(pk=id, container__customer=customer)
    except:
        return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}),
                                     content_type="application/json")
    if request.method == 'DELETE':
        distro.delete()
        return HttpResponse(json.dumps({'message': 'Ok'}),
                            content_type="application/json")
    if request.method == 'POST':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        allowd_fields = ('name', 'path', 'note')
        for field in allowed_fields:
            if field in j:
                setattr(distro, field, j[field])
        distro.full_clean()
        distro.save()
    d = {
        'id': distro.pk,
        'container': distro.container.uid,
        'name': distro.name,
        'path': distro.path,
        'note': distro.note,
        'uuid': distro.uuid,
    }
    return spit_json(request, d)
开发者ID:pauloxnet,项目名称:uwsgi.it,代码行数:31,代码来源:views.py


示例6: tag

def tag(request, id):
    customer = request.user.customer
    try:
        t = Tag.objects.get(customer=customer, pk=id)
    except:
        return HttpResponseNotFound(json.dumps({'error': 'Not found'}), content_type="application/json")

    allowed_keys = ('name', 'note')
    if request.method == 'POST':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        for key in allowed_keys:
            if key in j:
                setattr(t, key, j[key])
        try:
            t.save()
            j = {'id': t.pk, 'name': t.name, 'note': t.note}
            return spit_json(request, j)
        except:
            response = HttpResponse(json.dumps({'error': 'Conflict'}), content_type="application/json")
            response.status_code = 409
        return response
    elif request.method == 'GET':
        j = {'id': t.pk, 'name': t.name, 'note': t.note}
        return spit_json(request, j)
    elif request.method == 'DELETE':
        t.delete()
        return HttpResponse(json.dumps({'message': 'Ok'}), content_type="application/json")
    allowed_keys = ('name', 'note')
    response = HttpResponse(json.dumps({'error': 'Method not allowed'}), content_type="application/json")
    response.status_code = 405
    return response
开发者ID:taifu,项目名称:uwsgi.it,代码行数:34,代码来源:views.py


示例7: me

def me(request):
    customer = request.user.customer
    if request.method == "POST":
        response = check_body(request)
        if response:
            return response
        allowed_keys = ("vat", "company")
        j = json.loads(request.read())
        for key in j:
            if key in allowed_keys:
                setattr(customer, key, j[key])
        if "password" in j:
            customer.user.set_password(j["password"])
            customer.user.save()
        if "email" in j:
            customer.user.email = j["email"]
            customer.user.save()
        customer.save()
    c = {
        "email": customer.user.email,
        "vat": customer.vat,
        "company": customer.company,
        "uuid": customer.uuid,
        "containers": [cc.uid for cc in customer.container_set.all()],
        "servers": [s.address for s in customer.server_set.all()],
    }
    return spit_json(request, c)
开发者ID:unbit,项目名称:uwsgi.it,代码行数:27,代码来源:views.py


示例8: tags

def tags(request):
    customer = request.user.customer
    allowed_keys = ("name", "note")
    if request.method == "POST":
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        tag = Tag(customer=customer)
        for key in allowed_keys:
            if key in j:
                setattr(tag, key, j[key])
        try:
            tag.save()
            j = {"id": tag.pk, "name": tag.name, "note": tag.note}
            response = spit_json(request, j)
            response.status_code = 201
            response.reason_phrase = "Created"
        except:
            response = HttpResponse(json.dumps({"error": "Conflict"}), content_type="application/json")
            response.status_code = 409
        return response

    elif request.method == "GET":
        j = [{"id": t.pk, "name": t.name} for t in Tag.objects.filter(customer=customer)]
        return spit_json(request, j)
    response = HttpResponse(json.dumps({"error": "Method not allowed"}), content_type="application/json")
    response.status_code = 405
    return response
开发者ID:unbit,项目名称:uwsgi.it,代码行数:29,代码来源:views.py


示例9: custom_distro

def custom_distro(request, id):
    customer = request.user.customer
    try:
        distro = CustomDistro.objects.get(pk=id, container__customer=customer)
    except:
        return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
    if request.method == "DELETE":
        distro.delete()
        return HttpResponse(json.dumps({"message": "Ok"}), content_type="application/json")
    if request.method == "POST":
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        allowd_fields = ("name", "path", "note")
        for field in allowed_fields:
            if field in j:
                setattr(distro, field, j[field])
        distro.full_clean()
        distro.save()
    d = {
        "id": distro.pk,
        "container": distro.container.uid,
        "name": distro.name,
        "path": distro.path,
        "note": distro.note,
        "uuid": distro.uuid,
    }
    return spit_json(request, d)
开发者ID:unbit,项目名称:uwsgi.it,代码行数:29,代码来源:views.py


示例10: custom_distros

def custom_distros(request, id=None):
    customer = request.user.customer
    if not id:
        j = [{'id': d.pk, 'name': d.name, 'container': d.container.uid} for d in CustomDistro.objects.filter(container__customer=customer)]
        return spit_json(request, j)
    try:
        container = customer.container_set.get(pk=(int(id) - UWSGI_IT_BASE_UID))
    except:
        return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
    if request.method == 'POST':
        if not container.custom_distros_storage:
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        distro = CustomDistro(container=container) 
        allowed_fields = ('name', 'path', 'note')
        for field in allowed_fields:
            if field in j:
                setattr(distro, field, j[field])
        try:
            distro.full_clean()
            distro.save()
        except:
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        response = HttpResponse(json.dumps({'message': 'Created'}), content_type="application/json")
        response.status_code = 201
        return response
    j = [{'id': d.pk, 'name': d.name} for d in CustomDistro.objects.filter(container__server=container.server,container__customer=customer).exclude(container=container)]
    return spit_json(request, j)
开发者ID:Mikrobit,项目名称:uwsgi.it,代码行数:31,代码来源:views.py


示例11: loopbox

def loopbox(request, id):
    customer = request.user.customer
    try:
        loopbox = Loopbox.objects.get(pk=id, container__in=customer.container_set.all())
    except:
        return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
    if request.method == 'POST':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        if not j:
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        if 'tags' in j:
            new_tags = []
            for tag in j['tags']:
                try:
                    new_tags.append(Tag.objects.get(customer=customer, name=tag))
                except:
                    pass
            loopbox.tags = new_tags
        loopbox.save()
    elif request.method == 'DELETE':
        loopbox.delete()
        return HttpResponse(json.dumps({'message': 'Ok'}), content_type="application/json")
    l = {
        'id': loopbox.pk,
        'container': loopbox.container.uid,
        'filename': loopbox.filename,
        'mountpoint': loopbox.mountpoint,
        'ro': loopbox.ro,
        'tags': [t.name for t in loopbox.tags.all()]
    }
    return spit_json(request, l)
开发者ID:taifu,项目名称:uwsgi.it,代码行数:34,代码来源:views.py


示例12: loopbox

def loopbox(request, id):
    customer = request.user.customer
    try:
        loopbox = Loopbox.objects.get(pk=id, container__in=customer.container_set.all())
    except:
        return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
    if request.method == "POST":
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        if not j:
            return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
        if "tags" in j:
            new_tags = []
            for tag in j["tags"]:
                try:
                    new_tags.append(Tag.objects.get(customer=customer, name=tag))
                except:
                    pass
            loopbox.tags = new_tags
        loopbox.save()
    elif request.method == "DELETE":
        loopbox.delete()
        return HttpResponse(json.dumps({"message": "Ok"}), content_type="application/json")
    l = {
        "id": loopbox.pk,
        "container": loopbox.container.uid,
        "filename": loopbox.filename,
        "mountpoint": loopbox.mountpoint,
        "ro": loopbox.ro,
        "tags": [t.name for t in loopbox.tags.all()],
    }
    return spit_json(request, l)
开发者ID:unbit,项目名称:uwsgi.it,代码行数:34,代码来源:views.py


示例13: containers

def containers(request):
    if request.method == 'POST':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        needed_keys = ('server', 'name', 'memory', 'storage')
        for k in needed_keys:
            if not k in j.keys():
                return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        try:
            server = Server.objects.get(address=j['server'])
            if server.owner != request.user.customer:
                return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        except:
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        try:
            container = Container(customer=request.user.customer, server=server)
            container.name = j['name']
            container.memory = int(j['memory'])
            container.storage = int(j['storage'])
            container.save()
            response = HttpResponse(json.dumps({'message': 'Created'}), content_type="application/json")
            response.status_code = 201
            return response
        except:
            response = HttpResponse(json.dumps({'error': 'Conflict'}), content_type="application/json")
            response.status_code = 409
            return response
    elif (request.method == 'GET' and
         'tags' in request.GET):
            containers = request.user.customer.container_set.filter(tags__name__in=request.GET['tags'].split(','))
    else:
        containers = request.user.customer.container_set.all()

    c = []
    for container in containers:
        cc = {
            'uid': container.uid,
            'name': container.name,
            'hostname': container.hostname,
            'ip': str(container.ip),
            'memory': container.memory,
            'storage': container.storage,
            'uuid': container.uuid,
            'distro': None,
            'distro_name': None,
            'server': container.server.name,
            'server_address': container.server.address,
            'tags': [t.name for t in container.tags.all()]
        }
        if container.distro:
            cc['distro'] = container.distro.pk
            cc['distro_name'] = container.distro.name
        c.append(cc)

    return spit_json(request, c)
开发者ID:taifu,项目名称:uwsgi.it,代码行数:57,代码来源:views.py


示例14: loopboxes

def loopboxes(request):
    if request.method == "POST":
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        needed_keys = ("container", "filename", "mountpoint")
        for k in needed_keys:
            if not k in j.keys():
                return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
        try:
            container = request.user.customer.container_set.get(pk=(int(j["container"]) - UWSGI_IT_BASE_UID))
        except:
            return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
        try:
            loopbox = Loopbox(container=container)
            loopbox.filename = j["filename"]
            loopbox.mountpoint = j["mountpoint"]
            if "ro" in j:
                loopbox.ro = j["ro"]
            loopbox.save()
            response = HttpResponse(json.dumps({"message": "Created"}), content_type="application/json")
            response.status_code = 201
            return response
        except:
            response = HttpResponse(json.dumps({"error": "Conflict"}), content_type="application/json")
            response.status_code = 409
            return response
    elif request.method == "GET":
        query = {}
        if "tags" in request.GET:
            query["tags__name__in"] = request.GET["tags"].split(",")
        if "container" in request.GET:
            try:
                query["container"] = request.user.customer.container_set.get(
                    pk=(int(request.GET["container"]) - UWSGI_IT_BASE_UID)
                )
            except:
                return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
        else:
            query["container__in"] = request.user.customer.container_set.all()
        loopboxes = Loopbox.objects.filter(**query)
    else:
        loopboxes = Loopbox.objects.filter(container__in=request.user.customer.container_set.all())

    l = []
    for loopbox in loopboxes:
        ll = {
            "id": loopbox.pk,
            "container": loopbox.container.uid,
            "filename": loopbox.filename,
            "mountpoint": loopbox.mountpoint,
            "ro": loopbox.ro,
            "tags": [t.name for t in loopbox.tags.all()],
        }
        l.append(ll)
    return spit_json(request, l)
开发者ID:unbit,项目名称:uwsgi.it,代码行数:57,代码来源:views.py


示例15: loopboxes

def loopboxes(request):
    if request.method == 'POST':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        needed_keys = ('container', 'filename', 'mountpoint')
        for k in needed_keys:
            if not k in j.keys():
                return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        try:
            container = request.user.customer.container_set.get(pk=(int(j['container']) - UWSGI_IT_BASE_UID))
        except:
            return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        try:
            loopbox = Loopbox(container=container)
            loopbox.filename = j['filename']
            loopbox.mountpoint = j['mountpoint']
            if 'ro' in j:
                loopbox.ro = j['ro']
            loopbox.save()
            response = HttpResponse(json.dumps({'message': 'Created'}), content_type="application/json")
            response.status_code = 201
            return response
        except:
            response = HttpResponse(json.dumps({'error': 'Conflict'}), content_type="application/json")
            response.status_code = 409
            return response
    elif request.method == 'GET':
        query = {}
        if 'tags' in request.GET:
            query['tags__name__in'] = request.GET['tags'].split(',')
        if 'container' in request.GET:
            try:
                query['container'] = request.user.customer.container_set.get(pk=(int(request.GET['container']) - UWSGI_IT_BASE_UID))
            except:
                return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}), content_type="application/json")
        else:
            query['container__in'] = request.user.customer.container_set.all()
        loopboxes = Loopbox.objects.filter(**query)
    else:
        loopboxes = Loopbox.objects.filter(container__in=request.user.customer.container_set.all())

    l = []
    for loopbox in loopboxes:
        ll = {
            'id': loopbox.pk,
            'container': loopbox.container.uid,
            'filename': loopbox.filename,
            'mountpoint': loopbox.mountpoint,
            'ro': loopbox.ro,
            'tags': [t.name for t in loopbox.tags.all()]
        }
        l.append(ll)
    return spit_json(request, l)
开发者ID:taifu,项目名称:uwsgi.it,代码行数:55,代码来源:views.py


示例16: domain

def domain(request, id):
    customer = request.user.customer
    try:
        domain = customer.domain_set.get(pk=id)
    except:
        return HttpResponseNotFound(json.dumps({"error": "Not found"}), content_type="application/json")
    allowed_keys = ("note",)
    if request.method == "POST":
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        for key in allowed_keys:
            if key in j:
                setattr(domain, key, j[key])
        if "tags" in j:
            new_tags = []
            for tag in j["tags"]:
                try:
                    new_tags.append(Tag.objects.get(customer=customer, name=tag))
                except:
                    pass
            domain.tags = new_tags
        try:
            domain.save()
            j = {
                "id": domain.pk,
                "name": domain.name,
                "uuid": domain.uuid,
                "tags": [t.name for t in domain.tags.all()],
                "note": domain.note,
            }
            return spit_json(request, j)
        except:
            response = HttpResponse(json.dumps({"error": "Conflict"}), content_type="application/json")
            response.status_code = 409
        return response
    elif request.method == "DELETE":
        domain.delete()
        return HttpResponse(json.dumps({"message": "Ok"}), content_type="application/json")

    elif request.method == "GET":
        j = {
            "id": domain.pk,
            "name": domain.name,
            "uuid": domain.uuid,
            "tags": [t.name for t in domain.tags.all()],
            "note": domain.note,
        }
        return spit_json(request, j)

    response = HttpResponse(json.dumps({"error": "Method not allowed"}), content_type="application/json")
    response.status_code = 405
    return response
开发者ID:unbit,项目名称:uwsgi.it,代码行数:54,代码来源:views.py


示例17: raise_alarm

def raise_alarm(request, id):
    customer = request.user.customer
    try:
        container = customer.container_set.get(
            pk=(int(id) - UWSGI_IT_BASE_UID))
    except:
        return HttpResponseForbidden(json.dumps({'error': 'Forbidden'}),
                                     content_type="application/json")
    if request.method == 'POST':
        response = check_body(request)
        if response:
            return response
        alarm = Alarm(container=container, level=1)
        if 'color' in request.GET:
            color = request.GET['color']
            if not color.startswith('#'):
                color = '#' + color
            alarm.color = color
        alarm._class = request.GET.get('class', None)
        alarm.vassal = request.GET.get('vassal', None)
        alarm.line = request.GET.get('line', None)
        alarm.func = request.GET.get('func', None)
        alarm.filename = request.GET.get('filename', None)
        # user alarm by default
        alarm.level = 1
        if 'level' in request.GET:
            alarm.level = int(request.GET['level'])
            if alarm.level < 1:
                return HttpResponseForbidden(
                    json.dumps({'error': 'Forbidden'}),
                    content_type="application/json")
        if 'unix' in request.GET:
            alarm.unix = datetime.datetime.fromtimestamp(
                int(request.GET['unix']))
        else:
            alarm.unix = datetime.datetime.now()
        alarm.msg = request.read()
        try:
            alarm.save()
            response = HttpResponse(json.dumps({'message': 'Created'}),
                                    content_type="application/json")
            response.status_code = 201
            return response
        except:
            response = HttpResponse(json.dumps({'error': 'Conflict'}),
                                    content_type="application/json")
            response.status_code = 409
            return response
    response = HttpResponse(json.dumps({'error': 'Method not allowed'}),
                            content_type="application/json")
    response.status_code = 405
    return response
开发者ID:pauloxnet,项目名称:uwsgi.it,代码行数:52,代码来源:views.py


示例18: domain

def domain(request, id):
    customer = request.user.customer
    try:
        domain = customer.domain_set.get(pk=id)
    except:
        return HttpResponseNotFound(json.dumps({'error': 'Not found'}),
                                    content_type="application/json")
    allowed_keys = ('note',)
    if request.method == 'POST':
        response = check_body(request)
        if response:
            return response
        j = json.loads(request.read())
        for key in allowed_keys:
            if key in j:
                setattr(domain, key, j[key])
        if 'tags' in j:
            new_tags = []
            for tag in j['tags']:
                try:
                    new_tags.append(
                        Tag.objects.get(customer=customer, name=tag))
                except:
                    pass
            domain.tags = new_tags
        try:
            domain.save()
            j = {'id': domain.pk, 'name': domain.name, 'uuid': domain.uuid,
                 'tags': [t.name for t in domain.tags.all()],
                 'note': domain.note}
            return spit_json(request, j)
        except:
            response = HttpResponse(json.dumps({'error': 'Conflict'}),
                                    content_type="application/json")
            response.status_code = 409
        return response
    elif request.method == 'DELETE':
        domain.delete()
        return HttpResponse(json.dumps({'message': 'Ok'}),
                            content_type="application/json")

    elif request.method == 'GET':
        j = {'id': domain.pk, 'name': domain.name, 'uuid': domain.uuid,
             'tags': [t.name for t in domain.tags.all()],
             'note': domain.note}
        return spit_json(request, j)

    response = HttpResponse(json.dumps({'error': 'Method not allowed'}),
                            content_type="application/json")
    response.status_code = 405
    return response
开发者ID:pauloxnet,项目名称:uwsgi.it,代码行数:51,代码来源:views.py


示例19: raise_alarm

def raise_alarm(request, id):
    customer = request.user.customer
    try:
        container = customer.container_set.get(pk=(int(id) - UWSGI_IT_BASE_UID))
    except:
        return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
    if request.method == "POST":
        response = check_body(request)
        if response:
            return response
        alarm = Alarm(container=container, level=1)
        if "color" in request.GET:
            color = request.GET["color"]
            if not color.startswith("#"):
                color = "#" + color
            alarm.color = color
        alarm._class = request.GET.get("class", None)
        alarm.vassal = request.GET.get("vassal", None)
        alarm.line = request.GET.get("line", None)
        alarm.func = request.GET.get("func", None)
        alarm.filename = request.GET.get("filename", None)
        # user alarm by default
        alarm.level = 1
        if "level" in request.GET:
            alarm.level = int(request.GET["level"])
            if alarm.level < 1:
                return HttpResponseForbidden(json.dumps({"error": "Forbidden"}), content_type="application/json")
        if "unix" in request.GET:
            alarm.unix = datetime.datetime.fromtimestamp(int(request.GET["unix"]))
        else:
            alarm.unix = datetime.datetime.now()
        alarm.msg = request.read()
        try:
            alarm.save()
            response = HttpResponse(json.dumps({"message": "Created"}), content_type="application/json")
            response.status_code = 201
            return response
        except:
            response = HttpResponse(json.dumps({"error": "Conflict"}), content_type="application/json")
            response.status_code = 409
            return response
    response = HttpResponse(json.dumps({"error": "Method not allowed"}), content_type="application/json")
    response.status_code = 405
    return response
开发者ID:unbit,项目名称:uwsgi.it,代码行数:44,代码来源:views.py


示例20: private_server_file_metadata

def private_server_file_metada 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.spit_json函数代码示例发布时间:2022-05-26
下一篇:
Python uwsgi.worker_id函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap