populate_db: Refactor saved_data to use a consistent type.

This commit is contained in:
Tim Abbott 2016-01-27 13:14:21 -08:00
parent c55ac01ae6
commit 5f9cd4d7c8
1 changed files with 5 additions and 5 deletions

View File

@ -716,7 +716,7 @@ def send_messages(data):
random_max = 1000000 random_max = 1000000
recipients = {} recipients = {}
while num_messages < tot_messages: while num_messages < tot_messages:
saved_data = '' saved_data = {}
message = Message() message = Message()
message.sending_client = get_client('populate_db') message.sending_client = get_client('populate_db')
length = random.randint(1, 5) length = random.randint(1, 5)
@ -731,10 +731,10 @@ def send_messages(data):
# Use an old recipient # Use an old recipient
message_type, recipient_id, saved_data = recipients[num_messages - 1] message_type, recipient_id, saved_data = recipients[num_messages - 1]
if message_type == Recipient.PERSONAL: if message_type == Recipient.PERSONAL:
personals_pair = saved_data personals_pair = saved_data['personals_pair']
random.shuffle(personals_pair) random.shuffle(personals_pair)
elif message_type == Recipient.STREAM: elif message_type == Recipient.STREAM:
message.subject = saved_data message.subject = saved_data['subject']
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:
message.recipient = get_recipient_by_id(recipient_id) message.recipient = get_recipient_by_id(recipient_id)
@ -756,14 +756,14 @@ def send_messages(data):
message.recipient = Recipient.objects.get(type=Recipient.PERSONAL, message.recipient = Recipient.objects.get(type=Recipient.PERSONAL,
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'] = personals_pair
elif message_type == Recipient.STREAM: 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 stream # Pick a random subscriber to the stream
message.sender = random.choice(Subscription.objects.filter( message.sender = random.choice(Subscription.objects.filter(
recipient=message.recipient)).user_profile recipient=message.recipient)).user_profile
message.subject = stream.name + str(random.randint(1, 3)) message.subject = stream.name + str(random.randint(1, 3))
saved_data = message.subject saved_data['subject'] = message.subject
message.pub_date = now() message.pub_date = now()
do_send_message(message) do_send_message(message)