Rename Recipient.CLASS to Recipient.STREAM.

(imported from commit a530194163f7260c73921137fa1ff671f14516f6)
This commit is contained in:
Tim Abbott
2012-10-10 16:57:21 -04:00
parent 1fc4780a81
commit 44e9e4cebf
7 changed files with 36 additions and 36 deletions

View File

@@ -153,7 +153,7 @@ def process_loop(log):
'zsig' : zsig, # logged here but not used by app 'zsig' : zsig, # logged here but not used by app
'content' : body } 'content' : body }
else: else:
zeph = { 'type' : 'class', zeph = { 'type' : 'stream',
'time' : str(notice.time), 'time' : str(notice.time),
'sender' : sender, 'sender' : sender,
'class' : notice.cls.lower(), 'class' : notice.cls.lower(),
@@ -221,7 +221,7 @@ def forward_to_zephyr(message):
for line in cleaned_content.split("\n")) for line in cleaned_content.split("\n"))
print "Sending message from %s humbug=>zephyr at %s" % (message["sender_email"], datetime.datetime.now()) print "Sending message from %s humbug=>zephyr at %s" % (message["sender_email"], datetime.datetime.now())
if message['type'] == "class": if message['type'] == "stream":
zeph = zephyr.ZNotice(sender=message["sender_email"].replace("mit.edu", "ATHENA.MIT.EDU"), zeph = zephyr.ZNotice(sender=message["sender_email"].replace("mit.edu", "ATHENA.MIT.EDU"),
auth=True, cls=message["display_recipient"], auth=True, cls=message["display_recipient"],
instance=message["instance"]) instance=message["instance"])

View File

