mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		
							
								
								
									
										19
									
								
								zerver/lib/stream_subscription.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								zerver/lib/stream_subscription.py
									
									
									
									
									
										Normal 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()
 | 
			
		||||
		Reference in New Issue
	
	Block a user