@csrf_exempt
@check_api_key
@validate_json(schemas.check)
def create_check(request):
    if request.method == "GET":
        code = 200
        response = {
            "checks": [{
                "name": check.name,
                "ping_url": check.url(),
                "tags": check.tags,
                "timeout": int(check.timeout.total_seconds()),
                "grace": int(check.grace.total_seconds()),
                # "channels": check.channels,
            } for check in Check.objects.filter(user=request.user)]
        }
    elif request.method == "POST":
        check = Check(user=request.user)
        check.name = str(request.json.get("name", ""))
        check.tags = str(request.json.get("tags", ""))
        if "timeout" in request.json:
            check.timeout = td(seconds=request.json["timeout"])
        if "grace" in request.json:
            check.grace = td(seconds=request.json["grace"])

        check.save()

        # This needs to be done after saving the check, because of
        # the M2M relation between checks and channels:
        if request.json.get("channels") == "*":
            check.assign_all_channels()

        code = 201
        response = {
            "ping_url": check.url()
        }
    else:
        return HttpResponse(status=405)

    return JsonResponse(response, status=code)
dataset/ETHPy150Open healthchecks/healthchecks/hc/api/views.py/create_check/original