Files
zulip/zephyr/management/commands/diff_user_to_userprofile.py
Tim Abbott b82edb6fd6 [manual] Add User fields to the UserProfile model.
And keep the fields updated, by copying on UserProfile creation and
updating the UserProfile object whenever we're updating the User
object, and add management commands to (1) initially ensure that they
match and (2) check that they still match (aka that the updating code
is working).

The copy_user_to_userprofile migration needs to be run after this is
deployed to prod.

(imported from commit 0a598d2e10b1a7a2f5c67dd5140ea4bb8e1ec0b8)
2013-04-01 14:34:25 -04:00

20 lines
859 B
Python

from optparse import make_option
from django.core.management.base import BaseCommand
from zephyr.models import UserProfile, User
class Command(BaseCommand):
option_list = BaseCommand.option_list
help = "Diff all the shared fields between User to UserProfile."
def handle(self, *args, **options):
for user_profile in UserProfile.objects.all():
user = user_profile.user
def diff_fields(user_version, user_profile_version):
if user_version != user_profile_version:
print "Some values differ for %s!" % (user_profile.user.email,)
diff_fields(user.email, user_profile.email)
diff_fields(user.is_active, user_profile.is_active)
diff_fields(user.is_staff, user_profile.is_staff)
diff_fields(user.date_joined, user_profile.date_joined)