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


Python ScheduledNotification.remove_all_for_incident方法代码示例

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


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

示例1: silence

# 需要导入模块: from notification.models import ScheduledNotification [as 别名]
# 或者: from notification.models.ScheduledNotification import remove_all_for_incident [as 别名]
def silence(request, incident_id):
    try:
        incident = Incident.objects.get(id=incident_id)
        silence_for = request.POST.get('silence_for')
        url = request.POST.get("url")
        if IncidentSilenced.objects.filter(incident=incident).count() < 1:
            silenced_incident = IncidentSilenced()
            silenced_incident.incident = incident
            silenced_incident.silenced_until = timezone.now(
                ) + timezone.timedelta(hours=int(silence_for))
            silenced_incident.silenced = True
            silenced_incident.save()
            event_log_message = "%s silenced incident %s for %s hours" % (
                request.user.username, incident.incident_key, silence_for)
            event_log = EventLog()
            event_log.incident_key = incident
            event_log.action = 'silence_incident'
            event_log.user = request.user
            event_log.service_key = incident.service_key
            event_log.data = event_log_message
            event_log.occurred_at = timezone.now()
            event_log.save()
            ScheduledNotification.remove_all_for_incident(incident)
            incident.event_type = Incident.ACKNOWLEDGE
            incident.save()
            unsilence_incident.apply_async(
                (incident_id,), eta=silenced_incident.silenced_until)
        return HttpResponseRedirect(url)
    except Service.DoesNotExist:
        raise Http404
开发者ID:bantonj,项目名称:openduty,代码行数:32,代码来源:incidents.py

示例2: forward_incident

# 需要导入模块: from notification.models import ScheduledNotification [as 别名]
# 或者: from notification.models.ScheduledNotification import remove_all_for_incident [as 别名]
def forward_incident(request):
    try:
        with transaction.atomic():
            incident = Incident.objects.get(id=request.POST['id'])
            user = User.objects.get(id=request.POST['user_id'])
            ScheduledNotification.remove_all_for_incident(incident)
            NotificationHelper.notify_user_about_incident(incident, user)
            event_log_message = "%s  changed assignee of incident :  %s  to %s" % (
                request.user.username, incident.incident_key, user.username)
            event_log = EventLog()
            event_log.user = request.user
            event_log.action = "forward"
            event_log.incident_key = incident
            event_log.service_key = incident.service_key
            event_log.data = event_log_message
            event_log.occurred_at = timezone.now()
            event_log.save()

    except Incident.DoesNotExist:
        messages.error(request, 'Incident not found')
        return HttpResponseRedirect(request.POST['url'])
    except User.DoesNotExist:
        messages.error(request, 'Incident not found')
        return HttpResponseRedirect(request.POST['url'])
    except ValidationError as e:
        messages.error(request, e.messages)
    return HttpResponseRedirect(request.POST['url'])
开发者ID:bantonj,项目名称:openduty,代码行数:29,代码来源:incidents.py

示例3: create

