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


Python ScheduledNotification.user_to_notify方法代码示例

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


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

示例1: generate_notifications_for_user

# 需要导入模块: from notification.models import ScheduledNotification [as 别名]
# 或者: from notification.models.ScheduledNotification import user_to_notify [as 别名]
    def generate_notifications_for_user(incident, user):

        now = timezone.make_aware(datetime.now(), timezone.get_current_timezone())
        current_time = now
        notifications = []
        methods = user.notification_methods.all()
        method_index = 0

        for method in methods:
            notification_time = incident.service_key.retry * method_index + incident.service_key.escalate_after
            notify_at = current_time + timedelta(minutes=notification_time)
            notification = ScheduledNotification()
            notification.incident = incident
            notification.user_to_notify = user
            notification.notifier = method.method
            notification.send_at = notify_at
            uri = settings.BASE_URL + "/incidents/details/" + str(incident.id)
            notification.message = "A Service is experiencing a problem: " + incident.incident_key + " " + incident.description + ". Handle at: " + uri

            notifications.append(notification)
            print "Notify %s at %s with method: %s" % (user.username, notify_at, notification.notifier)
            method_index += 1

        # todo: error handling
        return notifications
开发者ID:yuandaxing,项目名称:openDRI,代码行数:27,代码来源:helper.py

示例2: generate_notifications_for_incident

# 需要导入模块: from notification.models import ScheduledNotification [as 别名]
# 或者: from notification.models.ScheduledNotification import user_to_notify [as 别名]
    def generate_notifications_for_incident(incident):
        now = timezone.make_aware(datetime.now(), timezone.get_current_timezone())
        duty_officers = get_escalation_for_service(incident.service_key)

        current_time = now

        notifications = []

        for officer_index, duty_officer in enumerate(duty_officers):
            escalation_time = incident.service_key.escalate_after * (officer_index + 1)
            escalate_at = current_time + timedelta(minutes=escalation_time)

            methods = duty_officer.notification_methods.order_by('position').all()
            method_index = 0

            for method in methods:
                notification_time = incident.service_key.retry * method_index + incident.service_key.escalate_after * officer_index
                notify_at = current_time + timedelta(minutes=notification_time)
                if notify_at < escalate_at:
                    notification = ScheduledNotification()
                    notification.incident = incident
                    notification.user_to_notify = duty_officer
                    notification.notifier = method.method
                    notification.send_at = notify_at
                    uri = settings.BASE_URL + "/incidents/details/" + str(incident.id)
                    notification.message = "A Service is experiencing a problem: {} {}. Handle at: {}. Details: {}".format(incident.incident_key, incident.description, uri, incident.details)

                    notifications.append(notification)

                    print("Notify {} at {} with method: {}".format(duty_officer.username, notify_at, notification.notifier))
                else:
                    break
                method_index += 1

            # todo: error handling

        return notifications
开发者ID:PAStheLoD,项目名称:openduty,代码行数:39,代码来源:helper.py


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