Skip to content

querysets

django_spire.notification.querysets

NotificationQuerySet

Bases: HistoryQuerySet

app_notifications

Source code in django_spire/notification/querysets.py
def app_notifications(self):
    return self.filter(type=NotificationTypeChoices.APP)

by_content_object

Source code in django_spire/notification/querysets.py
def by_content_object(self, content_object: type[Model]):
    return self.filter(
        content_type=get_content_type_for_model(content_object),
        object_id=content_object.pk,
    )

by_content_objects

Source code in django_spire/notification/querysets.py
def by_content_objects(self, content_objects: list[type[Model]]):
    if not content_objects:
        return self.none()

    content_type_to_object_ids = defaultdict(list)

    for content_object in content_objects:
        content_type_to_object_ids[
            get_content_type_for_model(content_object)
        ].append(content_object.pk)

    queries = Q()
    for content_type, object_ids in content_type_to_object_ids.items():
        queries |= Q(
            content_type=content_type,
            object_id__in=object_ids
        )

    return self.filter(queries)

by_user

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

by_users

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

email_notifications

Source code in django_spire/notification/querysets.py
def email_notifications(self):
    return self.filter(type=NotificationTypeChoices.EMAIL)

errored

Source code in django_spire/notification/querysets.py
def errored(self):
    return self.filter(status=NotificationStatusChoices.ERRORED)

failed

Source code in django_spire/notification/querysets.py
def failed(self):
    return self.filter(status=NotificationStatusChoices.FAILED)

high_priority

Source code in django_spire/notification/querysets.py
def high_priority(self):
    return self.filter(priority=NotificationPriorityChoices.HIGH)

low_priority

Source code in django_spire/notification/querysets.py
def low_priority(self):
    return self.filter(priority=NotificationPriorityChoices.LOW)

medium_priority

Source code in django_spire/notification/querysets.py
def medium_priority(self):
    return self.filter(priority=NotificationPriorityChoices.MEDIUM)

pending

Source code in django_spire/notification/querysets.py
def pending(self):
    return self.filter(status=NotificationStatusChoices.PENDING)

processing

Source code in django_spire/notification/querysets.py
def processing(self):
    return self.filter(status=NotificationStatusChoices.PROCESSING)

push_notifications

Source code in django_spire/notification/querysets.py
def push_notifications(self):
    return self.filter(status=NotificationTypeChoices.PUSH)

ready_to_send

Source code in django_spire/notification/querysets.py
def ready_to_send(self):
    return self.pending().filter(publish_datetime__lte=now())

sent

Source code in django_spire/notification/querysets.py
def sent(self):
    return self.filter(status=NotificationStatusChoices.SENT)

sms_notifications

Source code in django_spire/notification/querysets.py
def sms_notifications(self):
    return self.filter(type=NotificationTypeChoices.SMS)

unsent

Source code in django_spire/notification/querysets.py
def unsent(self):
    return self.filter(status__in=[NotificationStatusChoices.PENDING, NotificationStatusChoices.PROCESSING])

NotificationContentObjectQuerySet

Bases: QuerySet

by_notification_content_object

Source code in django_spire/notification/querysets.py
def by_notification_content_object(self, content_object: type[Model]):
    return self.filter(
        notification__content_type=get_content_type_for_model(content_object),
        notification__object_id=content_object.pk,
    )

by_notification_content_objects

Source code in django_spire/notification/querysets.py
def by_notification_content_objects(self, content_objects: list[type[Model]]):
    if not content_objects:
        return self.none()

    content_type_to_object_ids = defaultdict(list)

    for content_object in content_objects:
        content_type_to_object_ids[
            get_content_type_for_model(content_object)
        ].append(content_object.pk)

    queries = Q()
    for content_type, object_ids in content_type_to_object_ids.items():
        queries |= Q(
            notification__content_type=content_type,
            notification__object_id__in=object_ids
        )

    return self.filter(queries)