# 需要导入模块: from notification.models import ScheduledNotification [as 别名]
# 或者: from notification.models.ScheduledNotification import remove_all_for_incident [as 别名]
    def create(self, request, *args, **kwargs):
        try:
            token = Token.objects.get(key = request.DATA["service_key"])
            serviceToken = ServiceTokens.objects.get(token_id=token)
            service = serviceToken.service_id
        except ServiceTokens.DoesNotExist:
            return Response({}, status=status.HTTP_404_NOT_FOUND)
        except Token.DoesNotExist:
            return Response({}, status=status.HTTP_403_FORBIDDEN)

        with transaction.atomic():
            try:
                incident = Incident.objects.get(incident_key =  request.DATA["incident_key"], service_key = service)

                event_log_message = "%s api key changed %s from %s to %s" % (serviceToken.name, incident.incident_key, incident.event_type, request.DATA['event_type'])
            except (Incident.DoesNotExist, KeyError):
                incident = Incident()
                try:
                    incident.incident_key = request.DATA["incident_key"]
                except KeyError:
                    if request.DATA["event_type"] == Incident.TRIGGER:
                        incident.incident_key = base64.urlsafe_b64encode(uuid.uuid1().bytes).replace('=', '')
                    else:
                        response = {}
                        response["status"] = "failure"
                        response["message"] = "Mandatory parameter missing"
                        return Response(response, status=status.HTTP_400_BAD_REQUEST)
                incident.service_key = service

                event_log_message = "%s api key created %s with status %s" % (serviceToken.name, incident.incident_key, request.DATA['event_type'])

            if incident.event_type != Incident.ACKNOWLEDGE or (incident.event_type == Incident.ACKNOWLEDGE and request.DATA["event_type"] == Incident.RESOLVE ):
                event_log = EventLog()
                event_log.service_key = incident.service_key
                event_log.data = event_log_message
                event_log.occurred_at = datetime.now()
                event_log.save()

                incident.event_type = request.DATA["event_type"]
                incident.description = request.DATA["description"][:100]
                incident.details =request.DATA["details"]
                incident.occurred_at = datetime.now()
                try:
                    incident.full_clean()
                except ValidationError as e:
                    return Response({'errors': e.messages}, status=status.HTTP_400_BAD_REQUEST)
                incident.save()

                if incident.event_type == Incident.TRIGGER:
                    NotificationHelper.notify_incident(incident)
                if incident.event_type == "resolve" or incident.event_type == Incident.ACKNOWLEDGE:
                    ScheduledNotification.remove_all_for_incident(incident)

            headers = self.get_success_headers(request.POST)

            response = {}
            response["status"] = "success"
            response["message"] = "Event processed"
            response["incident_key"] = incident.incident_key
            return Response(response, status=status.HTTP_201_CREATED, headers=headers)
开发者ID:PAStheLoD,项目名称:openduty,代码行数:62,代码来源:incidents.py

示例4: _update_type

# 需要导入模块: from notification.models import ScheduledNotification [as 别名]
# 或者: from notification.models.ScheduledNotification import remove_all_for_incident [as 别名]
def _update_type(user, ids, event_type):
    for incident_id in ids:
        with transaction.atomic():
            incident = Incident.objects.get(id=int(incident_id))

            logmessage = EventLog()
            logmessage.service_key = incident.service_key
            logmessage.user = user
            logmessage.action = event_type
            logmessage.data = "%s changed %s from %s to %s" % (
                user.username,
                incident.incident_key,
                incident.event_type,
                event_type)
            logmessage.occurred_at = timezone.now()

            incident.event_type = event_type
            incident.occurred_at = timezone.now()
            incident.save()

            logmessage.incident_key = incident
            logmessage.save()
            if incident.event_type == Incident.RESOLVE or incident.event_type == Incident.ACKNOWLEDGE:
                ScheduledNotification.remove_all_for_incident(incident)
开发者ID:bantonj,项目名称:openduty,代码行数:26,代码来源:incidents.py

示例5: update_type

# 需要导入模块: from notification.models import ScheduledNotification [as 别名]
# 或者: from notification.models.ScheduledNotification import remove_all_for_incident [as 别名]
def update_type(request):
    try:
        with transaction.atomic():
            incident = Incident.objects.get(id = request.POST['id'])

            logmessage = EventLog()
            logmessage.service_key = incident.service_key
            logmessage.data = "%s changed %s from %s to %s" % (request.user.username, incident.incident_key, incident.event_type, request.POST['event_type'])
            logmessage.occurred_at = datetime.now()
            logmessage.save()

            incident.event_type = request.POST['event_type']
            incident.occurred_at = datetime.now()
            incident.save()

            if incident.event_type == "resolve" or incident.event_type == Incident.ACKNOWLEDGE:
                ScheduledNotification.remove_all_for_incident(incident)

    except Incident.DoesNotExist:
        messages.error(request, 'Incident not found')
        return HttpResponseRedirect(request.POST['url'])
    except ValidationError as e:
        messages.error(request, e.messages)
    return HttpResponseRedirect(request.POST['url'])
开发者ID:PAStheLoD,项目名称:openduty,代码行数:26,代码来源:incidents.py


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