@@ -43,7 +43,7 @@ def process_push(oldrev, newrev, refname):
oldrev, newrev, refname]) oldrev, newrev, refname])
commits = subprocess.check_output(["git", "log", "--reverse", "--pretty=- **%aN**: %s", "%s..%s" % (oldrev, newrev)]) commits = subprocess.check_output(["git", "log", "--reverse", "--pretty=- **%aN**: %s", "%s..%s" % (oldrev, newrev)])
message_data = { message_data = {
"type": "class", "type": "stream",
"class": "test" if refname == "refs/heads/test-post-receive" else "devel", "class": "test" if refname == "refs/heads/test-post-receive" else "devel",
"instance": "commits", "instance": "commits",
"content": "The following commits were just pushed to `%s`:\n\n" "content": "The following commits were just pushed to `%s`:\n\n"

View File

@@ -118,7 +118,7 @@ class Command(BaseCommand):
# Create public classes. # Create public classes.
create_streams(class_list, humbug_realm) create_streams(class_list, humbug_realm)
recipient_classes = [klass.type_id for klass in recipient_classes = [klass.type_id for klass in
Recipient.objects.filter(type=Recipient.CLASS)] Recipient.objects.filter(type=Recipient.STREAM)]
# Create subscriptions to classes # Create subscriptions to classes
profiles = UserProfile.objects.all() profiles = UserProfile.objects.all()
@@ -126,14 +126,14 @@ class Command(BaseCommand):
# Subscribe to some classes. # Subscribe to some classes.
for recipient in recipient_classes[:int(len(recipient_classes) * for recipient in recipient_classes[:int(len(recipient_classes) *
float(i)/len(profiles)) + 1]: float(i)/len(profiles)) + 1]:
r = Recipient.objects.get(type=Recipient.CLASS, type_id=recipient) r = Recipient.objects.get(type=Recipient.STREAM, type_id=recipient)
new_subscription = Subscription(userprofile=profile, new_subscription = Subscription(userprofile=profile,
recipient=r) recipient=r)
new_subscription.save() new_subscription.save()
else: else:
humbug_realm = Realm.objects.get(domain="humbughq.com") humbug_realm = Realm.objects.get(domain="humbughq.com")
recipient_classes = [klass.type_id for klass in recipient_classes = [klass.type_id for klass in
Recipient.objects.filter(type=Recipient.CLASS)] Recipient.objects.filter(type=Recipient.STREAM)]
# Extract a list of all users # Extract a list of all users
users = [user.id for user in User.objects.all()] users = [user.id for user in User.objects.all()]
@@ -170,7 +170,7 @@ class Command(BaseCommand):
profiles = UserProfile.objects.filter(realm=mit_realm) profiles = UserProfile.objects.filter(realm=mit_realm)
for cls in mit_subs_list.all_subs: for cls in mit_subs_list.all_subs:
stream = Stream.objects.get(name=cls, realm=mit_realm) stream = Stream.objects.get(name=cls, realm=mit_realm)
recipient = Recipient.objects.get(type=Recipient.CLASS, type_id=stream.id) recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id)
for i, profile in enumerate(profiles): for i, profile in enumerate(profiles):
if profile.user.email in mit_subs_list.subs_lists: if profile.user.email in mit_subs_list.subs_lists:
key = profile.user.email key = profile.user.email
@@ -189,7 +189,7 @@ class Command(BaseCommand):
profiles = UserProfile.objects.filter(realm=humbug_realm) profiles = UserProfile.objects.filter(realm=humbug_realm)
for cls in humbug_class_list: for cls in humbug_class_list:
stream = Stream.objects.get(name=cls, realm=humbug_realm) stream = Stream.objects.get(name=cls, realm=humbug_realm)
recipient = Recipient.objects.get(type=Recipient.CLASS, type_id=stream.id) recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id)
for i, profile in enumerate(profiles): for i, profile in enumerate(profiles):
# Subscribe to some classes. # Subscribe to some classes.
new_subscription = Subscription(userprofile=profile, recipient=recipient) new_subscription = Subscription(userprofile=profile, recipient=recipient)
@@ -235,7 +235,7 @@ def restore_saved_messages():
old_message["sender_full_name"], old_message["sender_full_name"],
old_message["sender_short_name"]) old_message["sender_short_name"])
message.sender = UserProfile.objects.get(user__email=old_message["sender_email"]) message.sender = UserProfile.objects.get(user__email=old_message["sender_email"])
type_hash = {"class": Recipient.CLASS, "huddle": Recipient.HUDDLE, "personal": Recipient.PERSONAL} type_hash = {"stream": Recipient.STREAM, "huddle": Recipient.HUDDLE, "personal": Recipient.PERSONAL}
message.type = type_hash[old_message["type"]] message.type = type_hash[old_message["type"]]
message.content = old_message["content"] message.content = old_message["content"]
message.instance = old_message["instance"] message.instance = old_message["instance"]
@@ -248,9 +248,9 @@ def restore_saved_messages():
user_profile = UserProfile.objects.get(user__email=u["email"]) user_profile = UserProfile.objects.get(user__email=u["email"])
message.recipient = Recipient.objects.get(type=Recipient.PERSONAL, message.recipient = Recipient.objects.get(type=Recipient.PERSONAL,
type_id=user_profile.id) type_id=user_profile.id)
elif message.type == Recipient.CLASS: elif message.type == Recipient.STREAM:
stream = create_stream_if_needed(realm, old_message["recipient"]) stream = create_stream_if_needed(realm, old_message["recipient"])
message.recipient = Recipient.objects.get(type=Recipient.CLASS, message.recipient = Recipient.objects.get(type=Recipient.STREAM,
type_id=stream.id) type_id=stream.id)
elif message.type == Recipient.HUDDLE: elif message.type == Recipient.HUDDLE:
for u in old_message["recipient"]: for u in old_message["recipient"]:
@@ -280,7 +280,7 @@ def send_messages(data):
offset = random.randint(0, len(texts)) offset = random.randint(0, len(texts))
recipient_classes = [klass.id for klass in recipient_classes = [klass.id for klass in
Recipient.objects.filter(type=Recipient.CLASS)] Recipient.objects.filter(type=Recipient.STREAM)]
recipient_huddles = [h.id for h in Recipient.objects.filter(type=Recipient.HUDDLE)] recipient_huddles = [h.id for h in Recipient.objects.filter(type=Recipient.HUDDLE)]
huddle_members = {} huddle_members = {}
@@ -309,7 +309,7 @@ def send_messages(data):
if message_type == Recipient.PERSONAL: if message_type == Recipient.PERSONAL:
personals_pair = saved_data personals_pair = saved_data
random.shuffle(personals_pair) random.shuffle(personals_pair)
elif message_type == Recipient.CLASS: elif message_type == Recipient.STREAM:
message.instance = saved_data message.instance = saved_data
message.recipient = get_recipient_by_id(recipient_id) message.recipient = get_recipient_by_id(recipient_id)
elif message_type == Recipient.HUDDLE: elif message_type == Recipient.HUDDLE:
@@ -322,7 +322,7 @@ def send_messages(data):
personals_pair = random.choice(personals_pairs) personals_pair = random.choice(personals_pairs)
random.shuffle(personals_pair) random.shuffle(personals_pair)
elif (randkey <= random_max * 1.0): elif (randkey <= random_max * 1.0):
message_type = Recipient.CLASS message_type = Recipient.STREAM
message.recipient = get_recipient_by_id(random.choice(recipient_classes)) message.recipient = get_recipient_by_id(random.choice(recipient_classes))
if message_type == Recipient.HUDDLE: if message_type == Recipient.HUDDLE:
@@ -333,7 +333,7 @@ def send_messages(data):
type_id=personals_pair[0]) type_id=personals_pair[0])
message.sender = get_user_profile_by_id(personals_pair[1]) message.sender = get_user_profile_by_id(personals_pair[1])
saved_data = personals_pair saved_data = personals_pair
elif message_type == Recipient.CLASS: elif message_type == Recipient.STREAM:
stream = Stream.objects.get(id=message.recipient.type_id) stream = Stream.objects.get(id=message.recipient.type_id)
# Pick a random subscriber to the class # Pick a random subscriber to the class
message.sender = random.choice(Subscription.objects.filter( message.sender = random.choice(Subscription.objects.filter(

View File

@@ -22,7 +22,7 @@ def get_display_recipient(recipient):
returns: an appropriate string describing the recipient (the class returns: an appropriate string describing the recipient (the class
name, for a class, or the email, for a user). name, for a class, or the email, for a user).
""" """
if recipient.type == Recipient.CLASS: if recipient.type == Recipient.STREAM:
stream = Stream.objects.get(id=recipient.type_id) stream = Stream.objects.get(id=recipient.type_id)
return stream.name return stream.name
elif recipient.type == Recipient.HUDDLE: elif recipient.type == Recipient.HUDDLE:
@@ -41,7 +41,7 @@ def get_log_recipient(recipient):
returns: an appropriate string describing the recipient (the class returns: an appropriate string describing the recipient (the class
name, for a class, or the email, for a user). name, for a class, or the email, for a user).
""" """
if recipient.type == Recipient.CLASS: if recipient.type == Recipient.STREAM:
stream = Stream.objects.get(id=recipient.type_id) stream = Stream.objects.get(id=recipient.type_id)
return stream.name return stream.name
@@ -149,7 +149,7 @@ def create_stream_if_needed(realm, class_name):
new_class.name = class_name new_class.name = class_name
new_class.realm = realm new_class.realm = realm
new_class.save() new_class.save()
recipient = Recipient(type_id=new_class.id, type=Recipient.CLASS) recipient = Recipient(type_id=new_class.id, type=Recipient.STREAM)
recipient.save() recipient.save()
return new_class return new_class
@@ -168,7 +168,7 @@ class Stream(models.Model):
stream = cls(name=name, realm=realm) stream = cls(name=name, realm=realm)
stream.save() stream.save()
recipient = Recipient(type_id=stream.id, type=Recipient.CLASS) recipient = Recipient(type_id=stream.id, type=Recipient.STREAM)
recipient.save() recipient.save()
return (stream, recipient) return (stream, recipient)
@@ -177,14 +177,14 @@ class Recipient(models.Model):
type = models.PositiveSmallIntegerField(db_index=True) type = models.PositiveSmallIntegerField(db_index=True)
# Valid types are {personal, class, huddle} # Valid types are {personal, class, huddle}
PERSONAL = 1 PERSONAL = 1
CLASS = 2 STREAM = 2
HUDDLE = 3 HUDDLE = 3
def type_name(self): def type_name(self):
if self.type == self.PERSONAL: if self.type == self.PERSONAL:
return "personal" return "personal"
elif self.type == self.CLASS: elif self.type == self.STREAM:
return "class" return "stream"
elif self.type == self.HUDDLE: elif self.type == self.HUDDLE:
return "huddle" return "huddle"
else: else:
@@ -297,7 +297,7 @@ def do_send_message(message, synced_from_mit=False, no_log=False):
# For personals, you send out either 1 or 2 copies of the message, for # For personals, you send out either 1 or 2 copies of the message, for
# personals to yourself or to someone else, respectively. # personals to yourself or to someone else, respectively.
assert((len(recipients) == 1) or (len(recipients) == 2)) assert((len(recipients) == 1) or (len(recipients) == 2))
elif (message.recipient.type == Recipient.CLASS or elif (message.recipient.type == Recipient.STREAM or
message.recipient.type == Recipient.HUDDLE): message.recipient.type == Recipient.HUDDLE):
recipients = [get_user_profile_by_id(s.userprofile_id) for recipients = [get_user_profile_by_id(s.userprofile_id) for
s in Subscription.objects.filter(recipient=message.recipient, active=True)] s in Subscription.objects.filter(recipient=message.recipient, active=True)]

View File

@@ -207,7 +207,7 @@ function same_recipient(a, b) {
return a.recipient_id === b.recipient_id; return a.recipient_id === b.recipient_id;
case 'personal': case 'personal':
return a.reply_to === b.reply_to; return a.reply_to === b.reply_to;
case 'class': case 'stream':
return (a.recipient_id === b.recipient_id) && return (a.recipient_id === b.recipient_id) &&
(a.instance === b.instance); (a.instance === b.instance);
} }
@@ -364,7 +364,7 @@ function add_message_metadata(dummy, message) {
received.last = Math.max(received.last, message.id); received.last = Math.max(received.last, message.id);
switch (message.type) { switch (message.type) {
case 'class': case 'stream':
message.is_class = true; message.is_class = true;
if ($.inArray(message.instance, instance_list) === -1) { if ($.inArray(message.instance, instance_list) === -1) {
instance_list.push(message.instance); instance_list.push(message.instance);

View File

@@ -62,7 +62,7 @@ class AuthedTestCase(TestCase):
def users_subscribed_to_class(self, class_name, realm_domain): def users_subscribed_to_class(self, class_name, realm_domain):
realm = Realm.objects.get(domain=realm_domain) realm = Realm.objects.get(domain=realm_domain)
stream = Stream.objects.get(name=class_name, realm=realm) stream = Stream.objects.get(name=class_name, realm=realm)
recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.CLASS) recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
subscriptions = Subscription.objects.filter(recipient=recipient) subscriptions = Subscription.objects.filter(recipient=recipient)
return [subscription.userprofile.user for subscription in subscriptions] return [subscription.userprofile.user for subscription in subscriptions]
@@ -247,7 +247,7 @@ class ClassMessagesTest(AuthedTestCase):
a_subscriber = subscribers[0].username a_subscriber = subscribers[0].username
a_subscriber_email = subscribers[0].email a_subscriber_email = subscribers[0].email
self.login(a_subscriber_email, a_subscriber) self.login(a_subscriber_email, a_subscriber)
self.send_message(a_subscriber_email, "Scotland", Recipient.CLASS) self.send_message(a_subscriber_email, "Scotland", Recipient.STREAM)
new_subscriber_messages = [] new_subscriber_messages = []
for subscriber in subscribers: for subscriber in subscribers:
@@ -316,7 +316,7 @@ class MessagePOSTTest(AuthedTestCase):
successful. successful.
""" """
self.login("hamlet@humbughq.com", "hamlet") self.login("hamlet@humbughq.com", "hamlet")
result = self.client.post("/send_message/", {"type": "class", result = self.client.post("/send_message/", {"type": "stream",
"class": "Verona", "class": "Verona",
"content": "Test message", "content": "Test message",
"instance": "Test instance"}) "instance": "Test instance"})
@@ -329,7 +329,7 @@ class MessagePOSTTest(AuthedTestCase):
""" """
self.login("hamlet@humbughq.com", "hamlet") self.login("hamlet@humbughq.com", "hamlet")
self.assertFalse(Stream.objects.filter(name="nonexistent_class")) self.assertFalse(Stream.objects.filter(name="nonexistent_class"))
result = self.client.post("/send_message/", {"type": "class", result = self.client.post("/send_message/", {"type": "stream",
"class": "nonexistent_class", "class": "nonexistent_class",
"content": "Test message", "content": "Test message",
"instance": "Test instance"}) "instance": "Test instance"})

View File

@@ -167,7 +167,7 @@ def home(request):
subscriptions = Subscription.objects.filter(userprofile_id=user_profile, active=True) subscriptions = Subscription.objects.filter(userprofile_id=user_profile, active=True)
classes = [get_display_recipient(sub.recipient) for sub in subscriptions classes = [get_display_recipient(sub.recipient) for sub in subscriptions
if sub.recipient.type == Recipient.CLASS] if sub.recipient.type == Recipient.STREAM]
return render_to_response('zephyr/index.html', return render_to_response('zephyr/index.html',
{'user_profile': user_profile, {'user_profile': user_profile,
@@ -354,7 +354,7 @@ def send_message_backend(request, user_profile, sender):
sender = create_forged_message_users(request, user_profile) sender = create_forged_message_users(request, user_profile)
message_type_name = request.POST["type"] message_type_name = request.POST["type"]
if message_type_name == 'class': if message_type_name == 'stream':
if "class" not in request.POST: if "class" not in request.POST:
return json_error("Missing class") return json_error("Missing class")
if "instance" not in request.POST: if "instance" not in request.POST:
@@ -369,7 +369,7 @@ def send_message_backend(request, user_profile, sender):
# return json_error("Invalid instance name") # return json_error("Invalid instance name")
stream = create_stream_if_needed(user_profile.realm, stream_name) stream = create_stream_if_needed(user_profile.realm, stream_name)
recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.CLASS) recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
elif message_type_name == 'personal': elif message_type_name == 'personal':
if "recipient" not in request.POST: if "recipient" not in request.POST:
return json_error("Missing recipient") return json_error("Missing recipient")
@@ -408,7 +408,7 @@ def send_message_backend(request, user_profile, sender):
message.sender = UserProfile.objects.get(user=sender) message.sender = UserProfile.objects.get(user=sender)
message.content = strip_html(request.POST['content']) message.content = strip_html(request.POST['content'])
message.recipient = recipient message.recipient = recipient
if message_type_name == 'class': if message_type_name == 'stream':
message.instance = instance_name message.instance = instance_name
if 'time' in request.POST: if 'time' in request.POST:
# Forged messages come with a timestamp # Forged messages come with a timestamp
@@ -426,7 +426,7 @@ def gather_subscriptions(user_profile):
subscriptions = Subscription.objects.filter(userprofile=user_profile, active=True) subscriptions = Subscription.objects.filter(userprofile=user_profile, active=True)
# For now, don't display the subscription for your ability to receive personals. # For now, don't display the subscription for your ability to receive personals.
return sorted([get_display_recipient(sub.recipient) for sub in subscriptions return sorted([get_display_recipient(sub.recipient) for sub in subscriptions
if sub.recipient.type == Recipient.CLASS]) if sub.recipient.type == Recipient.STREAM])
@login_required @login_required
def subscriptions(request): def subscriptions(request):
@@ -456,7 +456,7 @@ def json_remove_subscription(request):
return json_error("Not subscribed, so you can't unsubscribe") return json_error("Not subscribed, so you can't unsubscribe")
recipient = Recipient.objects.get(type_id=stream.id, recipient = Recipient.objects.get(type_id=stream.id,
type=Recipient.CLASS) type=Recipient.STREAM)
subscription = Subscription.objects.get( subscription = Subscription.objects.get(
userprofile=user_profile, recipient=recipient) userprofile=user_profile, recipient=recipient)
subscription.active = False subscription.active = False
@@ -482,7 +482,7 @@ def json_add_subscription(request):
stream = create_stream_if_needed(user_profile.realm, sub_name) stream = create_stream_if_needed(user_profile.realm, sub_name)
recipient = Recipient.objects.get(type_id=stream.id, recipient = Recipient.objects.get(type_id=stream.id,
type=Recipient.CLASS) type=Recipient.STREAM)
subscription = Subscription.objects.filter(userprofile=user_profile, subscription = Subscription.objects.filter(userprofile=user_profile,
recipient=recipient) recipient=recipient)