Files
zulip/zephyr/management/commands/activate_mit.py
Tim Abbott 198480ef99 Use get_user_profile_by_email more consistently.
The previous situation was bad for two reasons:

(1) It had a lot of copies of the code, some of them missing pieces:
  UserProfile.objects.get(user__email__iexact=foo)

This was in particular going to be inconvenient since we are dropping
the __user part of that.

(2) It didn't take advantage of our memcached caching.

(imported from commit 2325795f288a7cf306cdae191f5d3080aac0651a)
2013-03-29 16:18:38 -04:00

27 lines
1.1 KiB
Python

from optparse import make_option
from django.core.management.base import BaseCommand
from confirmation.models import Confirmation
from zephyr.models import UserProfile, MitUser, get_user_profile_by_email
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--resend', '-r', dest='resend', action='store_true',
help='Send tokens even if tokens were previously sent for the user.'),)
help = "Generate an activation email to send to MIT users."
def handle(self, *args, **options):
for username in args:
email = username + "@mit.edu"
try:
get_user_profile_by_email(email)
except UserProfile.DoesNotExist:
print username + ": User does not exist in database"
continue
mit_user, created = MitUser.objects.get_or_create(email=email)
if not created and not options["resend"]:
print username + ": User already exists. Use -r to resend."
else:
Confirmation.objects.send_confirmation(mit_user, email)
print username + ": Mailed."