Files
zulip/zephyr/management/commands/activate_mit.py
Luke Faraone 71a91197fa Enable absolute imports.
See PEP 328[1] for details. This feature was introduced in Python 2.5 and
will become mandatory in Python 3.

[1]: http://www.python.org/dev/peps/pep-0328

(imported from commit 7444eeba8a08d5f91b94c7921848f2274979bd76)
2013-04-23 09:51:17 -07:00

29 lines
1.2 KiB
Python

from __future__ import absolute_import
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."