2012-11-14 19:40:25 +01:00
|
|
|
from optparse import make_option
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
2013-01-10 22:01:33 +01:00
|
|
|
from zephyr.models import UserProfile
|
|
|
|
from zephyr.lib.actions import compute_mit_user_fullname
|
|
|
|
|
2012-11-14 19:40:25 +01:00
|
|
|
# Helper to be used with manage.py shell to fix bad names on prod.
|
|
|
|
def update_mit_fullnames(change=False):
|
|
|
|
for u in UserProfile.objects.select_related().all():
|
2013-03-28 20:47:22 +01:00
|
|
|
if (u.is_active or u.realm.domain != "mit.edu"):
|
2012-11-14 19:40:25 +01:00
|
|
|
# Don't change fullnames for non-MIT users or users who
|
|
|
|
# actually have an account (is_active) and thus have
|
|
|
|
# presumably set their fullname how they like it.
|
|
|
|
continue
|
2013-03-28 20:43:34 +01:00
|
|
|
computed_name = compute_mit_user_fullname(u.email)
|
2012-11-14 19:40:25 +01:00
|
|
|
if u.full_name != computed_name:
|
2013-03-28 20:43:34 +01:00
|
|
|
print "%s: %s => %s" % (u.email, u.full_name, computed_name)
|
2012-11-14 19:40:25 +01:00
|
|
|
if change:
|
|
|
|
u.full_name = computed_name
|
|
|
|
u.save()
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
option_list = BaseCommand.option_list + (
|
|
|
|
make_option('--dry-run', '-n', dest='dry_run', default=False, action='store_true'),)
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
update_mit_fullnames(change=not options['dry_run'])
|