Rename class => stream in models.py.

(imported from commit c9513da997e126bc3c84c6d66176d3402a57db66)
This commit is contained in:
Tim Abbott
2012-10-10 16:58:51 -04:00
parent 44e9e4cebf
commit cdcaaa578f

View File

@@ -19,8 +19,8 @@ def get_display_recipient(recipient):
""" """
recipient: an instance of Recipient. recipient: an instance of Recipient.
returns: an appropriate string describing the recipient (the class returns: an appropriate string describing the recipient (the stream
name, for a class, or the email, for a user). name, for a stream, or the email, for a user).
""" """
if recipient.type == Recipient.STREAM: if recipient.type == Recipient.STREAM:
stream = Stream.objects.get(id=recipient.type_id) stream = Stream.objects.get(id=recipient.type_id)
@@ -38,8 +38,8 @@ def get_log_recipient(recipient):
""" """
recipient: an instance of Recipient. recipient: an instance of Recipient.
returns: an appropriate string describing the recipient (the class returns: an appropriate string describing the recipient (the stream
name, for a class, or the email, for a user). name, for a stream, or the email, for a user).
""" """
if recipient.type == Recipient.STREAM: if recipient.type == Recipient.STREAM:
stream = Stream.objects.get(id=recipient.type_id) stream = Stream.objects.get(id=recipient.type_id)
@@ -141,17 +141,17 @@ def create_user_if_needed(realm, email, password, full_name, short_name):
user = User.objects.get(email=email) user = User.objects.get(email=email)
return user return user
def create_stream_if_needed(realm, class_name): def create_stream_if_needed(realm, stream_name):
try: try:
return Stream.objects.get(name__iexact=class_name, realm=realm) return Stream.objects.get(name__iexact=stream_name, realm=realm)
except Stream.DoesNotExist: except Stream.DoesNotExist:
new_class = Stream() stream = Stream()
new_class.name = class_name stream.name = stream_name
new_class.realm = realm stream.realm = realm
new_class.save() stream.save()
recipient = Recipient(type_id=new_class.id, type=Recipient.STREAM) recipient = Recipient(type_id=stream.id, type=Recipient.STREAM)
recipient.save() recipient.save()
return new_class return stream
class Stream(models.Model): class Stream(models.Model):
@@ -175,7 +175,7 @@ class Stream(models.Model):
class Recipient(models.Model): class Recipient(models.Model):
type_id = models.IntegerField(db_index=True) type_id = models.IntegerField(db_index=True)
type = models.PositiveSmallIntegerField(db_index=True) type = models.PositiveSmallIntegerField(db_index=True)
# Valid types are {personal, class, huddle} # Valid types are {personal, stream, huddle}
PERSONAL = 1 PERSONAL = 1
STREAM = 2 STREAM = 2
HUDDLE = 3 HUDDLE = 3
@@ -350,7 +350,7 @@ def filter_by_subscriptions(messages, user):
subscriptions = [sub.recipient for sub in subscriptions = [sub.recipient for sub in
Subscription.objects.filter(userprofile=userprofile, active=True)] Subscription.objects.filter(userprofile=userprofile, active=True)]
for message in messages: for message in messages:
# If you are subscribed to the personal or class, or if you # If you are subscribed to the personal or stream, or if you
# sent the personal, you can see the message. # sent the personal, you can see the message.
if (message.recipient in subscriptions) or \ if (message.recipient in subscriptions) or \
(message.recipient.type == Recipient.PERSONAL and (message.recipient.type == Recipient.PERSONAL and