Skip to content

Commit d13a6a9

Browse files
committed
refactor queryset
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 914d3e3 commit d13a6a9

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

aboutcode/notifications/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
from aboutcode.notifications.models import AbstractWebhookDelivery
1010
from aboutcode.notifications.models import AbstractWebhookSubscription
11+
from aboutcode.notifications.models import WebhookSubscriptionQuerySetMixin
1112

1213
__version__ = "0.1.0"
1314

14-
__all__ = ["AbstractWebhookSubscription", "AbstractWebhookDelivery"]
15+
__all__ = [
16+
"AbstractWebhookSubscription",
17+
"AbstractWebhookDelivery",
18+
"WebhookSubscriptionQuerySetMixin",
19+
]

aboutcode/notifications/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
logger = logging.getLogger(__name__)
2020

2121

22+
class WebhookSubscriptionQuerySetMixin:
23+
"""Mixin for WebhookSubscription querysets. Combine with the project's base QuerySet."""
24+
25+
def active(self):
26+
return self.filter(is_active=True)
27+
28+
2229
class AbstractWebhookSubscription(models.Model):
2330
"""
2431
Abstract base for Webhook subscription models.

notification/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
from aboutcode.notifications import AbstractWebhookDelivery
1717
from aboutcode.notifications import AbstractWebhookSubscription
18+
from aboutcode.notifications import WebhookSubscriptionQuerySetMixin
1819
from dje.models import DataspacedModel
1920
from dje.models import DataspacedQuerySet
2021

2122
logger = logging.getLogger("dje")
2223

2324

24-
class WebhookSubscriptionQuerySet(DataspacedQuerySet):
25-
def active(self):
26-
return self.filter(is_active=True)
25+
class WebhookSubscriptionQuerySet(WebhookSubscriptionQuerySetMixin, DataspacedQuerySet):
26+
pass
2727

2828

2929
class WebhookSubscription(DataspacedModel, AbstractWebhookSubscription):

0 commit comments

Comments
 (0)