Add zerver/lib/stream_subscription.py.

The first method we extract to this library is
get_active_subscriptions_for_stream_id().

We also move num_subscribers_for_stream_id() to here, which
is slightly annoying (having the method on Stream was nice)
but avoids some circular dependency issues.
This commit is contained in:
Steve Howell
2017-10-29 07:40:07 -07:00
committed by Tim Abbott
parent 138568f4f4
commit 126e14d1de
4 changed files with 38 additions and 37 deletions

View File

@@ -0,0 +1,19 @@
from django.db.models.query import QuerySet
from zerver.models import (
Recipient,
Subscription,
)
def get_active_subscriptions_for_stream_id(stream_id):
# type: (int) -> QuerySet
return Subscription.objects.filter(
recipient__type=Recipient.STREAM,
recipient__type_id=stream_id,
active=True,
)
def num_subscribers_for_stream_id(stream_id):
# type: (int) -> int
return get_active_subscriptions_for_stream_id(stream_id).filter(
user_profile__is_active=True,
).count()