本文整理汇总了Python中hc.api.models.Channel.kind方法的典型用法代码示例。如果您正苦于以下问题:Python Channel.kind方法的具体用法?Python Channel.kind怎么用?Python Channel.kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hc.api.models.Channel
的用法示例。
在下文中一共展示了Channel.kind方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_slack_btn
# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import kind [as 别名]
def add_slack_btn(request):
code = request.GET.get("code", "")
if len(code) < 8:
return HttpResponseBadRequest()
result = requests.post("https://slack.com/api/oauth.access", {
"client_id": settings.SLACK_CLIENT_ID,
"client_secret": settings.SLACK_CLIENT_SECRET,
"code": code
})
doc = result.json()
if doc.get("ok"):
channel = Channel()
channel.user = request.team.user
channel.kind = "slack"
channel.value = result.text
channel.save()
channel.assign_all_checks()
messages.success(request, "The Slack integration has been added!")
else:
s = doc.get("error")
messages.warning(request, "Error message from slack: %s" % s)
return redirect("hc-channels")
示例2: _make_user
# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import kind [as 别名]
def _make_user(email):
username = str(uuid.uuid4())[:30]
user = User(username=username, email=email)
user.save()
channel = Channel()
channel.user = user
channel.kind = "email"
channel.value = email
channel.email_verified = True
channel.save()
return user
示例3: handle
# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import kind [as 别名]
def handle(self, *args, **options):
for user in User.objects.all():
q = Channel.objects.filter(user=user)
q = q.filter(kind="email", email_verified=True, value=user.email)
if q.count() > 0:
continue
print("Creating default channel for %s" % user.email)
channel = Channel(user=user)
channel.kind = "email"
channel.value = user.email
channel.email_verified = True
channel.save()
channel.checks.add(*Check.objects.filter(user=user))
示例4: _make_user
# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import kind [as 别名]
def _make_user(email):
username = str(uuid.uuid4())[:30]
user = User(username=username, email=email)
user.set_unusable_password()
user.save()
profile = Profile(user=user)
profile.save()
channel = Channel()
channel.user = user
channel.kind = "email"
channel.value = email
channel.email_verified = True
channel.save()
return user
示例5: _make_user
# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import kind [as 别名]
def _make_user(email):
username = str(uuid.uuid4())[:30]
user = User(username=username, email=email)
user.set_unusable_password()
user.save()
# Ensure a profile gets created
Profile.objects.for_user(user)
channel = Channel()
channel.user = user
channel.kind = "email"
channel.value = email
channel.email_verified = True
channel.save()
return user
示例6: add_pd
# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import kind [as 别名]
def add_pd(request, state=None):
if settings.PD_VENDOR_KEY is None:
raise Http404("pagerduty integration is not available")
if state and request.user.is_authenticated():
if "pd" not in request.session:
return HttpResponseBadRequest()
session_state = request.session.pop("pd")
if session_state != state:
return HttpResponseBadRequest()
if request.GET.get("error") == "cancelled":
messages.warning(request, "PagerDuty setup was cancelled")
return redirect("hc-channels")
channel = Channel()
channel.user = request.team.user
channel.kind = "pd"
channel.value = json.dumps({
"service_key": request.GET.get("service_key"),
"account": request.GET.get("account")
})
channel.save()
channel.assign_all_checks()
messages.success(request, "The PagerDuty integration has been added!")
return redirect("hc-channels")
state = _prepare_state(request, "pd")
callback = settings.SITE_ROOT + reverse("hc-add-pd-state", args=[state])
connect_url = "https://connect.pagerduty.com/connect?" + urlencode({
"vendor": settings.PD_VENDOR_KEY,
"callback": callback
})
ctx = {"page": "channels", "connect_url": connect_url}
return render(request, "integrations/add_pd.html", ctx)