当前位置: 首页>>代码示例>>Python>>正文


Python Check.to_dict方法代码示例

本文整理汇总了Python中hc.api.models.Check.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Check.to_dict方法的具体用法?Python Check.to_dict怎么用?Python Check.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hc.api.models.Check的用法示例。


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

示例1: checks

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import to_dict [as 别名]
def checks(request):
    if request.method == "GET":
        q = Check.objects.filter(user=request.user)
        doc = {"checks": [check.to_dict() for check in q]}
        return JsonResponse(doc)

    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()

        return JsonResponse(check.to_dict(), status=201)

    # If request is neither GET nor POST, return "405 Method not allowed"
    return HttpResponse(status=405)
开发者ID:Persistent13,项目名称:healthchecks,代码行数:28,代码来源:views.py

示例2: checks

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import to_dict [as 别名]
def checks(request):
    if request.method == "GET":
        q = Check.objects.filter(user=request.user)

        tags = set(request.GET.getlist("tag"))
        for tag in tags:
            # approximate filtering by tags
            q = q.filter(tags__contains=tag)

        checks = []
        for check in q:
            # precise, final filtering
            if not tags or check.matches_tag_set(tags):
                checks.append(check.to_dict())

        return JsonResponse({"checks": checks})

    elif request.method == "POST":
        created = False
        check = _lookup(request.user, request.json)
        if check is None:
            num_checks = Check.objects.filter(user=request.user).count()
            if num_checks >= request.user.profile.check_limit:
                return HttpResponseForbidden()

            check = Check(user=request.user)
            created = True

        _update(check, request.json)

        return JsonResponse(check.to_dict(), status=201 if created else 200)

    # If request is neither GET nor POST, return "405 Method not allowed"
    return HttpResponse(status=405)
开发者ID:cogzidel,项目名称:healthchecks,代码行数:36,代码来源:views.py

示例3: test_next_ping_with_cron_syntax

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import to_dict [as 别名]
    def test_next_ping_with_cron_syntax(self):
        dt = timezone.make_aware(datetime(2000, 1, 1), timezone=timezone.utc)

        # Expect ping every round hour
        check = Check()
        check.kind = "cron"
        check.schedule = "0 * * * *"
        check.status = "up"
        check.last_ping = dt

        d = check.to_dict()
        self.assertEqual(d["next_ping"], "2000-01-01T01:00:00+00:00")
开发者ID:cogzidel,项目名称:healthchecks,代码行数:14,代码来源:test_check_model.py

示例4: checks

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import to_dict [as 别名]
def checks(request):
    if request.method == "GET":
        q = Check.objects.filter(user=request.user)
        doc = {"checks": [check.to_dict() for check in q]}
        return JsonResponse(doc)

    elif request.method == "POST":
        name = str(request.json.get("name", ""))
        tags = str(request.json.get("tags", ""))

        timeout = DEFAULT_TIMEOUT
        if "timeout" in request.json:
            timeout = td(seconds=request.json["timeout"])

        grace = DEFAULT_GRACE
        if "grace" in request.json:
            grace = td(seconds=request.json["grace"])

        unique_fields = request.json.get("unique", [])
        if unique_fields:
            existing_checks = Check.objects.filter(user=request.user)
            if "name" in unique_fields:
                existing_checks = existing_checks.filter(name=name)
            if "tags" in unique_fields:
                existing_checks = existing_checks.filter(tags=tags)
            if "timeout" in unique_fields:
                existing_checks = existing_checks.filter(timeout=timeout)
            if "grace" in unique_fields:
                existing_checks = existing_checks.filter(grace=grace)

            if existing_checks.count() > 0:
                # There might be more than one matching check, return first
                first_match = existing_checks.first()
                return JsonResponse(first_match.to_dict(), status=200)

        check = Check(user=request.user, name=name, tags=tags,
                      timeout=timeout, grace=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()

        return JsonResponse(check.to_dict(), status=201)

    # If request is neither GET nor POST, return "405 Method not allowed"
    return HttpResponse(status=405)
开发者ID:haswalt,项目名称:healthchecks,代码行数:51,代码来源:views.py


注:本文中的hc.api.models.Check.to_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。