Skip to content

querysets

django_spire.notification.app.querysets

AppNotificationQuerySet

Bases: HistoryQuerySet, NotificationContentObjectQuerySet, SearchQuerySetMixin

annotate_is_viewed_by_user

Source code in django_spire/notification/app/querysets.py
def annotate_is_viewed_by_user(self, user: User) -> QuerySet:
    return self.by_user(user=user).annotate(
        viewed=Case(
            When(views__user=user, then=Value(True)),
            default=Value(False),
            output_field=BooleanField(),
        )
    )

ordered_by_priority_and_sent_datetime

Source code in django_spire/notification/app/querysets.py
def ordered_by_priority_and_sent_datetime(self) -> QuerySet:
    priority_order = Case(
        When(notification__priority=NotificationPriorityChoices.LOW, then=Value(3)),
        When(notification__priority=NotificationPriorityChoices.MEDIUM, then=Value(2)),
        When(notification__priority=NotificationPriorityChoices.HIGH, then=Value(1)),
        output_field=IntegerField(),
    )
    return self.annotate(priority_order=priority_order).order_by(
        '-notification__sent_datetime', 'priority_order'
    )

by_user

Source code in django_spire/notification/app/querysets.py
def by_user(self, user: User) -> QuerySet:
    return self.filter(notification__user=user)

by_users

Source code in django_spire/notification/app/querysets.py
def by_users(self, users: list[User]) -> QuerySet:
    return self.filter(notification__user__in=users)

exclude_viewed_by_user

Source code in django_spire/notification/app/querysets.py
def exclude_viewed_by_user(self, user: User) -> QuerySet:
    return self.by_user(user=user).exclude(views__user=user)

is_sent

Source code in django_spire/notification/app/querysets.py
def is_sent(self) -> QuerySet:
    return self.filter(notification__status=NotificationStatusChoices.SENT)

search

Source code in django_spire/notification/app/querysets.py
def search(self, search_value: str | None) -> QuerySet:
    if search_value in [None, '']:
        return self

    return self.filter(
        Q(notification__title__icontains=search_value)
        | Q(notification__body__icontains=search_value)
    )