예제 #1
0
    def notification_type(self):
        from pretix.base.notifications import get_all_notification_types

        no_type = None
        no_types = get_all_notification_types()
        typepath = self.action_type
        while not no_type and '.' in typepath:
            no_type = no_type or no_types.get(typepath + ('.*' if typepath != self.action_type else ''))
            typepath = typepath.rsplit('.', 1)[0]
        return no_type
예제 #2
0
def send_notification(logentry_id: int, action_type: str, user_id: int, method: str):
    logentry = LogEntry.all.get(id=logentry_id)
    user = User.objects.get(id=user_id)
    types = get_all_notification_types(logentry.event)
    notification_type = types.get(action_type)
    if not notification_type:
        return  # Ignore, e.g. plugin not active for this event

    with language(user.locale):
        notification = notification_type.build_notification(logentry)

        if method == "mail":
            send_notification_mail(notification, user)
예제 #3
0
def notify(logentry_id: int):
    logentry = LogEntry.all.get(id=logentry_id)
    if not logentry.event:
        return  # Ignore, we only have event-related notifications right now
    types = get_all_notification_types(logentry.event)

    notification_type = None
    typepath = logentry.action_type
    while not notification_type and '.' in typepath:
        notification_type = types.get(typepath + ('.*' if typepath != logentry.action_type else ''))
        typepath = typepath.rsplit('.', 1)[0]

    if not notification_type:
        return  # No suitable plugin

    # All users that have the permission to get the notification
    users = logentry.event.get_users_with_permission(
        notification_type.required_permission
    ).filter(notifications_send=True)
    if logentry.user:
        users = users.exclude(pk=logentry.user.pk)

    # Get all notification settings, both specific to this event as well as global
    notify_specific = {
        (ns.user, ns.method): ns.enabled
        for ns in NotificationSetting.objects.filter(
            event=logentry.event,
            action_type=notification_type.action_type,
            user__pk__in=users.values_list('pk', flat=True)
        )
    }
    notify_global = {
        (ns.user, ns.method): ns.enabled
        for ns in NotificationSetting.objects.filter(
            event__isnull=True,
            action_type=notification_type.action_type,
            user__pk__in=users.values_list('pk', flat=True)
        )
    }

    for um, enabled in notify_specific.items():
        user, method = um
        if enabled:
            send_notification.apply_async(args=(logentry_id, notification_type.action_type, user.pk, method))

    for um, enabled in notify_global.items():
        user, method = um
        if enabled and um not in notify_specific:
            send_notification.apply_async(args=(logentry_id, notification_type.action_type, user.pk, method))
예제 #4
0
def send_notification(logentry_id: int, action_type: str, user_id: int, method: str):
    logentry = LogEntry.all.get(id=logentry_id)
    if logentry.event:
        sm = lambda: scope(organizer=logentry.event.organizer)  # noqa
    else:
        sm = lambda: scopes_disabled()  # noqa
    with sm():
        user = User.objects.get(id=user_id)
        types = get_all_notification_types(logentry.event)
        notification_type = types.get(action_type)
        if not notification_type:
            return  # Ignore, e.g. plugin not active for this event

        with language(user.locale), override(logentry.event.timezone if logentry.event else user.timezone):
            notification = notification_type.build_notification(logentry)

            if method == "mail":
                send_notification_mail(notification, user)
예제 #5
0
def notify(logentry_id: int):
    logentry = LogEntry.all.get(id=logentry_id)
    if not logentry.event:
        return  # Ignore, we only have event-related notifications right now
    types = get_all_notification_types(logentry.event)
    notification_type = types.get(logentry.action_type)
    if not notification_type:
        return  # Ignore, e.g. plugin not active for this event

    # All users that have the permission to get the notification
    users = logentry.event.get_users_with_permission(
        notification_type.required_permission
    ).filter(notifications_send=True)
    if logentry.user:
        users = users.exclude(pk=logentry.user.pk)

    # Get all notification settings, both specific to this event as well as global
    notify_specific = {
        (ns.user, ns.method): ns.enabled
        for ns in NotificationSetting.objects.filter(
            event=logentry.event,
            action_type=logentry.action_type,
            user__pk__in=users.values_list('pk', flat=True)
        )
    }
    notify_global = {
        (ns.user, ns.method): ns.enabled
        for ns in NotificationSetting.objects.filter(
            action_type=logentry.action_type,
            user__pk__in=users.values_list('pk', flat=True)
        )
    }

    for um, enabled in notify_specific.items():
        user, method = um
        if enabled:
            send_notification.apply_async(args=(logentry_id, user.pk, method))

    for um, enabled in notify_global.items():
        user, method = um
        if enabled and um not in notify_specific:
            send_notification.apply_async(args=(logentry_id, user.pk, method))
예제 #6
0
파일: user.py 프로젝트: zippyy/pretix
 def types(self):
     return get_all_notification_types(self.event)
예제 #7
0
파일: user.py 프로젝트: FlaviaBastos/pretix
 def types(self):
     return get_all_notification_types(self.event)