From fb2b3ae21ae988b38b7682ee0256f488b8fa86f6 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 9 Apr 2013 13:10:40 -0400 Subject: [PATCH] Handle multiple preregistration user objects when choosing streams (imported from commit 52faa0256a719bed8a8ccc120f8177cce20450e2) --- zephyr/lib/actions.py | 8 ++++++-- zephyr/views.py | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/zephyr/lib/actions.py b/zephyr/lib/actions.py index b77c85e158..ab2695557f 100644 --- a/zephyr/lib/actions.py +++ b/zephyr/lib/actions.py @@ -27,6 +27,8 @@ from zephyr.lib.cache import cache_with_key, user_profile_by_id_cache_key, \ from zephyr.decorator import get_user_profile_by_email, json_to_list, JsonableError from zephyr.lib.event_queue import request_event_queue, get_user_events +import confirmation.settings + from zephyr import tornado_callbacks import subprocess @@ -731,9 +733,11 @@ def do_finish_tutorial(user_profile): # We want to add the default subs list iff there were no subs try: - prereg_user = PreregistrationUser.objects.get(email=user_profile.email) + prereg_user = PreregistrationUser.objects.filter(email=user_profile.email, + status=confirmation.settings.STATUS_ACTIVE) \ + .order_by('-id')[0] streams = prereg_user.streams.all() - except PreregistrationUser.DoesNotExist: + except IndexError: # If the user signed up via a mechanism other than # PreregistrationUser (e.g. Google Apps connect or MitUser), # just give them the default streams. diff --git a/zephyr/views.py b/zephyr/views.py index c60f744bfc..ac07485c22 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -225,6 +225,12 @@ def accounts_register(request): user_profile.email, ) ) + # Mark any other PreregistrationUsers that are STATUS_ACTIVE as inactive + # so we can find the PreregistrationUser that we are actually working + # with here + PreregistrationUser.objects.filter(email=email) \ + .exclude(id=prereg_user.id) \ + .update(status=0) notify_new_user(user_profile) queue_json_publish(