Move get_stream to models.py and accept an id for the realm argument.

(imported from commit 7ce09b7ed450cfa3ddf1de22bbb0b19abfc4a2a2)
This commit is contained in:
Tim Abbott 2013-01-17 16:16:39 -05:00
parent b6345e6c3d
commit 8cb8c0065c
2 changed files with 12 additions and 7 deletions

View File

@ -159,6 +159,17 @@ def get_client(name):
return Client.objects.get(name=name)
return client
# get_stream takes either a realm id or a realm
def get_stream(stream_name, realm):
if isinstance(realm, Realm):
realm_id = realm.id
else:
realm_id = realm
try:
return Stream.objects.get(name__iexact=stream_name, realm_id=realm_id)
except Stream.DoesNotExist:
return None
def linebreak(string):
return string.replace('\n\n', '<p/>').replace('\n', '<br/>')

View File

@ -14,7 +14,7 @@ from django.core.mail import send_mail
from zephyr.models import Message, UserProfile, Stream, Subscription, \
Recipient, get_display_recipient, get_huddle, Realm, UserMessage, \
StreamColor, PreregistrationUser, get_client, MitUser, User, UserActivity, \
MAX_SUBJECT_LENGTH, MAX_MESSAGE_LENGTH
MAX_SUBJECT_LENGTH, MAX_MESSAGE_LENGTH, get_stream
from zephyr.lib.actions import do_add_subscription, do_remove_subscription, \
do_change_password, create_mit_user_if_needed, \
do_change_full_name, do_change_enable_desktop_notifications, \
@ -48,12 +48,6 @@ import base64
SERVER_GENERATION = int(time.time())
def get_stream(stream_name, realm):
try:
return Stream.objects.get(name__iexact=stream_name, realm=realm)
except Stream.DoesNotExist:
return None
def send_signup_message(sender, signups_stream, user_profile, internal=False):
if internal:
# When this is done using manage.py vs. the web interface