From 81d560dc1f52864d51160d3c92d8a3e944570369 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 4 Dec 2012 15:09:38 -0500 Subject: [PATCH] populate_db: Preserve the user's date_joined on replay. (imported from commit 91dcb4f41e0e58f165db6a7417e57548914ddab7) --- zephyr/management/commands/populate_db.py | 3 ++- zephyr/models.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index f0f9b91949..a9855368bc 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -529,7 +529,8 @@ def restore_saved_messages(): elif old_message["type"] == "user_activated" or old_message["type"] == "user_created": # These are rare, so just handle them the slow way user = User.objects.get(email=old_message["user"]) - do_activate_user(user, log=False) + timestamp=datetime.datetime.utcfromtimestamp(float(old_message['timestamp'])).replace(tzinfo=utc) + do_activate_user(user, log=False, timestamp=timestamp) # Update the cache of users to show this user as activated users_by_id[user.userprofile.id] = UserProfile.objects.get(user=user) users[user.email] = user.userprofile diff --git a/zephyr/models.py b/zephyr/models.py index e876e00686..d0c62b89c8 100644 --- a/zephyr/models.py +++ b/zephyr/models.py @@ -601,13 +601,14 @@ def log_subscription_property_change(user_email, property, property_dict): event.update(property_dict) log_event(event) -def do_activate_user(user, log=True): +def do_activate_user(user, log=True, timestamp=time.time()): user.is_active = True user.set_password(initial_password(user.email)) + user.date_joined = timestamp user.save() if log: log_event({'type': 'user_activated', - 'timestamp': time.time(), + 'timestamp': timestamp, 'user': user.email}) def do_change_password(user, password, log=True):